docker 安装es集群

本文档详细介绍了如何在Docker环境下设置Elasticsearch集群,包括修改系统参数、创建目录、配置各节点及启动命令。在每个步骤中,都提供了具体的操作方法,如设置最大进程数、内存限制以及配置集群节点间通信。在测试阶段,可以通过检查集群健康状态和节点信息确认集群是否正常运行。同时,文章也提到了可能遇到的问题,如启动异常和集群无法启动,并给出了相应的解决建议。

docker 安装集群

1.准备工作

修改文件打开数

/etc/security/limits.conf

*       soft    nproc       65535

*       hard    nproc       65535

*       soft    nofile      65535

*       hard    nofile      65535


单个用户最大进程数

/etc/security/limits.d/20-nproc.conf

* soft nproc 65535

root soft nproc unlimited

用户单进程可以使用的最大map内存区域数量
cd  /etc/
vim sysctl.conf     添加vm.max_map_count = 262144
sysctl -p

创建文件目录:

mkdir -p /data/elasticsearch/data

mkdir -p /data/elasticsearch/config

mkdir -p /data/elasticsearch/plugins



mkdir -p /data/elasticsearch01/data

mkdir -p /data/elasticsearch01/config

mkdir -p /data/elasticsearch01/plugins



mkdir -p /data/elasticsearch02/data

mkdir -p /data/elasticsearch02/config

mkdir -p /data/elasticsearch02/plugins

2.安装与配置

 编辑节点1配置文件elasticsearch.yml,放置在config目录

cluster.name: "cluster"

# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
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: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["宿主机ip:9300","宿主机ip:9301","宿主机ip:9302"]
discovery.zen.minimum_master_nodes: 2

  编辑节点2配置文件elasticsearch.yml

cluster.name: "cluster"

# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
node.name: es-node2
network.bind_host: 0.0.0.0
network.publish_host: 宿主机ip
http.port: 9201
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["宿主机ip:9300","宿主机ip:9301","宿主机ip:9302"]
discovery.zen.minimum_master_nodes: 2

  编辑节点3配置文件elasticsearch.yml

cluster.name: "cluster"

# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
node.name: es-node3
network.bind_host: 0.0.0.0
network.publish_host: 宿主机ip
http.port: 9202
transport.tcp.port: 9302
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["宿主机ip:9300","宿主机ip:9301","宿主机ip:9302"]
discovery.zen.minimum_master_nodes: 2

执行docker run命令

docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-v /data/elasticsearch/config:/usr/share/elasticsearch/config \
-v /data/elasticsearch/data:/usr/share/elasticsearch/data \
-v  /data/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
-d elasticsearch:7.0.0

docker run --name elasticsearch01 -p 9201:9201 -p 9301:9301 \
-v /data/elasticsearch01/config:/usr/share/elasticsearch/config \
-v /data/elasticsearch01/data:/usr/share/elasticsearch/data \
-v  /data/elasticsearch01/plugins:/usr/share/elasticsearch/plugins \
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
-d elasticsearch:7.0.0

docker run --name elasticsearch02 -p 9202:9202 -p 9302:9302 \
-v /data/elasticsearch02/config:/usr/share/elasticsearch/config \
-v /data/elasticsearch02/data:/usr/share/elasticsearch/data \
-v  /data/elasticsearch02/plugins:/usr/share/elasticsearch/plugins \
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
-d elasticsearch:7.0.0

3.测试

http://宿主机:9200/_cluster/health?pretty

http://宿主机:9200/_cat/nodes?pretty

4 遇到的问题

4.1 docker启动elasticsearch异常Exception in thread "main" java.nio.file.NoSuchFileException: /usr/share/elasticsearch/config/jvm.options

 启动之后 通过 docker cp [容器ID]:容器文件路径  要拷贝的宿主机路径

4.2 elasticsearch 集群无法启动出现如下提示 failed to send join request to master

是因为复制的elasticsearch文件夹下包含了data文件中实例一的节点数据,需要把其它实例data文件下的文件清空

可以回答这个问题。Docker 安装 Elasticsearch 集群的步骤如下: 1. 首先,需要在 Docker安装 Elasticsearch 镜像。可以使用以下命令: docker pull elasticsearch:7.9.3 2. 接着,需要创建一个 Docker 网络,用于 Elasticsearch 集群的通信。可以使用以下命令: docker network create esnet 3. 然后,需要创建 Elasticsearch 集群的配置文件。可以使用以下命令: mkdir -p ~/esdata/node1 ~/esdata/node2 ~/esdata/node3 touch ~/esdata/node1/elasticsearch.yml ~/esdata/node2/elasticsearch.yml ~/esdata/node3/elasticsearch.yml 4. 编辑每个节点的配置文件,将以下内容添加到每个配置文件中: cluster.name: my-cluster node.name: node-1 # 每个节点的名称不同 network.host: ... discovery.seed_hosts: ["node-1", "node-2", "node-3"] cluster.initial_master_nodes: ["node-1", "node-2", "node-3"] 5. 最后,启动 Elasticsearch 集群。可以使用以下命令: docker run -d --name=node1 --net=esnet -p 920:920 -p 930:930 -v ~/esdata/node1:/usr/share/elasticsearch/data -e "discovery.type=single-node" -e "node.name=node-1" elasticsearch:7.9.3 docker run -d --name=node2 --net=esnet -v ~/esdata/node2:/usr/share/elasticsearch/data -e "discovery.seed_hosts=node1,node2,node3" -e "node.name=node-2" elasticsearch:7.9.3 docker run -d --name=node3 --net=esnet -v ~/esdata/node3:/usr/share/elasticsearch/data -e "discovery.seed_hosts=node1,node2,node3" -e "node.name=node-3" elasticsearch:7.9.3 注意:以上命令中的 IP 地址和端口号需要根据实际情况进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值