docker 安装集群

docker 安装集群,第1张

docker 安装集群

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文件下的文件清空

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5679566.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存