docker 安装es集群

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值