docker-compose搭建elasticsearch集群

赵涵亮
2023-12-01

1.创建集群目录

mkdir -p /home/wangyan/es/master/config &&

mkdir -p /home/wangyan/es/master/data &&

mkdir -p /home/wangyan/es/master/log &&

mkdir -p /home/wangyan/es/node1/config &&

mkdir -p /home/wangyan/es/node1/data &&

mkdir -p /home/wangyan/es/node1/log &&

mkdir -p /home/wangyan/es/node2/config &&

mkdir -p /home/wangyan/es/node2/data &&

mkdir -p /home/wangyan/es/node2/log

2.修改目录权限

chmod 777 -R /home/wangyan/es/master &&
chmod 777 -R /home/wangyan/es/node1 &&
chmod 777 -R /home/wangyan/es/node2

3.分别在master,node1,node2的config目录下创建es.yml文件

master的es.yml

cluster.name: es-cluster
node.name: es-master
node.master: true
node.data: true
 
network.host: es-master
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
 
discovery.zen.ping.unicast.hosts: ["es-master:9300", "es-node1:9300", "es-node2:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
 
bootstrap.memory_lock: true
action.destructive_requires_name: true
cluster.initial_master_nodes: ["es-master"]

node1的es.yml

cluster.name: es-cluster
node.name: es-node1
node.master: false
node.data: true
 
network.host: es-node1
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
 
discovery.zen.ping.unicast.hosts: ["es-master:9300", "es-node1:9300", "es-node2:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
 
bootstrap.memory_lock: true
action.destructive_requires_name: true
cluster.initial_master_nodes: ["es-master"]

node2的es.yml

cluster.name: es-cluster
node.name: es-node2
node.master: false
node.data: true
 
network.host: es-node2
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
 
discovery.zen.ping.unicast.hosts: ["es-master:9300", "es-node1:9300", "es-node2:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping_timeout: 5s
 
bootstrap.memory_lock: true
action.destructive_requires_name: true
cluster.initial_master_nodes: ["es-master"]

4.在/home/wangyan/es 目录下创建 docker-compose.yml

version: "3"
services:
  es-master:
    image: elasticsearch:7.7.0
    container_name: es-master
    environment:
      - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9200:9200"
      - "9300:9300"
    volumes:
      - /home/wangyan/es/master/config/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /home/wangyan/es/master/data:/usr/share/elasticsearch/data
      - /home/wangyan/es/master/log:/usr/share/elasticsearch/log
    networks:
      - net-es
  es-node1:
    image: elasticsearch:7.7.0
    container_name: es-node1
    environment:
      - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9201:9200"
      - "9301:9300"
    volumes:
      - /home/wangyan/es/node1/config/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /home/wangyan/es/node1/data:/usr/share/elasticsearch/data
      - /home/wangyan/es/node1/log:/usr/share/elasticsearch/log
    networks:
      - net-es
  es-node2:
    image: elasticsearch:7.7.0
    container_name: es-node2
    environment:
      - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    ports:
      - "9202:9200"
      - "9302:9300"
    volumes:
      - /home/wangyan/es/node2/config/es.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /home/wangyan/es/node2/data:/usr/share/elasticsearch/data
      - /home/wangyan/es/node2/log:/usr/share/elasticsearch/log
    networks:
      - net-es
networks:
  net-es:
    driver: bridge

5.执行docker-compose命令

docker-compose -f docker-compose.yml up -d

参考博文: https://blog.csdn.net/qq_35394891/article/details/84345521

 类似资料: