本文记录了使用Docker搭建ElasticSearch集群遇到的问题及解决方案
转载请注明:http://blog.csdn.net/sinat_28434649/article/details/79278975
OS:linux
Docker:1.6.2
ElasticSearch:5.5.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
#启动容器
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参数,可以查看到报错信息。
# 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
#删除原容器
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%
可通过 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%
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
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
--ulimit nofile=65536:131072
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
在Docker搭建ES时遇到不少问题,特此把问题记录下来希望对大家有所帮助。大家如果遇到其它问题可留言。