🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
使用 docker-compose 部署集群 创建索引的时候就确定好主分片的数量,**后期是无法修改主分片数量的** 3个 es, 1个kibana docker-compose-elasticsearch.yml ``` version: '3' services: elasticsearch9200: image: elasticsearch:7.6.2 container_name: elasticsearch9200 volumes: - ./data/elasticsearch9200/data:/usr/share/elasticsearch/data - ./data/elasticsearch9200/plugins:/usr/share/elasticsearch/plugins - ./data/elasticsearch9200/config:/usr/share/elasticsearch/config environment: - TZ=Asia/Shanghai - LANG=en_US.UTF-8 ports: - "9200:9200" - "9300:9300" networks: wkcrm_network: restart: always elasticsearch9201: image: elasticsearch:7.6.2 container_name: elasticsearch9201 volumes: - ./data/elasticsearch9201/data:/usr/share/elasticsearch/data - ./data/elasticsearch9201/plugins:/usr/share/elasticsearch/plugins - ./data/elasticsearch9201/config:/usr/share/elasticsearch/config environment: - TZ=Asia/Shanghai - LANG=en_US.UTF-8 ports: - "9201:9200" - "9301:9300" networks: wkcrm_network: restart: always elasticsearch9202: image: elasticsearch:7.6.2 container_name: elasticsearch9202 volumes: - ./data/elasticsearch9202/data:/usr/share/elasticsearch/data - ./data/elasticsearch9202/plugins:/usr/share/elasticsearch/plugins - ./data/elasticsearch9202/config:/usr/share/elasticsearch/config environment: - TZ=Asia/Shanghai - LANG=en_US.UTF-8 ports: - "9202:9200" - "9302:9300" networks: wkcrm_network: restart: always kibana5601: image: kibana:7.6.2 container_name: kibana5601 volumes: - ./data/kibana5601/data:/usr/share/kibana/data - ./data/kibana5601/config:/usr/share/kibana/config - ./data/kibana5601/plugins:/usr/share/kibana/plugins ports: - "5601:5601" networks: wkcrm_network: restart: always networks: wkcrm_network: external: name: wkcrm_network ``` start.sh ``` #!/bin/bash chmod -R 777 ./; docker network create --driver=bridge wkcrm_network docker-compose -f docker-compose-elasticsearch.yml up -d echo " ------------ 正在下载安装中 ------------ "; ``` start.sh 执行报错可以参考 Linux 目录下的 sh文件执行报错 的解决 elasticsearch9200的 elasticsearch.yml ``` # 开启账号密码 #xpack.security.enabled: true #xpack.license.self_generated.type: basic #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 #跨域支持 http.cors.enabled: true http.cors.allow-origin: "*" #集群名称(所有节点的集群名称必须一致) cluster.name: elasticsearch #节点名称(集群下每个节点都不相同) node.name: "es-node-0" #定义为主节点 node.master: true #定义为数据节点 node.data: true #访问的IP地址,0.0.0.0表示不限制 network.host: 0.0.0.0 #访问端口号 http.port: 9200 #集群通讯端口号 transport.tcp.port: 9300 #所有节点的ip地址, docker 下可以使用服务名调用 discovery.zen.ping.unicast.hosts: ["elasticsearch9200:9300", "elasticsearch9201:9300", "elasticsearch9202:9300"] ``` elasticsearch9201的 elasticsearch.yml ``` # 开启账号密码 #xpack.security.enabled: true #xpack.license.self_generated.type: basic #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 #跨域支持 http.cors.enabled: true http.cors.allow-origin: "*" #集群名称(所有节点的集群名称必须一致) cluster.name: elasticsearch #节点名称(集群下每个节点都不相同) node.name: "es-node-1" #定义为主节点 node.master: false #定义为数据节点 node.data: true #访问的IP地址,0.0.0.0表示不限制 network.host: 0.0.0.0 #访问端口号 http.port: 9200 #集群通讯端口号 transport.tcp.port: 9300 #所有节点的ip地址, docker 下可以使用服务名调用 discovery.zen.ping.unicast.hosts: ["elasticsearch9200:9300", "elasticsearch9201:9300", "elasticsearch9202:9300"] ``` elasticsearch9202的 elasticsearch.yml ``` # 开启安全认证 #xpack.security.enabled: true #xpack.license.self_generated.type: basic #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 #跨域支持 http.cors.enabled: true http.cors.allow-origin: "*" #集群名称(所有节点的集群名称必须一致) cluster.name: elasticsearch #节点名称(集群下每个节点都不相同) node.name: "es-node-2" #定义为主节点 node.master: false #定义为数据节点 node.data: true #访问的IP地址,0.0.0.0表示不限制 network.host: 0.0.0.0 #访问端口号 http.port: 9200 #集群通讯端口号 transport.tcp.port: 9300 #所有节点的ip地址, docker 下可以使用服务名调用 discovery.zen.ping.unicast.hosts: ["elasticsearch9200:9300", "elasticsearch9201:9300", "elasticsearch9202:9300"] ``` 集群加账号密码的没实现, 主要是没实现节点间的ca证书 docker exec -it 容器id /bin/bash ./bin/elasticsearch-certutil ca 输入的证书密码, 最好都使用同一个 ``` # 这是生成证书名称, 直接回车即可 Please enter the desired output file [elastic-stack-ca.p12]: Enter password for elastic-stack-ca.p12 : 设置证书密码 123456 ``` ./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12 ``` Enter password for CA (elastic-stack-ca.p12) : 输入 密码 123456 输入文件名 回车使用默认即可 输入 密码 123456 ``` bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password 输入第一步输入的密码 bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password 输入第一步输入的密码 生成位置 /usr/share/elasticsearch/elastic-certificates.p12 退出容器, 复制docker 文件到主机 ``` docker cp 主机id:/usr/share/elasticsearch/elastic-certificates.p12 /dockerdata/elasticsearch-cluster/data/elastic-certificates.p12 ``` 在config目录创建certs目录 拷贝p12文件至certs目录 elasticsearch.yml ``` # 开启安全认证 xpack.security.enabled: true xpack.license.self_generated.type: basic xpack.security.transport.ssl.enabled: true xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12 ```