跳转到主要内容

elasticsearch

version: '3'
services:
  elasticsearch-1:
    image: swr.cn-south-1.myhuaweicloud.com/vp-whdev/all-in-devops/elasticsearch:8.8.0
    restart: always
    ports:
      - 9200:9200
      - 9300:9300
    privileged: true
    environment:
      - node.name=es01                                            # 节点名称,唯一
      - cluster.name=gzrqjt-log                                   # 集群名称,集群一致
      - cluster.initial_master_nodes=es01,es02                    # 集群节点成员,单机节点可以注释
      - discovery.seed_hosts=elasticsearch-2                      # 从指定主机发现,单机节点可以注释
      - xpack.security.enabled=false                              # xpack 安全设置
      - xpack.security.http.ssl.enabled=false                     # xpack 安全设置
      # - discovery.type=single-node                              # 单节点,单机节点放开注释
      - ES_JAVA_OPTS=-Xms512m -Xmx512m
    volumes:
      - ./data1:/usr/share/elasticsearch/data
    # extra_hosts:
    #   - "elasticsearch-2:172.18.41.2"  
    networks:
      - elasticsearch-net
  elasticsearch-2:
    image: swr.cn-south-1.myhuaweicloud.com/vp-whdev/all-in-devops/elasticsearch:8.8.0
    restart: always
    # ports:
    #   - 9200:9200
    #   - 9300:9300
    privileged: true
    environment:
      - node.name=es02                                            # 节点名称,唯一
      - cluster.name=gzrqjt-log                                   # 集群名称,集群一致
      - cluster.initial_master_nodes=es01,es02,es03               # 集群节点成员,单机节点可以注释
      - discovery.seed_hosts=elasticsearch-2,elasticsearch-3      # 从指定主机发现,单机节点可以注释
      - xpack.security.enabled=false                              # xpack 安全设置
      - xpack.security.http.ssl.enabled=false                     # xpack 安全设置	
      # - discovery.type=single-node                              # 单节点,单机节点放开注释
      - ES_JAVA_OPTS=-Xms512m -Xmx512m
    volumes:
      - ./data2:/usr/share/elasticsearch/data
    # extra_hosts:
    #   - "elasticsearch-2:172.18.41.2"  
    networks:
      - elasticsearch-net

  elasticsearch-3:
    image: swr.cn-south-1.myhuaweicloud.com/vp-whdev/all-in-devops/elasticsearch:8.8.0
    restart: always
    # ports:
    #   - 9200:9200
    #   - 9300:9300
    privileged: true
    environment:
      - node.name=es03                                            # 节点名称,唯一
      - cluster.name=gzrqjt-log                                   # 集群名称,集群一致
      - cluster.initial_master_nodes=es01,es02,es03               # 集群节点成员,单机节点可以注释
      - discovery.seed_hosts=elasticsearch-2,elasticsearch-3      # 从指定主机发现,单机节点可以注释
      - xpack.security.enabled=false                              # xpack 安全设置
      - xpack.security.http.ssl.enabled=false                     # xpack 安全设置	
      # - discovery.type=single-node                              # 单节点,单机节点放开注释
      - ES_JAVA_OPTS=-Xms512m -Xmx512m
    volumes:
      - ./data3:/usr/share/elasticsearch/data
    # extra_hosts:
    #   - "elasticsearch-2:172.18.41.2"  
    networks:
      - elasticsearch-net

networks:
  elasticsearch-net:
    external:
      name: elasticsearch-net    


# docker network create --subnet=172.20.100.0/24 --gateway 172.16.100.1 elasticsearch-net

# groupadd elasticsearch                                      # 增加用户组
# useradd elasticsearch -g elasticsearch -p codingwhy$@&*     # 增加用户

# chown -R elasticsearch:elasticsearch data1/               # 修改权限
# chmod 755 data1/                                          # 修改权限
# vi /etc/sysctl.conf
# vm.max_map_count=262144                                   # 设置进程拥有的内存大小,永久生效
# sysctl -w vm.max_map_count=262144                         # 设置进程拥有的内存大小,一次生效

测试服务状态

# curl localhost:9200/_cluster/health?pretty
{
  "cluster_name" : "wuxue-ny",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 1,
  "number_of_data_nodes" : 1,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 0,
  "delayed_unassigned_shards" : 0,
  "number_of_pending_tasks" : 0,
  "number_of_in_flight_fetch" : 0,
  "task_max_waiting_in_queue_millis" : 0,
  "active_shards_percent_as_number" : 100.0
}