2. 单主机 Elasticsearch 双节点或多节点集群环境部署

我已经买了一年的腾讯云轻量级服务器,并且安装好了ES,也做了一些系统配置,比如 修改vm.max_map_count、修改文件描述符数量
同时,也用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/

经验总结扩展阅读