NO IMAGE

本文記錄了使用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     
[email protected]:/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     
[email protected]:/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