搭建ES集群
- 创建网络
docker network create elastic
- 拉取镜像
docker pull docker.elastic.co/elasticsearch/elasticsearch:8.12.0
- 配置docker-compose.yml文件
注意:映射的宿主机目录需要事先存在,否则会清空容器中的内容。可以先将其注释掉启动容器后cp到宿主机,再启动容器。data目录所有节点最好用同一内容
# 配置节点es1
version: '3'
networks:
elastic:
external: true
services:
es:
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
container_name: es1
deploy:
resources:
limits:
memory: 2G
restart: always
networks:
elastic:
ipv4_address: 172.30.0.2
environment:
- ES_JAVA_OPTS=-Xms512m -Xmx512m #设置ip地址
ports:
- "9200:9200"
- "9300:9300"
volumes:
- ./local/plugins:/usr/share/elasticsearch/plugins
- ./local/data:/usr/share/elasticsearch/data
- ./local/config:/usr/share/elasticsearch/config
- ./local/logs:/usr/share/elasticsearch/logs
privileged: true
# 配置节点es2
version: '3'
networks:
elastic:
external: true
services:
es:
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
container_name: es2
deploy:
resources:
limits:
memory: 2G
restart: always
networks:
elastic:
ipv4_address: 172.30.0.4 #设置ip地址
environment:
- ES_JAVA_OPTS=-Xms512m -Xmx512m
ports:
- "9201:9200"
- "9301:9300"
volumes:
- ./local/plugins:/usr/share/elasticsearch/plugins
- ./local/data:/usr/share/elasticsearch/data
- ./local/config:/usr/share/elasticsearch/config
- ./local/logs:/usr/share/elasticsearch/logs
privileged: true
# 配置节点es3
version: '3'
networks:
elastic:
external: true
services:
es:
image: docker.elastic.co/elasticsearch/elasticsearch:8.12.0
container_name: es3
deploy:
resources:
limits:
memory: 2G
restart: always
networks:
elastic:
ipv4_address: 172.30.0.5 #设置ip地址
environment:
- ES_JAVA_OPTS=-Xms512m -Xmx512m
ports:
- "9202:9200"
- "9302:9300"
volumes:
- ./local/plugins:/usr/share/elasticsearch/plugins
- ./local/data:/usr/share/elasticsearch/data
- ./local/config:/usr/share/elasticsearch/config
- ./local/logs:/usr/share/elasticsearch/logs
privileged: true
- 复制容器中的映射目录到宿主机
# es1是容器名称,详情可看上一步。需看注意。这里只演示config。
docker cp es1:/usr/share/elasticsearch/config local/
- 配置es配置文件
# es1下的配置文件
vi local/config/elasticsearch.yml
cluster.name: "elasticsearch-cluster"
node.name: es-node1
network.host: 0.0.0.0
network.publish_host: 172.30.0.2
http.port: 9200
transport.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.roles: [master,data]
discovery.seed_hosts: ["172.30.0.2:9300","172.30.0.4:9300","172.30.0.5:9300"]
cluster.initial_master_nodes: ["es-node1", "es-node2", "es-node3"]
# es2下的配置文件
vi local/config/elasticsearch.yml
cluster.name: "elasticsearch-cluster"
node.name: es-node2
network.host: 0.0.0.0
network.publish_host: 172.30.0.4
http.port: 9200
transport.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.roles: [master,data]
discovery.seed_hosts: ["172.30.0.2:9300","172.30.0.4:9300","172.30.0.5:9300"]
# es3下的配置文件
vi local/config/elasticsearch.yml
cluster.name: "elasticsearch-cluster"
node.name: es-node3
network.host: 0.0.0.0
network.publish_host: 172.30.0.5
http.port: 9200
transport.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.roles: [master,data]
discovery.seed_hosts: ["172.30.0.2:9300","172.30.0.4:9300","172.30.0.5:9300"]
- 启动容器
docker-compose up -d
- 重置密码+kibana使用的token保存备用
docker exec -it es1 /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic
docker exec -it es1 /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana
- 访问ES,出现如下图内容,这时使用上述重置的密码
- 登录进去后,出现如图下内容
- 访问https://192.168.239.141:9200/_cat/nodes查看集群下的节点
搭建kibana
- 拉取镜像
docker pull docker.elastic.co/kibana/kibana:8.12.0
- 配置docker-compose.yml
version: '3'
networks:
elastic:
external: true
services:
kibana:
image: docker.elastic.co/kibana/kibana:8.12.0
container_name: kibana
deploy:
resources:
limits:
memory: 1G
restart: always
networks:
- elastic
ports:
- "5601:5601"
volumes:
- ./local/config:/usr/share/kibana/config
- 配置kibana.yml
i18n.locale: zh-CN # 中文,最后一行添加
- 启动kibana
docker-compose up -d
- 访问http://192.168.239.141:5601/
输入之前保存得token,并点击按钮
- 出现下方输出code界面,可通过docker-compose logs -f 查看
7. kibana配置完成会提示输入账号密码,密码之前保存过。