安装docker-compose

需要在运行docker容器的主机上安装docker-compose,可以参照官方文档手动安装,也可以使用ezhttp的一键安装工具(推荐)安装。如:

wget centos.bz/ezhttp.zip
 unzip ezhttp.zip
 cd ezhttp-master
 ./start.sh

在服务器上 /usr/local/目录下新建docker文件夹,在docker文件夹内新建文件:docker-compose.yml

docker-compose.yml 代码如下:

version: "3"
services:
  es-root:
    image: registry.cn-hangzhou.aliyuncs.com/elasticsearch-guoan/elasticsearch-root
    container_name: es-root
    environment:
      - "ES_JAVA_OPTS=-Xms4g -Xmx4g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9200:9200"
      - "9300:9300"
    volumes:
      - /usr/local/data/elasticsearch/es-root/logs:/usr/local/data/elasticsearch-6.1.3/logs
      - ./config/root/elasticsearch.yml:/usr/local/elasticsearch-6.1.3/config/elasticsearch.yml:ro
    networks:
      - net-es

  es-spare-1:
    image: registry.cn-hangzhou.aliyuncs.com/elasticsearch-guoan/elasticsearch-root
    container_name: es-spare-1
    environment:
      - "ES_JAVA_OPTS=-Xms4g -Xmx4g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9201:9200"
      - "9301:9300"
    volumes:
      - /usr/local/data/elasticsearch/es-node1/logs:/usr/local/data/elasticsearch-6.1.3/logs
      - /usr/local/data/elasticsearch/es-node1/data:/usr/local/data/elasticsearch-6.1.3/data 
      - ./config/root/elasticsearch-spare-1.yml:/usr/local/elasticsearch-6.1.3/config/elasticsearch.yml:ro
    networks:
      - net-es

  es-spare-2:
    image: registry.cn-hangzhou.aliyuncs.com/elasticsearch-guoan/elasticsearch-root
    container_name: es-spare-2
    environment:
      - "ES_JAVA_OPTS=-Xms4g -Xmx4g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9202:9200"
      - "9302:9300"
    volumes:
      - /usr/local/data/elasticsearch/es-node2/logs:/usr/local/data/elasticsearch-6.1.3/logs
      - /usr/local/data/elasticsearch/es-node2/data:/usr/local/data/elasticsearch-6.1.3/data 
      - ./config/root/elasticsearch-spare-2.yml:/usr/local/elasticsearch-6.1.3/config/elasticsearch.yml:ro
    networks:
      - net-es

  es-node-1:
    image: registry.cn-hangzhou.aliyuncs.com/elasticsearch-guoan/elasticsearch-root
    container_name: es-node-1
    environment:
      - "ES_JAVA_OPTS=-Xms4g -Xmx4g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9203:9200"
      - "9303:9300"
    volumes:
      - /usr/local/data/elasticsearch/es-node3/logs:/usr/local/data/elasticsearch-6.1.3/logs
      - /usr/local/data/elasticsearch/es-node3/data:/usr/local/data/elasticsearch-6.1.3/data  
      - ./config/node/elasticsearch-node-1.yml:/usr/local/elasticsearch-6.1.3/config/elasticsearch.yml:ro
    networks:
      - net-es

  es-node-2:
    image: registry.cn-hangzhou.aliyuncs.com/elasticsearch-guoan/elasticsearch-root
    container_name: es-node-2
    environment:
      - "ES_JAVA_OPTS=-Xms4g -Xmx4g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9204:9200"
      - "9304:9300"
    volumes:
      - /usr/local/data/elasticsearch/es-node4/logs:/usr/local/data/elasticsearch-6.1.3/logs
      - /usr/local/data/elasticsearch/es-node4/data:/usr/local/data/elasticsearch-6.1.3/data 
      - ./config/node/elasticsearch-node-2.yml:/usr/local/elasticsearch-6.1.3/config/elasticsearch.yml:ro
    networks:
      - net-es

  es-node-3:
    image: registry.cn-hangzhou.aliyuncs.com/elasticsearch-guoan/elasticsearch-root
    container_name: es-node-3
    environment:
      - "ES_JAVA_OPTS=-Xms4g -Xmx4g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9205:9200"
      - "9305:9300"
    volumes:
      - /usr/local/data/elasticsearch/es-node5/logs:/usr/local/data/elasticsearch-6.1.3/logs
      - /usr/local/data/elasticsearch/es-node5/data:/usr/local/data/elasticsearch-6.1.3/data  
      - ./config/node/elasticsearch-node-3.yml:/usr/local/elasticsearch-6.1.3/config/elasticsearch.yml:ro
    networks:
      - net-es
networks:
  net-es:

保存后在docker目录下创建目录 /config/root 和 /config/node两个文件夹

第一主节点,不做数据存储,配置文件为elasticsearch.yml

elasticsearch.yml 代码如下:

#集群名称
cluster.name:es-test
node.name: es-root
node.master: true
node.data: false
#TCP端口
transport.tcp.port: 9300
transport.tcp.compress: true 

http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-credentials: true

# Search pool
thread_pool.search.size: 7
thread_pool.search.queue_size: 2000

# Bulk pool
thread_pool.bulk.size: 4
thread_pool.bulk.queue_size: 1000

# Index pool
thread_pool.index.size: 4
thread_pool.index.queue_size: 1000

path.data: /usr/local/data/elasticsearch/data
path.logs: /usr/local/data/elasticsearch/logs

bootstrap.memory_lock: true

network.host: 0.0.0.0
network.publish_host: 0.0.0.0
network.bind_host: 0.0.0.0

http.port: 9200
http.max_content_length: 100mb
gateway.recover_after_nodes: 1
gateway.recover_after_time: 8m
gateway.expected_nodes: 4
cluster.routing.allocation.node_initial_primaries_recoveries: 8
cluster.routing.allocation.node_concurrent_recoveries: 4

discovery.zen.ping.unicast.hosts: ["es-root:9300","es-spare-1:9301","es-spare-2:9302"]

discovery.zen.minimum_master_nodes: 3

候选主节点修改如下:

node.master: true

node.data: true

node节点配置如下:

node.master: false

node.data: true

保存后,进入docker目录 

cd /usr/local/docker

执行docker-compose文件

docker-compose up

当所有镜像都出现started则表示镜像启动成功

启动成功后访问 http://host:9200查看集群状态

当cluster_uuid值不再为"_na_",表示elasticsearch集群准备就绪,elasticsearch插件 kibana和head 安装教程有太多我就不写了

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐