elasticsearch?組件基于單機(jī)的多實(shí)例集群部署方法
聲明:
本示例主要作為測(cè)試用,生產(chǎn)請(qǐng)慎重。
最近公司突發(fā)奇想,想讓我們搞個(gè)單機(jī)多實(shí)例的 es 的集群,看看其性能咋樣。通常來說,es 作為搜索引擎,應(yīng)用場(chǎng)景不乏日志分析、網(wǎng)絡(luò)安全、搜索引擎等,有時(shí)也會(huì)用作日志數(shù)據(jù)庫(kù)使用,畢竟其出色的搜索查詢性能,不是同等量級(jí) 關(guān)系型數(shù)據(jù)庫(kù)可以比擬的,主要還是因?yàn)槠?倒排索引 的特殊性,這里不討論 倒排索引 與 B+ Tree 的性能,我們主要看看這種集群怎么組建的。
環(huán)境準(zhǔn)備:
- ubuntu,24核,64G
- docker 20.10.2
因?yàn)槭?es 集群,我們準(zhǔn)備通過 docker 來創(chuàng)建實(shí)例,所以之前你還得先 pull es、kibana 的 image:
docker pull elasticsearch:6.8.23 docker pull kibana:6.8.23
如果你的容器有限,可以直接通過腳本運(yùn)行 docker run,但是如果容器數(shù)量多還有相關(guān)依賴,建議通過 容器編排 起容器,當(dāng)然數(shù)量更大的情況下,建議通過 k8s 部署。
我們的集群主要包含 3 個(gè) es 節(jié)點(diǎn),外加一個(gè) kibana 作為觀測(cè),所以通過 docker-compose 作為容器編排,相對(duì)合適。
接下來是我們的編排定義:docker-compose.yml
version: "2.3" services: es-0: image: elasticsearch:6.8.23 hostname: es-0 container_name: es-0 environment: - bootstrap.memory_lock=true ulimits: memlock: soft: -1 hard: -1 cap_add: - IPC_LOCK volumes: - /var/xxx/es_cluster/es-0:/usr/share/elasticsearch/data # 容器數(shù)據(jù)映射 - ./es_cluster/es-0/elasticsearch:/etc/default/elasticsearch # elasticsearch 文件映射 - ./es_cluster/es-0/config:/usr/share/elasticsearch/config # 配置映射,主要是 elasticsearch.yaml 和 jvm.options - /var/log/es_cluster/es-0/logs:/usr/share/elasticsearch/logs # 日志映射 - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime # 時(shí)間 - /etc/timezone:/etc/timezone #- ./elasticsearch/jvm.options:/etc/elasticsearch/jvm.options ports: - "9200:9200" # 端口映射 command: elasticsearch logging: options: max-size: "200M" max-file: "5" networks: app_net: ipv4_address: 172.238.238.219 healthcheck: test: ["CMD", "curl", "-f", "-s", "http://172.238.238.219:9200/_cluster/health?wait_for_status=yellow&timeout=50s"] interval: 30s timeout: 10s retries: 20 restart: always es-1: image: elasticsearch:6.8.23 hostname: es-1 container_name: es-1 environment: - bootstrap.memory_lock=true ulimits: memlock: soft: -1 hard: -1 cap_add: - IPC_LOCK volumes: - /var/xxx/es_cluster/es-1:/usr/share/elasticsearch/data - ./es_cluster/es-1/elasticsearch:/etc/default/elasticsearch - ./es_cluster/es-1/config:/usr/share/elasticsearch/config - /var/log/es_cluster/es-1/logs:/usr/share/elasticsearch/logs - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime - /etc/timezone:/etc/timezone #- ./elasticsearch/jvm.options:/etc/elasticsearch/jvm.options ports: - "9201:9201" command: elasticsearch logging: options: max-size: "200M" max-file: "5" networks: app_net: ipv4_address: 172.238.238.229 healthcheck: test: ["CMD", "curl", "-f", "-s", "http://172.238.238.229:9200/_cluster/health?wait_for_status=yellow&timeout=50s"] interval: 30s timeout: 10s retries: 20 restart: always es-2: image: elasticsearch:6.8.23 hostname: es-2 container_name: es-2 environment: - bootstrap.memory_lock=true ulimits: memlock: soft: -1 hard: -1 cap_add: - IPC_LOCK volumes: - /var/xxx/es_cluster/es-2:/usr/share/elasticsearch/data - ./es_cluster/es-2/elasticsearch:/etc/default/elasticsearch - ./es_cluster/es-2/config:/usr/share/elasticsearch/config - /var/log/es_cluster/es-2/logs:/usr/share/elasticsearch/logs - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime - /etc/timezone:/etc/timezone #- ./elasticsearch/jvm.options:/etc/elasticsearch/jvm.options ports: - "9202:9202" command: elasticsearch logging: options: max-size: "200M" max-file: "5" networks: app_net: ipv4_address: 172.238.238.239 healthcheck: test: ["CMD", "curl", "-f", "-s", "http://172.238.238.239:9200/_cluster/health?wait_for_status=yellow&timeout=50s"] interval: 30s timeout: 10s retries: 20 restart: always kibana: image: kibana:6.8.23 hostname: kibana container_name: kibana volumes: - ./kibana/kibana.yml:/usr/share/kibana/config/kibana.yml - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime - /etc/timezone:/etc/timezone - ./kibana/kibana.keystore:/usr/share/kibana/data/kibana.keystore ports: - "5601:5601" networks: app_net: ipv4_address: 172.238.238.242 restart: always logging: options: max-size: "200M" max-file: "5" networks: app_net: driver: bridge ipam: driver: default config: - subnet: 172.238.238.0/24
這里限定 docker 的網(wǎng)絡(luò)網(wǎng)段。
然后我們要看看對(duì)應(yīng)的其他準(zhǔn)備。
主要看我們的對(duì)應(yīng)到主機(jī)中的 data 目錄,所以參考 yml 中的相關(guān)映射,注意創(chuàng)建相關(guān)目錄。
這里我們主要看看相關(guān)的 elasticsearch.yaml 和 jvm.options。
elasticsearch.yml
cluster: name: logserver ################# node.name: es-0 # 其他節(jié)點(diǎn)類似,修改 node name discovery.zen.ping.unicast.hosts: ["es-0", "es-1", "es-2"] network.host: 0.0.0.0 discovery.zen.minimum_master_nodes: 2 gateway.recover_after_nodes: 3 http.port: 9200 transport.tcp.port: 9300 node.master: true node.data: true http.host: 0.0.0.0 http: enabled: true compression: true cors: enabled: true allow-origin: "*" bootstrap.memory_lock: true bootstrap.system_call_filter: false path.data: /usr/share/elasticsearch/data #cluster.routing.allocation.disk.threshold_enabled: true #cluster.routing.allocation.disk.watermark.flood_stage: 80gb #cluster.routing.allocation.disk.watermark.high: 100gb #cluster.routing.allocation.disk.watermark.low: 120gb ##Lock memory, do not write swap #bootstrap.mlockall: true ##The cache type is set to Soft Reference, ##and is reclaimed only if there is not enough memory #index.cache.field.max_size: 50000 #index.cache.field.expire: 10m #index.cache.field.type: soft ##Weighing the performance of the index and the timeliness of retrieval #index.translog.flush_threshold_ops: 10000 #index.refresh_interval: 1 #number_of_replicas: 0 #indices.lifecycle.poll_interval: 5m xpack.ml.enabled: false
jvm.options
... # Xms represents the initial size of total heap space # Xmx represents the maximum size of total heap space -Xms16g # 主機(jī)內(nèi)存64G,每個(gè)實(shí)例分配16G -Xmx16g ################################################################ ## Expert settings ################################################################ ## ...
這兩個(gè)文件按照上面內(nèi)容修改。
接下來是 kibana.yml:
... elasticsearch.url: "http://172.xxx.xxx.xxx:9200" # 根據(jù)實(shí)際情況,填入自己的主機(jī)ip ...
接下來通過 docker-compose 命令就可以起容器了。
docker-compsoe up -d # 后臺(tái)運(yùn)行容器 docker-compose ps # 查看容器運(yùn)行狀態(tài) docker-compose down # 停掉容器
接下來看看容器狀態(tài):
# docker-compose ps Name Command State Ports --------------------------------------------------------------------------------------------------- es-0 /usr/local/bin/docker-entr ... Up (healthy) 0.0.0.0:9200->9200/tcp, 9300/tcp es-1 /usr/local/bin/docker-entr ... Up (healthy) 9200/tcp, 0.0.0.0:9201->9201/tcp, 9300/tcp es-2 /usr/local/bin/docker-entr ... Up (healthy) 9200/tcp, 0.0.0.0:9202->9202/tcp, 9300/tcp kibana /usr/local/bin/kibana-docker Up 0.0.0.0:5601->5601/tcp
通過 kibana 查看容器狀態(tài):
其他看板:
可以看到,es 集群已經(jīng)順利起來了,集群實(shí)例就演示到這里,希望對(duì)你有用。
到此這篇關(guān)于elasticsearch 組件基于單機(jī)的多實(shí)例集群的文章就介紹到這了,更多相關(guān)elasticsearch 單機(jī)多實(shí)例集群內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用Docker+Jenkins自動(dòng)構(gòu)建部署
這篇文章主要介紹了使用Docker+Jenkins自動(dòng)構(gòu)建部署,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03使用Docker Compose部快速署ELK(親測(cè)有效)
這篇文章主要介紹了Docker Compose部署ELK的詳細(xì)過程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-08-08一文詳解如何在Ubuntu系統(tǒng)中安裝docker
這篇文章主要為大家詳細(xì)介紹了在Ubuntu操作系統(tǒng)上安裝Docker的步驟,以便我們可以開始使用Docker來構(gòu)建和運(yùn)行容器化應(yīng)用程序,希望對(duì)大家有所幫助2024-03-03Docker配置文件docker-compose.yml使用指南
本文主要介紹了Docker配置文件docker-compose.yml使用指南,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07Docker 數(shù)據(jù)卷,數(shù)據(jù)卷容器詳細(xì)介紹
這篇文章主要介紹了 Docker 數(shù)據(jù)卷,數(shù)據(jù)卷容器詳細(xì)介紹的相關(guān)資料,這里對(duì)Docker 數(shù)據(jù)卷,數(shù)據(jù)卷容器的感念及相關(guān)操作進(jìn)行了介紹,需要的朋友可以參考下2016-11-11詳解使用阿里云鏡像倉(cāng)庫(kù)構(gòu)建國(guó)外Docker鏡像
這篇文章主要介紹了詳解使用阿里云鏡像倉(cāng)庫(kù)構(gòu)建國(guó)外Docker鏡像,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11docker安裝并運(yùn)行rabbitmq的實(shí)例代碼
在本篇文章里小編給大家整理了關(guān)于docker安裝并運(yùn)行rabbitmq的實(shí)例代碼以及相關(guān)知識(shí)點(diǎn),需要的朋友們學(xué)習(xí)下。2019-10-10