基于Docker方式实现Elasticsearch集群
文本環(huán)境:Docker + (Elasticsearch6.8.5 * 3)
1、拉取Elasticsearch
docker pull elasticsearch6.8.52、創(chuàng)建es掛載目錄
創(chuàng)建3個(gè)文件夾用于存放es掛載地址:es01、es02、es03
[root@CentOS7 ~]# mkdir /es-cluster [root@CentOS7 ~]# cd /es-cluster/ [root@CentOS7 es-cluster]# mkdir es01 [root@CentOS7 es-cluster]# mkdir es02 [root@CentOS7 es-cluster]# mkdir es033、創(chuàng)建配置文件及數(shù)據(jù)存放目錄
我們以es01 為例,cd es01,增加es01.yml配置文件:
# es01.yml cluster.name: elasticsearch-cluster node.name: es-node1 network.bind_host: 0.0.0.0 network.publish_host: 10.211.55.4 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: ["10.211.55.4:9300","10.211.55.4:9301","10.211.55.4:9302"] discovery.zen.minimum_master_nodes: 2其他兩個(gè)es配置文件類似:
# es02.yml cluster.name: elasticsearch-cluster node.name: es-node2 network.bind_host: 0.0.0.0 network.publish_host: 10.211.55.4 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: ["10.211.55.4:9300","10.211.55.4:9301","10.211.55.4:9302"] discovery.zen.minimum_master_nodes: 2# es03.yml cluster.name: elasticsearch-cluster node.name: es-node2 network.bind_host: 0.0.0.0 network.publish_host: 10.211.55.4 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: ["10.211.55.4:9300","10.211.55.4:9301","10.211.55.4:9302"] discovery.zen.minimum_master_nodes: 2由于默認(rèn)es實(shí)例是1g,太吃內(nèi)存了,我們修改一下jvm參數(shù),每個(gè)es目錄下放一個(gè)jvm.option文件:
-Xms128m -Xmx128m4、創(chuàng)建es容器并啟動(dòng)
docker create --name es01 --net host -v /es-cluster/es01/es01.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /es-cluster/es01/jvm.options:/usr/share/elasticsearch/config/jvm.options -v /es-cluster/es01/data:/usr/share/elasticsearch/data elasticsearch:6.8.5docker create --name es02 --net host -v /es-cluster/es02/es02.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /es-cluster/es02/jvm.options:/usr/share/elasticsearch/config/jvm.options -v /es-cluster/es02/data:/usr/share/elasticsearch/data elasticsearch:6.8.5docker create --name es03 --net host -v /es-cluster/es03/es03.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /es-cluster/es03/jvm.options:/usr/share/elasticsearch/config/jvm.options -v /es-cluster/es03/data:/usr/share/elasticsearch/data elasticsearch:6.8.5創(chuàng)建完docker容器后,啟動(dòng)es容器:
docker start es01 es02 es03通過 docker ps -a 查看啟動(dòng)情況如圖所示,啟動(dòng)失敗了,我們通過 docker logs es01 查看啟動(dòng)日志:
data目錄訪問權(quán)限異常,我們給一下權(quán)限:
chmod 777 es01/data/ -R chmod 777 es02/data/ -R chmod 777 es03/data/ -R重新啟動(dòng)一下:
docker start es01 es02 es03在Elasticsearch-head中連接一下集群:
5、Elasticsearch-head安裝
elasticsearch-head 是用于監(jiān)控 Elasticsearch 狀態(tài)的客戶端插件,包括數(shù)據(jù)可視化、執(zhí)行增刪改查操作等。elasticsearch-head 插件的安裝在 Linux 和 Windows 沒什么區(qū)別,安裝之前確保當(dāng)前系統(tǒng)已經(jīng)安裝 nodejs 即可。
github地址:https://github.com/mobz/elasticsearch-head
如下是安裝命令:
# git 克隆 git clone git://github.com/mobz/elasticsearch-head.git # 進(jìn)入下載目錄 cd elasticsearch-head # 安裝依賴「需要node緩解」 npm install # 運(yùn)行 npm run start瀏覽器訪問:http://127.0.0.1:9100
6、最后補(bǔ)充
至此,基于Docker的Elasticsearch簡(jiǎn)單集群就搭建完了,下一篇我們將通過創(chuàng)建索引實(shí)例來介紹分片和副本,以及集群的 故障轉(zhuǎn)移 等知識(shí)點(diǎn)。
推薦閱讀:
重溫Elasticsearch
elasticsearch集群搭建-windows
了解一下Elasticsearch的基本概念
用Elasticsearch代替數(shù)據(jù)庫存儲(chǔ)日志方式
總結(jié)
以上是生活随笔為你收集整理的基于Docker方式实现Elasticsearch集群的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c++写入二进制、TXT文件,读取二进制
- 下一篇: HDU 2461 Rectangles#