本篇文章为大家展示了docker如何搭建elasticsearch集群,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
为陇县等地区用户提供了全套网页设计制作服务,及陇县网站建设行业解决方案。主营业务为成都网站设计、做网站、陇县网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
docker pull docker.io/elasticsearch:5.6.8
mkdir -p /docker/es/config mkdir -p /docker/es/data1 mkdir -p /docker/es/data2 mkdir -p /docker/es/data3
touch /docker/es/config/es1.yml touch /docker/es/config/es2.yml touch /docker/es/config/es3.yml
es1.yml文件内容为:
cluster.name: elasticsearch-cluster node.name: es-node1 network.bind_host: 0.0.0.0 network.publish_host: 192.168.100.102 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: ["192.168.100.102:9300","192.168.100.102:9301","192.168.100.102:9302"] discovery.zen.minimum_master_nodes: 2
es2.yml文件内容为:
cluster.name: elasticsearch-cluster node.name: es-node2 network.bind_host: 0.0.0.0 network.publish_host: 192.168.100.102 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: ["192.168.100.102:9300","192.168.100.102:9301","192.168.100.102:9302"] discovery.zen.minimum_master_nodes: 2
es3.yml文件内容为:
cluster.name: elasticsearch-cluster node.name: es-node3 network.bind_host: 0.0.0.0 network.publish_host: 192.168.100.102 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: ["192.168.100.102:9300","192.168.100.102:9301","192.168.100.102:9302"] discovery.zen.minimum_master_nodes: 2
在 /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144
执行下面命令
sysctl -w vm.max_map_count=262144
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 --privileged=true -v /docker/es/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /docker/es/data1:/usr/share/elasticsearch/data --name es-node1 elasticsearch:5.6.8
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9201:9201 -p 9301:9301 --privileged=true -v /docker/es/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /docker/es/data2:/usr/share/elasticsearch/data --name es-node2 elasticsearch:5.6.8
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9202:9202 -p 9302:9302 --privileged=true -v /docker/es/config/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /docker/es/data3:/usr/share/elasticsearch/data --name es-node3 elasticsearch:5.6.8
docker pull mobz/elasticsearch-head:5 docker run -di --name=es-head -p 9100:9100 docker.io/mobz/elasticsearch-head:5
下载分词器插件:https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v5.6.8
在宿主机解压
unzip elasticsearch-analysis-ik-5.6.8.zip
并改文件夹名为ik
mv elasticsearch ik
复制解压后的ik到docker镜像目录
docker cp ik es-node1:/usr/share/elasticsearch/plugins
docker restart 容器id
如果要单点运行 ,可以把es-node2 es-node3 停掉 并且注释掉es1.yml配置文件中的部分配置
cluster.name: elasticsearch-cluster node.name: es-node1 network.bind_host: 0.0.0.0 http.port: 9200 transport.tcp.port: 9300 http.cors.enabled: true http.cors.allow-origin: "*" node.data: true #network.publish_host: 192.168.100.102 #node.master: true #discovery.zen.ping.unicast.hosts: ["192.168.100.102:9300","192.168.100.102:9301","192.168.100.102:9302"] #discovery.zen.minimum_master_nodes: 2
docker run -it -d -e ELASTICSEARCH_URL=http://172.17.0.2:9200 --name kibana -p 5601:5601 kibana:5.6.8
es 的 URL要写容器内部的ip,查看容器内部的ip命令
docker inspect
上述内容就是docker如何搭建elasticsearch集群,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。