es集群构建:
1、安装head插件:
for Elasticsearch 5.x: docker run -p 9100:9100 mobz/elasticsearch-head:5
( docker run -p 9100:9100 10.211.121.26/library/elasticsearch-head )
出现问题
head主控页面是可以显示的,但是显示连接失败
“集群健康值: 未连接”
解决方案
修改elasticsearch.yml文件
vim $ES_HOME$/config/elasticsearch.yml
# 增加如下字段
http.cors.enabled: true
http.cors.allow-origin: "*"
运行:docker run -d -p 9100:9100 --name eshead 10.211.121.26/library/elasticsearch-head:5
2、安装中文分页插件:
use elasticsearch-plugin to install ( version > v5.5.1 ):
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.1/elasticsearch-analysis-ik-5.5.1.zip
3、修改系统参数:sysctl -w vm.max_map_count=262144
4、启动elasticsearch集群:
master:
docker run -d -p 9200:9200 -p 9300:9300 -v /data0/elasticsearch/data:/usr/share/elasticsearch/data -v /data0/elasticsearch/logs:/usr/share/elasticsearch/logs --name elasticsearch 10.211.121.26/library/elasticsearch:5.5.1_ik
docker cp elasticsearch.yml elasticsearch:/usr/share/elasticsearch/config/elasticsearch.yml
data:
docker run -d -p 9200:9200 -p 9300:9300 -v /data0/elasticsearch/data:/usr/share/elasticsearch/data -v /data0/elasticsearch/logs:/usr/share/elasticsearch/logs --name elasticsearch 10.211.121.26/library/elasticsearch:5.5.1_ik
docker cp elasticsearch.yml elasticsearch:/usr/share/elasticsearch/config/elasticsearch.yml
5、启动kibana
docker run --name kibana -e ELASTICSEARCH_URL=http://10.39.10.224:9200 -p 5601:5601 -d kibana:5.5.1
##################################################
如下为yml配置文件es.yml :
version: '3.2'
services:
es_master:
image: '10.211.121.26/library/elasticsearch:5.5.1_ik'
#command: [ elasticsearch, -E, network.host=0.0.0.0, -E, discovery.zen.ping.unicast.hosts=10.0.0.3, -E, discovery.zen.minimum_master_nodes=1 ]
command: [ elasticsearch, -E, network.host=0.0.0.0, -E, discovery.zen.ping.unicast.hosts=es_master, -E, discovery.zen.minimum_master_nodes=1, -E, node.master=true ]
volumes:
- /data0/elasticsearch/data:/usr/share/elasticsearch/data
- /data0/elasticsearch/logs:/usr/share/elasticsearch/logs
#目录必须在主机节点存在
networks:
esnet:
deploy:
replicas: 3
#默认是使用的vip模式,集群无法搭建成功。添加dnsrr后ok
endpoint_mode: dnsrr
placement:
constraints: [node.labels.app_role == elasticsearch]
nginx:
image: 'nginx:1'
ports:
- '9200:9200'
command: |
/bin/bash -c "echo '
server {
listen 9200;
add_header X-Frame-Options "SAMEORIGIN";
location / {
#proxy_pass http://elasticsearch:9200;
proxy_pass http://es_master:9200;
proxy_http_version 1.1;
proxy_set_header Connection keep-alive;
proxy_set_header Upgrade $$http_upgrade;
proxy_set_header Host $$host;
proxy_set_header X-Real-IP $$remote_addr;
proxy_cache_bypass $$http_upgrade;
}
}' | tee /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
networks:
esnet:
#ipv4_address: 12.0.0.100
eshead:
image: '10.211.121.26/library/elasticsearch-head:5'
ports:
- '9100:9100'
networks:
esnet:
networks:
esnet:
driver: overlay
ipam:
driver: default
config:
- subnet: 12.0.0.0/24
#在主机上给指定的node 添加 elasticsearch 标签,限制es节点运行在指定主机上。
# docker node update --label-add app_role=elasticsearch nodename
#
#在swarm master节点运行: docker stack deploy -c es.yml es001 ,docker将自动完成集群创建操作。
#