1.配置dockercompose配置文件

version: '2'
services:
  elasticsearch:
    image: es/elasticsearch:7.7
    container_name: es1
    restart: always
    dns_search: .
    environment:
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms256m -Xmx256m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:# data索引数据存储路径,logs日志输出,config配置
      - /etc/timezone:/etc/timezone
      - /etc/localtime:/etc/localtime
      - ./es/data:/usr/share/elasticsearch/data
      - ./es/logs:/usr/share/elasticsearch/logs
      - ./elasticsearch/config:/usr/share/elasticsearch/config
    ports:
      - 9200:9200
      - 9300:9300
    external_links:
      - es2 #同一机器下容器名称(为防止同一机器下docker容器之间不能通过ip进行互通)
      - es3
    tty: true
networks:
  default:
    external:
      name: esnetwork #同一机器下,所有节点需要在同一网络下

2.eLasticSearch配置文件修改

cluster.name: es-cluster
node.name: es-node1
network.bind_host: 0.0.0.0
network.publish_host: 本机ip地址
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
##一下五行为配置X-pack安全
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
##指定证书路径
xpack.security.transport.ssl.keystore.path: elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: elastic-certificates.p12
##是否参与master节点选举
node.master: true
##是否存储数据
node.data: true
#discovery.seed_hosts: ["elasticsearch2:10293","elasticsearch1:10193"]
#cluster.initial_master_nodes: ["es-node0","es-node1","es-node2"]
## 指定该集群下所有节点及端口(同一机器下可以用容器名称代替机器ip(前提是需要在dockerCompose配置中添加该节点的容器名))
discovery.seed_hosts: ["141.3.186.01:9301","es2:9302","es3:9303"]
##参与master节点选举的节点名称集合
cluster.initial_master_nodes: ["es-node1","es-node2","es-node3"]

3.其他节点可依照此配置统一配置,需注意:集群名称需一致,容器名称、节点名称、ip地址、端口号等不同。

配置完成后统一启动 docker-compose启动命令:

  • docker-compose up -d #启动
  • docker-compose restart #重启

可通过访问如下路径查看是否搭建成功:

http://141.3.186.01:9200/_cat/nodes?v&pretty


如图显示所有节点说明配置成功了

4.遇到问题

1.如果集群缺少几点(显示节点不全)
解决方法:关闭所有节点,删除所有节点的logs下的日志文件,然后重启所有节点。(可多试几次)

5.关于X-pack配置可参考如下文档

ES--es7.6.1开通安全防护认证流程

03-05 16:02