Docker搭建ES集群及问题总结

本文记录了使用Docker搭建ElasticSearch集群遇到的问题及解决方案

转载请注明:http://blog.csdn.net/sinat_28434649/article/details/79278975

说明:

 可直接阅读【8、创建集群总结】【9、问题总结】,也可按顺序阅读

1、环境说明:

OS:linux
Docker:1.6.2
ElasticSearch:5.5.2

2、安装镜像

root>docker search elasticsearch
NAME                                  DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
elasticsearch                         Elasticsearch is a powerful open source se...    2692      [OK]       
kibana                                Kibana gives shape to any kind of data —...     1093      [OK] 
root>docker pull elasticsearch

3、启动单个容器

#启动容器
root> docker run --name es1 elasticsearch
28ed1052f7b2c9d11fdec0179066e71ffc3cc4ae8ff15552a9909f006ebfbc47
#查看容器
root> docker ps
CONTAINER ID        IMAGE                  COMMAND                CREATED              STATUS              PORTS                NAMES
28ed1052f7b2        elasticsearch:latest   "/docker-entrypoint.   About a minute ago   Up About a minute   9200/tcp, 9300/tcp   es1
#进入容器,并查看es
root> docker exec -it es1 /bin/bash
ERRO[0000] Unable to connect to local syslog daemon     
root@28ed1052f7b2:/usr/share/elasticsearch# curl http://localhost:9200/_cat/health
1517982628 05:50:28 elasticsearch green 1 1 0 0 0 0 0 0 - 100.0%

注意:docker run -d  参数可以在后台创建并启动容器,初次创建时,建议不加-d参数,可以查看到报错信息。

4、启动另一个容器

集群需要开启配置:
# Uncomment the following lines for a production cluster deployment
#transport.host: 0.0.0.0
#discovery.zen.minimum_master_nodes: 1
参考 文档
docker run --name es2 --link es1:es1 elasticsearch -Ediscovery.zen.ping.unicast.hosts=es1:9300 -Etransport.host=0.0.0.0
异常:
ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[3]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

上述问题可查看官方文档

解决方案

步骤1:修改服务器vm.max_map_count参数

root>sysctl -w vm.max_map_count=262144
root>sysctl -p

步骤2:

通过--umlmit参数修改配置(docker 1.6以后有效)

#删除原容器
root>docker rm -f es1 es2
#创建es1
root>docker run --name es1 --ulimit nofile=65536:131072 elasticsearch -Etransport.host=0.0.0.0  -Ebootstrap.system_call_filter=false
#创建es2
root>docker run --name es2 --ulimit nofile=65536:131072 --link es1:es1 elasticsearch -Ediscovery.zen.ping.unicast.hosts=es1:9300 -Etransport.host=0.0.0.0  -Ebootstrap.system_call_filter=false
root>docker exec -it es2 /bin/bash
ERRO[0000] Unable to connect to local syslog daemon     
root@7f68583cce29:/usr/share/elasticsearch# curl http://localhost:9200/_cat/health                                                                              
1517986600 06:56:40 elasticsearch green 2 2 0 0 0 0 0 0 - 100.0%

注意:启动es2前,需要先启动es1

5、对外暴露接口

通过-p 9201:9200 参数暴露容器接口
#删除原容器
root>docker rm -f es1 es2
#创建es1
root>docker run --name es1 -p 9201:9200 --ulimit nofile=65536:131072 elasticsearch -Etransport.host=0.0.0.0  -Ebootstrap.system_call_filter=false
#创建es2
root>docker run --name es2 --ulimit nofile=65536:131072 --link es1:es1 elasticsearch -Ediscovery.zen.ping.unicast.hosts=es1:9300 -Etransport.host=0.0.0.0  -Ebootstrap.system_call_filter=false
#本地查看es情况
root> curl http://localhost:9201/_cat/health
1517987309 07:08:29 elasticsearch green 2 2 0 0 0 0 0 0 - 100.0%

6、修改JVM启动参数

可通过 ES_JAVA_OPTS 环境变量修改JVM参数

#删除原容器
root>docker rm -f es1 es2
#创建es1
root>docker run --name es1 -p 9201:9200 --ulimit nofile=65536:131072  -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" -d elasticsearch -Etransport.host=0.0.0.0  -Ebootstrap.system_call_filter=false
#创建es2
root>docker run --name es2 --ulimit nofile=65536:131072 --link es1:es1  -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" -d elasticsearch -Ediscovery.zen.ping.unicast.hosts=es1:9300 -Etransport.host=0.0.0.0  -Ebootstrap.system_call_filter=false
#本地查看es情况
root> curl http://localhost:9201/_cat/health
1517987309 07:08:29 elasticsearch green 2 2 0 0 0 0 0 0 - 100.0%

7、通过elasticsearch.yml配置文件启动

node1/config/elasticsearch.yml

http.host: 0.0.0.0
cluster.name: elastic-cky
node.name: elastic-01
node.master: true
node.data: true
bootstrap.system_call_filter: false

# Uncomment the following lines for a production cluster deployment
transport.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1

node2/config/elasticsearch.yml

http.host: 0.0.0.0
cluster.name: elastic-cky
node.name: elastic-02
node.master: true
node.data: true
bootstrap.system_call_filter: false


# Uncomment the following lines for a production cluster deployment
transport.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.unicast.hosts: ["es1:9300"]

启动容器


 root>docker run --name es1 -p 9201:9200 -v "$PWD/node1/config/elasticsearch.yml":/usr/share/elasticsearch/config/elasticsearch.yml --ulimit nofile=65536:131072  -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" -d elasticsearch 

 root>docker run --name es2 -v "$PWD/node2/config/elasticsearch.yml":/usr/share/elasticsearch/config/elasticsearch.yml --ulimit nofile=65536:131072 --link es1:es1  -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" -d elasticsearch 

查看集群健康情况

curl http://localhost:9201/_cat/health

8、创建集群总结

 无配置文件:创建命令如下,若有异常参见【9、问题总结】
root>docker run --name es1 -p 9201:9200 --ulimit nofile=65536:131072 elasticsearch -Etransport.host=0.0.0.0  -Ebootstrap.system_call_filter=false
root>docker run --name es2 --ulimit nofile=65536:131072 --link es1:es1 elasticsearch -Ediscovery.zen.ping.unicast.hosts=es1:9300 -Etransport.host=0.0.0.0  -Ebootstrap.system_call_filter=false

yml配置文件:创建命令参见【7、通过elasticsearch.yml配置文件启动】
个人推荐使用yml配置文件创建ES,便于后期修改配置。

9、问题总结

1: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
--ulimit nofile=65536:131072
2: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
root>sysctl -w vm.max_map_count=262144
root>sysctl -p
3: system call filters failed to install; check the logs and fix your configuration or disable system call
-Ebootstrap.system_call_filter=false

4: Maximum number of threads check

 --ulimit nproc=2048:4096


10、结束语

在Docker搭建ES时遇到不少问题,特此把问题记录下来希望对大家有所帮助。大家如果遇到其它问题可留言。

11、参考文档

https://www.elastic.co/guide/en/elasticsearch/reference/5.5/max-number-threads-check.html
https://hub.docker.com/_/elasticsearch/
http://dockone.io/question/293
https://www.cnblogs.com/yy-cxd/p/6553624.html

你可能感兴趣的:(Docker,ElasticSearch)