美文网首页
elasticsearch:8.6.2 docker 集群(安全

elasticsearch:8.6.2 docker 集群(安全

作者: 廖全磊LesterLiao | 来源:发表于2023-03-05 17:00 被阅读0次

docker 单机搭建请移步官方文档

第一台机器启动命令

docker run --name es1 --net elastic -p 9200:9200 -p 9300:9300 \
-e "network.bind_host=0.0.0.0" -e "network.publish_host=172.16.49.91"  \
-v /es-data/data:/usr/share/elasticsearch/data \
-it docker.elastic.co/elasticsearch/elasticsearch:8.6.2

启动成功会生成token如下



通过方框内的token,继续创建第二台机器

docker run --name es2 -e ES_JAVA_OPTS="-Xms1g -Xmx1g" -p 9200:9200 -p 9300:9300 --net elastic \
-e "network.bind_host=0.0.0.0" -e "network.publish_host=172.16.49.86"  \
-e ENROLLMENT_TOKEN="eyJ2ZXIiOiI4LjYuMiIsImFkciI6WyIxNzIuMTYuNDkuOTE6OTIwMCJdLCJmZ3IiOiI5ZDEyNmVkYWQxNjMzYmI3MGY5MmVkZmMzN2ExMGQ5MzFmNjhlMWE3N2QzZDY1OWFjNDgxZTE0MzI0MzJjYTA3Iiwia2V5IjoiTGZyTHRZWUJURzJmOHNURWdYN3g6OURWRGlFQWlUT1NBNVNWOXdYTE9MZyJ9" \
-it docker.elastic.co/elasticsearch/elasticsearch:8.6.2

踩坑记录

  • 内存小的机器必须指定ES_JAVA_OPTS,不然会报内存不够的错误
  • -e "network.bind_host=0.0.0.0" -e "network.publish_host=172.16.49.91" 此配置为了解决elasticsearch默认创建证书时,证书的ip列表只包含了容器本地ip,宿主机ip没有包含,导致外部无法访问elasticsearch,此处我被官方文档误导,走入了手动生成ca证书的误区(虽然也可以解决,但是需要手动生成容器内的http.p12和transport.p12证书,且无法通过token 直接创建服务,异常麻烦),经过仔细思考,终于用简单方式实现
  • -p 9200:9200 -p 9300:9300 ,9300的端口绑定必须指定,不然第二太机器创建的时候会加入不了集群
  • -v /es-data/data:/usr/share/elasticsearch/data ,挂载外部目录的时候,注意文件夹提权,elasticsearch.yml无法挂载在外部,会报错(原因可能是elasticsearch启动的时候会删除此文件,并重新生成,导致报错 Device or resource busy)

es集群从节点重启报错

ERROR: Skipping security auto configuration because it appears that the node is not starting up for the first time. The node might already be part of a cluster and this auto setup utility is designed to configure Security for new clusters only.

此错误,需要删除容器中的环境变量ENROLLMENT_TOKEN

方法如下

# 找到容器目录
docker inspect es2 | grep ResolvConfPath
# 暂停 docker 服务
systemctl stop docker
#  找到 resolv.conf 同级目录下的 config.v2.json 并移除其文件中的"ENROLLMENT_TOKEN" key
# 启动docker 服务
systemctl start docker
# 启动 容器(完美解决)
docker start es2

metricbeat 安装完成后有两个地方需要修改,才能顺利采集es数据

1、配置 /etc/metricbeat/metricbeat.yml 如下,主要用于向es中发送数据



2 、配置 /etc/metricbeat/modules.d/elasticsearch-xpack.yml 如下,主要用于收集es数据


相关文章

网友评论

      本文标题:elasticsearch:8.6.2 docker 集群(安全

      本文链接:https://www.haomeiwen.com/subject/qhxpldtx.html