章工运维 章工运维
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)

章工运维

业精于勤,荒于嬉
首页
  • linux
  • windows
  • 中间件
  • 监控
  • 网络
  • 存储
  • 安全
  • 防火墙
  • 数据库
  • 系统
  • docker
  • 运维工具
  • other
  • elk
  • K8S
  • ansible
  • Jenkins
  • GitLabCI_CD
  • 随笔
  • 面试
  • 工具
  • 收藏夹
  • Shell
  • python
  • golang
友链
  • 索引

    • 分类
    • 标签
    • 归档
    • 首页 (opens new window)
    • 关于我 (opens new window)
    • 图床 (opens new window)
    • 评论 (opens new window)
    • 导航栏 (opens new window)
周刊
GitHub (opens new window)
  • ansible系列文章

  • Kubernetes笔记

  • elk

    • elk安装
    • docker-compose安装elk
    • filebeat-log相关配置指南
    • logstash提取日志字段到kibana仪表盘展示
    • 深入理解 ELK 中 Logstash 的底层原理
    • filebeat及logstash配置
    • es索引定期删除脚本
    • logstash线上配置文件
    • elk报错问题总结
    • es备份和还原
    • ES集群与角色规划
    • ES8.8集群与Kibana部署
    • ElasticSearch可视化工具介绍
    • 使用docker构建ElasticSearch集群
    • jenkins

    • GitLabCI_CD

    • 专题
    • elk
    章工运维
    2024-04-16
    目录

    使用docker构建ElasticSearch集群

    # 一、准备工作

    # 1、拉取ElasticSearch镜像
    docker pull elasticsearch:7.14.1
    docker tag docker.io/elasticsearch:7.14.1 elasticsearch
    docker rmi docker.io/elasticsearch:7.14.1
    
    1
    2
    3
    # 2、创建相关文件夹,用于存放配置文件
    mkdir -p /data//docker-compose/elasticsearch
    mkdir -p /data/docker-data/elasticsearch/101/config
    mkdir -p /data/docker-data/elasticsearch/102/config
    mkdir -p /data/docker-data/elasticsearch/103/config
    
    1
    2
    3
    4
    # 3、赋予文件夹权限
    chmod -R 777 /data/docker-data/elasticsearch
    
    1

    ElasticSearch对共享目录的文件夹权限有要求,因此这里为共享目录设置权限

    # 4、将当前用户的内存权限变大
    查看当前用户的内存权限
    sysctl -a|grep vm.max_map_count
    # 显示 vm.max_map_count = 65530
    
    1
    2
    3

    elasticsearch要求该值至少是262144,否则会报错,max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    # 将用户拥有的内存权限增大
    sysctl -w vm.max_map_count=262144
    
    1
    2

    # 二、编写docker-compose.yml

    cd /data/docker-compose/elasticsearch
    vi docker-compose.yml
    
    version: '3.6'
    services:
      es_101:
        image: elasticsearch
        container_name: es_101
        hostname: es_101
        environment:
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        volumes:
          - /data/docker-data/elasticsearch/101/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
          - /data/docker-data/elasticsearch/101/data:/usr/share/elasticsearch/data
        privileged: true
        ports:
          - 9201:9200
          - 9301:9300
    
      es_102:
        image: elasticsearch
        container_name: es_102
        hostname: es_102
        environment:
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        volumes:
          - /data/docker-data/elasticsearch/102/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
          - /data/docker-data/elasticsearch/102/data:/usr/share/elasticsearch/data
        privileged: true
        ports:
          - 9202:9200
          - 9302:9300
    
      es_103:
        image: elasticsearch
        container_name: es_103
        hostname: es_103
        environment:
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
        volumes:
          - /data/docker-data/elasticsearch/103/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
          - /data/docker-data/elasticsearch/103/data:/usr/share/elasticsearch/data
        privileged: true
        ports:
          - 9203:9200
          - 9303:9300
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46

    # 三、编写ElasticSearch和kibana的配置文件

    cd /data/docker-data/elasticsearch/101/config
    vi elasticsearch.yml
    
    cluster.name: es_cluster
    node.name: es_101
    node.master: true
    node.data: true
    network.host: 0.0.0.0
    http.port: 9200
    transport.tcp.port: 9300
    discovery.zen.ping.unicast.hosts: ["es_101","es_102","es_103"]
    discovery.zen.minimum_master_nodes: 1
    cluster.initial_master_nodes: es_101
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    cd /data/docker-data/elasticsearch/102/config
    vi elasticsearch.yml
    
    cluster.name: es_cluster
    node.name: es_102
    node.master: true
    node.data: true
    network.host: 0.0.0.0
    http.port: 9200
    transport.tcp.port: 9300
    discovery.zen.minimum_master_nodes: 1
    discovery.zen.ping.unicast.hosts: ["es_101","es_102","es_103"]
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    cd /data/docker-data/elasticsearch/103/config
    vi elasticsearch.yml
    
    cluster.name: es_cluster
    node.name: es_103
    node.master: true
    node.data: true
    network.host: 0.0.0.0
    http.port: 9200
    transport.tcp.port: 9300
    discovery.zen.minimum_master_nodes: 1
    discovery.zen.ping.unicast.hosts: ["es_101","es_102","es_103"]
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14

    # 四、执行构建ElasticSearch集群

    # 1、开始构建
    cd /data/docker-compose/elasticsearch
    docker-compose up -d
    
    1
    2

    此时,因为没有授予共享目录文件夹权限,因此es集群其实是启动不成功的

    # 2、授予文件夹权限
    chmod -R 777 /data/docker-data/elasticsearch/
    
    1
    # 3、重新执行构建
    cd /data/docker-compose/elasticsearch
    docker-compose restart
    
    1
    2

    # 五、验证结果:

    宿主机:192.168.78.200

    访问192.168.78.200:9201 或 192.168.78.200:9202 或 192.168.78.200:9203

    返回下面结果:

    // 20210927041419
    // http://192.168.78.200:9201/
    
    {
      "name": "es_101",
      "cluster_name": "es_cluster",
      "cluster_uuid": "_KgoQSikS6StSHpBK4Yr0Q",
      "version": {
        "number": "7.14.1",
        "build_flavor": "default",
        "build_type": "docker",
        "build_hash": "66b55ebfa59c92c15db3f69a335d500018b3331e",
        "build_date": "2021-08-26T09:01:05.390870785Z",
        "build_snapshot": false,
        "lucene_version": "8.9.0",
        "minimum_wire_compatibility_version": "6.8.0",
        "minimum_index_compatibility_version": "6.0.0-beta1"
      },
      "tagline": "You Know, for Search"
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20

    说明集群搭建成功了。

    # 六、ElasticSearch可视化工具

    详见文章:elasticsearch可视化工具介绍


    原文链接 (opens new window)

    微信 支付宝
    上次更新: 2024/04/16, 17:30:00

    ← ElasticSearch可视化工具介绍 jenkins容器安装→

    最近更新
    01
    不花一分钱从0到1建站教程
    04-22
    02
    批量拿取多台服务器的日志文件
    04-21
    03
    高德MCP智能体搞定旅游计划
    04-19
    更多文章>
    Theme by Vdoing | Copyright © 2019-2025 | 点击查看十年之约 | 鄂ICP备2024072800号
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式