elasticsearch?組件基于單機的多實例集群部署方法
聲明:
本示例主要作為測試用,生產(chǎn)請慎重。
最近公司突發(fā)奇想,想讓我們搞個單機多實例的 es 的集群,看看其性能咋樣。通常來說,es 作為搜索引擎,應(yīng)用場景不乏日志分析、網(wǎng)絡(luò)安全、搜索引擎等,有時也會用作日志數(shù)據(jù)庫使用,畢竟其出色的搜索查詢性能,不是同等量級 關(guān)系型數(shù)據(jù)庫可以比擬的,主要還是因為其 倒排索引 的特殊性,這里不討論 倒排索引 與 B+ Tree 的性能,我們主要看看這種集群怎么組建的。
環(huán)境準(zhǔn)備:
- ubuntu,24核,64G
- docker 20.10.2
因為是 es 集群,我們準(zhǔn)備通過 docker 來創(chuàng)建實例,所以之前你還得先 pull es、kibana 的 image:
docker pull elasticsearch:6.8.23 docker pull kibana:6.8.23
如果你的容器有限,可以直接通過腳本運行 docker run,但是如果容器數(shù)量多還有相關(guān)依賴,建議通過 容器編排 起容器,當(dāng)然數(shù)量更大的情況下,建議通過 k8s 部署。
我們的集群主要包含 3 個 es 節(jié)點,外加一個 kibana 作為觀測,所以通過 docker-compose 作為容器編排,相對合適。
接下來是我們的編排定義: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 # 時間 - /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)段。
然后我們要看看對應(yīng)的其他準(zhǔn)備。
主要看我們的對應(yīng)到主機中的 data 目錄,所以參考 yml 中的相關(guān)映射,注意創(chuàng)建相關(guān)目錄。
這里我們主要看看相關(guān)的 elasticsearch.yaml 和 jvm.options。
elasticsearch.yml
cluster: name: logserver ################# node.name: es-0 # 其他節(jié)點類似,修改 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 # 主機內(nèi)存64G,每個實例分配16G -Xmx16g ################################################################ ## Expert settings ################################################################ ## ...
這兩個文件按照上面內(nèi)容修改。
接下來是 kibana.yml:
... elasticsearch.url: "http://172.xxx.xxx.xxx:9200" # 根據(jù)實際情況,填入自己的主機ip ...
接下來通過 docker-compose 命令就可以起容器了。
docker-compsoe up -d # 后臺運行容器 docker-compose ps # 查看容器運行狀態(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)順利起來了,集群實例就演示到這里,希望對你有用。
到此這篇關(guān)于elasticsearch 組件基于單機的多實例集群的文章就介紹到這了,更多相關(guān)elasticsearch 單機多實例集群內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
一文詳解如何在Ubuntu系統(tǒng)中安裝docker
這篇文章主要為大家詳細(xì)介紹了在Ubuntu操作系統(tǒng)上安裝Docker的步驟,以便我們可以開始使用Docker來構(gòu)建和運行容器化應(yīng)用程序,希望對大家有所幫助2024-03-03Docker配置文件docker-compose.yml使用指南
本文主要介紹了Docker配置文件docker-compose.yml使用指南,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07Docker 數(shù)據(jù)卷,數(shù)據(jù)卷容器詳細(xì)介紹
這篇文章主要介紹了 Docker 數(shù)據(jù)卷,數(shù)據(jù)卷容器詳細(xì)介紹的相關(guān)資料,這里對Docker 數(shù)據(jù)卷,數(shù)據(jù)卷容器的感念及相關(guān)操作進(jìn)行了介紹,需要的朋友可以參考下2016-11-11