2. 單主機 Elasticsearch 雙節點或多節點集群環境部署

我已經買了一年的騰訊云輕量級服務器,并且安裝好了ES,也做了一些系統配置,比如 修改vm.max_map_count、修改文件描述符數量
【2. 單主機 Elasticsearch 雙節點或多節點集群環境部署】同時,也用ES安裝目錄下的 bin/elasticsearch 腳本嘗試了第一次啟動 ES,并且用 https://localhost:9200 來訪問它 。
本文,我打算在我的騰訊云服務器上搭一個雙節點的環境,并且用上 kibana 來管理 。
網上給出了兩種方案:
  1. 把 elasticsearch.tar.gz 解壓多次到不同的文件夾,每個文件夾作為一個節點,然后分別修改每個文件夾中的 elasticsearch.yml,再分別啟動 。比如 Elasticsearch 在本地單機多節點部署集群
  2. 把 elasticsearch.tar.gz 解壓一次,然后準備多個YAML配置文件 , 然后啟動時,每個節點用上不同的配置文件 。比如 配置Elasticsearch
我傾向于第2種 , 可以把集群中的各個節點的配置文件放到一個文件夾下,方便查看 。
1. 查看可執行文件 elasticsearch使用命令 more bin/elasticsearch 查看啟動腳本 , 如下圖所示:
2. 單主機 Elasticsearch 雙節點或多節點集群環境部署

文章插圖
從啟動腳本 elasticsearch 的頭部注釋可以看出 , 可以使用
ES_PATH_CONF=/path/to/custom/config ./bin/elasticsearch這樣的命令來指定啟動節點時,使用不同的配置文件!
有了思路之后 , 接下來就開始實踐 。
2. 準備兩個配置文件配置項節點1節點2節點名稱node1node2配置文件目錄/opt/config/es-cluster/node1//opt/config/es-cluster/node2/data目錄/var/lib/es-cluster/node1/var/lib/es-cluster/node2log目錄/var/log/es-cluster/node1/var/log/es-cluster/node2執行以下命令創建目標文件夾和文件:
[lighthouse@centos ~]$ cd /opt[lighthouse@centos opt]$ sudo mkdir config[lighthouse@centos opt]$ cd config[lighthouse@centos config]$ sudo mkdir es-cluster[lighthouse@centos config]$ sudo chown elastic:elastic es-cluster/[lighthouse@centos config]$ ls -altotal 12drwxr-xr-x   3  root     root     4096  0ct  9  17:59  .drwxr-xr-x.  6  root     root     4096  0ct  9  17:59  ..drwxr-xr-x.  2  elastic  elastic  4096  0ct  9  17:59  es-cluster[lighthouse@centos config]$ su elasticPassword:[elastic@centos config]$ cd es-cluster[elastic@centos es-cluster]$ mkdir node1[elastic@centos es-cluster]$ mkdir node2[elastic@centos es-cluster]$ touch node1/elasticsearch.yml[elastic@centos es-cluster]$ touch node2/elasticsearch.yml[elastic@centos es-cluster]$ exit[lighthouse@centos es-cluster]$ cd /var/lib[lighthouse@centos lib]$ sudo mkdir es-cluster[lighthouse@centos lib]$ cd es-cluster[lighthouse@centos es-cluster]$ sudo mkdir node1[lighthouse@centos es-cluster]$ sudo mkdir node2[lighthouse@centos es-cluster]$ cd ..[lighthouse@centos lib]$ sudo chown -R elastic:elastic es-cluster/[lighthouse@centos lib]$ cd /var/log[lighthouse@centos log]$ sudo mkdir es-cluster[lighthouse@centos log]$ cd es-cluster[lighthouse@centos es-cluster]$ sudo mkdir node1[lighthouse@centos es-cluster]$ sudo mkdir node2[lighthouse@centos es-cluster]$ cd ..[lighthouse@centos log]$ sudo chown -R elastic:elastic es-cluster/修改 node1/elasticsearch.yml 內容如下:
cluster.name: es-clusternode.name: node1node.roles: ["master", "data", "ingest"]network.host: 10.0.4.10http.port: 9200transport.port: 9300path:  data: /var/lib/es-cluster/node1  logs: /var/log/es-cluster/node1discovery.seed_hosts:  - 10.0.4.10:9300  - 10.0.4.10:9301cluster.initial_master_nodes:  - node1  - node2xpack.security.enabled: falsexpack.security.transport.ssl.enabled: false修改 node2/elasticsearch.yml 內容如下:
cluster.name: es-clusternode.name: node2node.roles: ["master", "data", "ingest"]network.host: 10.0.4.10http.port: 9201transport.port: 9301path:  data: /var/lib/es-cluster/node2  logs: /var/log/es-cluster/node2discovery.seed_hosts:  - 10.0.4.10:9300  - 10.0.4.10:9301cluster.initial_master_nodes:  - node1  - node2xpack.security.enabled: falsexpack.security.transport.ssl.enabled: false

推薦閱讀