今天小編給大家分享一下如何使用docker部署Elasticsearch集群的相關(guān)知識(shí)點(diǎn),內(nèi)容詳細(xì),邏輯清晰,相信大部分人都還太了解這方面的知識(shí),所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的吉林網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
注意,6.x
版本已經(jīng)不能通過 -epath.config
參數(shù)去指定配置文件的加載位置,文檔說明:
for the archive distributions, the config directory location defaults to$es_home/config
. the location of the >config directorycan be changed
via thees_path_conf
environment variable as follows:es_path_conf=/path/to/my/config ./bin/elasticsearch
alternatively, you can export the es_path_conf environment variable via the command line or via your shell profile.
即交給環(huán)境變量 es_path_conf
來設(shè)定了(),單機(jī)部署多個(gè)實(shí)例且不使用容器的同學(xué)多多注意。
準(zhǔn)備工作
安裝 docker
& docker-compose
這里推進(jìn)使用 daocloud 做個(gè)加速安裝:
#docker curl -ssl https://get.daocloud.io/docker | sh #docker-compose curl -l \ https://get.daocloud.io/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` \ > /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose #查看安裝結(jié)果 docker-compose -v
數(shù)據(jù)目錄
#創(chuàng)建數(shù)據(jù)/日志目錄 這里我們部署3個(gè)節(jié)點(diǎn) mkdir /opt/elasticsearch/data/{node0,nod1,node2} -p mkdir /opt/elasticsearch/logs/{node0,nod1,node2} -p cd /opt/elasticsearch #權(quán)限我也很懵逼啦 給了 privileged 也不行 索性0777好了 chmod 0777 data/* -r && chmod 0777 logs/* -r #防止jvm報(bào)錯(cuò) echo vm.max_map_count=262144 >> /etc/sysctl.conf sysctl -p
docker-compse 編排服務(wù)
創(chuàng)建編排文件
vim docker-compose.yml
參數(shù)說明
- cluster.name=elasticsearch-cluster
集群名稱
- node.name=node0
- node.master=true
- node.data=true
節(jié)點(diǎn)名稱、是否可作為主節(jié)點(diǎn)、是否存儲(chǔ)數(shù)據(jù)
- bootstrap.memory_lock=true
鎖定進(jìn)程的物理內(nèi)存地址避免交換(swapped)來提高性能
- http.cors.enabled=true
- http.cors.allow-origin=*
開啟cors以便使用head插件
- "es_java_opts=-xms512m -xmx512m"
jvm內(nèi)存大小配置
- "discovery.zen.ping.unicast.hosts=elasticsearch_n0,elasticsearch_n1,elasticsearch_n2"
- "discovery.zen.minimum_master_nodes=2"
由于5.2.1
后的版本是不支持多播的,所以需要手動(dòng)指定集群各節(jié)點(diǎn)的tcp
數(shù)據(jù)交互地址,用于集群的節(jié)點(diǎn)發(fā)現(xiàn)
和failover
,默認(rèn)缺省9300
端口,如設(shè)定了其它端口需另行指定,這里我們直接借助容器通信,也可以將各節(jié)點(diǎn)的9300
映射至宿主機(jī),通過網(wǎng)絡(luò)端口通信。
設(shè)定failover
選取的quorum = nodes/2 + 1
當(dāng)然,也可以掛載自己的配置文件,es
鏡像的配置文件是/usr/share/elasticsearch/config/elasticsearch.yml
,掛載如下:
volumes: - path/to/local/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro
docker-compose.yml
version: '3' services: elasticsearch_n0: image: elasticsearch:6.6.2 container_name: elasticsearch_n0 privileged: true environment: - cluster.name=elasticsearch-cluster - node.name=node0 - node.master=true - node.data=true - bootstrap.memory_lock=true - http.cors.enabled=true - http.cors.allow-origin=* - "es_java_opts=-xms512m -xmx512m" - "discovery.zen.ping.unicast.hosts=elasticsearch_n0,elasticsearch_n1,elasticsearch_n2" - "discovery.zen.minimum_master_nodes=2" ulimits: memlock: soft: -1 hard: -1 volumes: - ./data/node0:/usr/share/elasticsearch/data - ./logs/node0:/usr/share/elasticsearch/logs ports: - 9200:9200 elasticsearch_n1: image: elasticsearch:6.6.2 container_name: elasticsearch_n1 privileged: true environment: - cluster.name=elasticsearch-cluster - node.name=node1 - node.master=true - node.data=true - bootstrap.memory_lock=true - http.cors.enabled=true - http.cors.allow-origin=* - "es_java_opts=-xms512m -xmx512m" - "discovery.zen.ping.unicast.hosts=elasticsearch_n0,elasticsearch_n1,elasticsearch_n2" - "discovery.zen.minimum_master_nodes=2" ulimits: memlock: soft: -1 hard: -1 volumes: - ./data/node1:/usr/share/elasticsearch/data - ./logs/node1:/usr/share/elasticsearch/logs ports: - 9201:9200 elasticsearch_n2: image: elasticsearch:6.6.2 container_name: elasticsearch_n2 privileged: true environment: - cluster.name=elasticsearch-cluster - node.name=node2 - node.master=true - node.data=true - bootstrap.memory_lock=true - http.cors.enabled=true - http.cors.allow-origin=* - "es_java_opts=-xms512m -xmx512m" - "discovery.zen.ping.unicast.hosts=elasticsearch_n0,elasticsearch_n1,elasticsearch_n2" - "discovery.zen.minimum_master_nodes=2" ulimits: memlock: soft: -1 hard: -1 volumes: - ./data/node2:/usr/share/elasticsearch/data - ./logs/node2:/usr/share/elasticsearch/logs ports: - 9202:9200
這里我們分別為node0/node1/node2
開放宿主機(jī)的9200/9201/9202
作為http服務(wù)端口
,各實(shí)例的tcp數(shù)據(jù)傳輸
用默認(rèn)的9300
通過容器管理通信。
如果需要多機(jī)部署,則將es
的transport.tcp.port: 9300
端口映射至宿主機(jī)xxxx
端口,discovery.zen.ping.unicast.hosts
填寫各主機(jī)代理的地址即可:
#比如其中一臺(tái)宿主機(jī)為192.168.1.100 ... - "discovery.zen.ping.unicast.hosts=192.168.1.100:9300,192.168.1.101:9300,192.168.1.102:9300" ... ports: ... - 9300:9300
創(chuàng)建并啟動(dòng)服務(wù)
[root@localhost elasticsearch]# docker-compose up -d [root@localhost elasticsearch]# docker-compose ps name command state ports -------------------------------------------------------------------------------------------- elasticsearch_n0 /usr/local/bin/docker-entr ... up 0.0.0.0:9200->9200/tcp, 9300/tcp elasticsearch_n1 /usr/local/bin/docker-entr ... up 0.0.0.0:9201->9200/tcp, 9300/tcp elasticsearch_n2 /usr/local/bin/docker-entr ... up 0.0.0.0:9202->9200/tcp, 9300/tcp #啟動(dòng)失敗查看錯(cuò)誤 [root@localhost elasticsearch]# docker-compose logs #最多是一些訪問權(quán)限/jvm vm.max_map_count 的設(shè)置問題
查看集群狀態(tài)
192.168.20.6 是我的服務(wù)器地址
訪問http://192.168.20.6:9200/_cat/nodes?v
即可查看集群狀態(tài):
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 172.25.0.3 36 98 79 3.43 0.88 0.54 mdi * node0 172.25.0.2 48 98 79 3.43 0.88 0.54 mdi - node2 172.25.0.4 42 98 51 3.43 0.88 0.54 mdi - node1
驗(yàn)證 failover
通過集群接口查看狀態(tài)
模擬主節(jié)點(diǎn)下線,集群開始選舉新的主節(jié)點(diǎn),并對(duì)數(shù)據(jù)進(jìn)行遷移,重新分片。
[root@localhost elasticsearch]# docker-compose stop elasticsearch_n0 stopping elasticsearch_n0 ... done
集群狀態(tài)(注意換個(gè)http端口 原主節(jié)點(diǎn)下線了),down掉的節(jié)點(diǎn)還在集群中,等待一段時(shí)間仍未恢復(fù)后就會(huì)被剔出
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 172.25.0.2 57 84 5 0.46 0.65 0.50 mdi - node2 172.25.0.4 49 84 5 0.46 0.65 0.50 mdi * node1 172.25.0.3 mdi - node0
等待一段時(shí)間
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 172.25.0.2 44 84 1 0.10 0.33 0.40 mdi - node2 172.25.0.4 34 84 1 0.10 0.33 0.40 mdi * node1
恢復(fù)節(jié)點(diǎn) node0
[root@localhost elasticsearch]# docker-compose start elasticsearch_n0 starting elasticsearch_n0 ... done
等待一段時(shí)間
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 172.25.0.2 52 98 25 0.67 0.43 0.43 mdi - node2 172.25.0.4 43 98 25 0.67 0.43 0.43 mdi * node1 172.25.0.3 40 98 46 0.67 0.43 0.43 mdi - node0
配合 head 插件觀察
git clone git://github.com/mobz/elasticsearch-head.git cd elasticsearch-head npm install npm run start
集群狀態(tài)圖示更容易看出數(shù)據(jù)自動(dòng)遷移的過程
1、集群正常 數(shù)據(jù)安全分布在3個(gè)節(jié)點(diǎn)上
2、下線 node1 主節(jié)點(diǎn) 集群開始遷移數(shù)據(jù)
遷移中
遷移完成
3、恢復(fù) node1 節(jié)點(diǎn)
問題小記
elasticsearch watermark
部署完后創(chuàng)建索引發(fā)現(xiàn)有些分片處于 unsigned 狀態(tài),是由于 elasticsearch watermark:low,high,flood_stage的限定造成的,默認(rèn)硬盤使用率高于85%
就會(huì)告警,開發(fā)嘛,手動(dòng)關(guān)掉好了,數(shù)據(jù)會(huì)分片到各節(jié)點(diǎn),生產(chǎn)自行決斷。
curl -x put http://192.168.20.6:9201/_cluster/settings \ -h 'content-type':'application/json' \ -d '{"transient":{"cluster.routing.allocation.disk.threshold_enabled": false}}'
以上就是“如何使用docker部署Elasticsearch集群”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,小編每天都會(huì)為大家更新不同的知識(shí),如果還想學(xué)習(xí)更多的知識(shí),請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)站名稱:如何使用docker部署Elasticsearch集群
當(dāng)前地址:http://aaarwkj.com/article4/pphpie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、域名注冊、小程序開發(fā)、商城網(wǎng)站、做網(wǎng)站、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)