Elasticsearch集群rpm包部署

规划主机

主机IP

主机名

系统

172.17.10.101

elk101.guoguod.cn

CentOS7

172.17.10.102

elk102.guoguod.cn

CentOS7

172.17.10.103

elk103.guoguod.cn

CentOS7

1.下载

https://www.elastic.co/cn/downloads
#下载地址
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.5-x86_64.rpm
#下载rpm包版本
  • 1.
  • 2.
  • 3.
  • 4.

2.安装

以下操作三台主机都需要执行

[root@elk101 data]# rpm -ivh elasticsearch-7.17.5-x86_64.rpm
warning: elasticsearch-7.17.5-x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY
Preparing...                          ################################# [100%]
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Updating / installing...
   1:elasticsearch-0:7.17.5-1         ################################# [100%]
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
 sudo systemctl daemon-reload
 sudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executing
 sudo systemctl start elasticsearch.service
Created elasticsearch keystore in /etc/elasticsearch/elasticsearch.keystore
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

3.启动

修改配置文件

对172.17.10.101主机进行操作

[root@elk101 data]# vim /etc/elasticsearch/elasticsearch.yml

cluster.name: guoguo-es
#集群的名称

network.host: 0.0.0.0
#指定了Elasticsearch绑定的IP地址  0.0.0.0可以从任何IP地址接收连接请求

path.data: /data/elasticsearch/lib/elasticsearch
#存储其索引数据的目录
path.logs: /var/elasticsearch/log/elasticsearch
#日志文件的存储位置

discovery.seed_hosts: ["172.17.10.101","172.17.10.102","172.17.10.103"]
#指定es集群的节点ip

cluster.initial_master_nodes: ["172.17.10.101","172.17.10.102","172.17.10.103"]
#指定参与master选举的节点ip
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.

将配置文件传给另外两台节点

[root@elk101 data]# scp /etc/elasticsearch/elasticsearch.yml root@172.17.10.102:/etc/elasticsearch/
[root@elk101 data]# scp /etc/elasticsearch/elasticsearch.yml root@172.17.10.103:/etc/elasticsearch/
  • 1.
  • 2.

以下操作三台主机都需要执行

创建存放数据目录和日志目录

[root@elk101 data]# mkdir -p /data/elasticsearch/lib/elasticsearch
[root@elk101 data]# mkdir -p /var/elasticsearch/log/elasticsearch
[root@elk101 data]# chown -R elasticsearch:elasticsearch /data/elasticsearch
  • 1.
  • 2.
  • 3.

设置开机自启并启动

[root@elk101 data]#  sudo systemctl daemon-reload
[root@elk101 data]#  sudo systemctl enable elasticsearch.service
Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.
[root@elk101 data]# systemctl start elasticsearch.service
[root@elk101 data]# ss -tnl
State      Recv-Q Send-Q            Local Address:Port              Peer Address:Port
LISTEN     0      128                 [::]:9200                      [::]:*
LISTEN     0      128                 [::]:9300                      [::]:*
#9200端口号是ES集群外部提供客户端http/https访问的端口。
#9300端口号是ES集群内部进行通信和数据传输的端口用的tcp协议。
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.

4.集群验证

验证客户端


[root@elk102 data]# curl 172.17.10.101:9200
{
  "name" : "elk101.guoguod.cn", #这个节点的主机名
  "cluster_name" : "guoguo-es", #集群的名字
  "cluster_uuid" : "95nbR-RaQY-hhe0EPlTdmw", #uuid   如果 uuid 为_na_ 说明出现故障了
  "version" : {
    "number" : "7.17.5",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "8d61b4f7ddf931f219e3745f295ed2bbc50c8e84",
    "build_date" : "2022-06-23T21:57:28.736740635Z",
    "build_snapshot" : false,
    "lucene_version" : "8.11.1",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.

查看集群状态

[root@elk102 data]# curl 172.17.10.102:9200/_cat/nodes

[root@elk101 ~]# curl 172.17.10.102:9200/_cat/nodes
172.17.10.103 8 71 0 0.22 0.09 0.03 cdfhilmrstw - elk103.guoguod.cn
172.17.10.102 8 71 1 0.43 0.13 0.05 cdfhilmrstw * elk102.guoguod.cn   #带*号表明是master
172.17.10.101 6 71 1 0.47 0.15 0.05 cdfhilmrstw - elk101.guoguod.cn
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
[root@elk102 data]# curl 172.17.10.102:9200/_cat/nodes?v

[root@elk101 ~]# curl 172.17.10.102:9200/_cat/nodes?v
ip            heap.percent ram.percent cpu load_1m load_5m load_15m node.role   master name
172.17.10.103            8          71   0    0.17    0.08     0.03 cdfhilmrstw -      elk103.guoguod.cn
172.17.10.102            8          71   0    0.33    0.13     0.05 cdfhilmrstw *      elk102.guoguod.cn
172.17.10.101            6          71   0    0.37    0.14     0.05 cdfhilmrstw -      elk101.guoguod.cn

#ip             节点的ip地址
#heap.percent   堆内存使用的百分比
#ram.percent    内存使用的百分比
#cpu            cpu
#load_1m        1分钟负载
#load_5m        5分钟负载
#load_15m       15分钟负载
#node.role      集群角色 *代表master
#name           此节点的主机名或者名称
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.

es集群启动后会先启动9300端口,内部做选举选出master然后启动9200端口号进行服务

es集群当半数以上存活才能对外提供服务,比如3个节点组成的集群,2台故障es就停止对外提供服务 四个节点组成的集群,3台故障es就停止对外提供服务

因为防止脑裂,集群半数以上通过投票,整个对外提供服务,新加入的节点也能对外提供服务

Elasticsearch集群需要半数以上节点存活才能确保集群健康和正常对外提供服务,以维护数据一致性和避免脑裂问题。

什么是脑裂?

脑裂是指在高可用性系统中,由于通信故障导致集群被错误地划分为多个子集群,每个子集群都认为自己是合法的代表,从而引发数据不一致和服务冲突的状态。