搭建Elasticsearch集群

搭建步骤(以三个节点为例)

  • 拷⻉elasticsearch-7.2.0安装包3份,分别命名elasticsearch-7.2.0-a,
    elasticsearch-7.2.0-b, elasticsearch-7.2.0-c。
    分别修改elasticsearch.yml⽂件。 分别启动a ,b ,c 三个节点。
    打开浏览器输⼊:http://localhost:9200/_cat/health?v ,如果返回的node.total是3,代表集
    群搭建成功

配置elasticsearch.yml

[work@localhost elasticsearch-7.2.0]$ cd config/
[work@localhost config]$ vim elasticsearch.yml 

以下是三个节点配置文件 注释部分未粘贴

**节点1**
#集群名称
cluster.name: my-application
#节点名称
node.name: node-1 #是不是有资格主节点
node.master: true
#是否存储数据
node.data: true
#最大集群节点数
node.max_local_storage_nodes: 3
#网关地址
network.host: 0.0.0.0
#端口
http.port: 9200
#内部节点之间沟通端⼝
transport.tcp.port: 9300
#es7.x 之后新增的配置,写候选主节点的设备地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["192.168.80.130:9300","192.168.80.130:9400","192.168.80.130:9500"]
#es7.x 之后新增的配置,初始化⼀个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["node-1", "node-2","node-3"] #数据和存储路径
path.data: /home/work/data
path.logs: /home/work/logs

节点2
#集群名称
cluster.name: my-application
#节点名称
node.name: node-2 #是不是有资格主节点
node.master: true
#是否存储数据
node.data: true
#最大集群节点数
node.max_local_storage_nodes: 3
#网关地址
network.host: 0.0.0.0
#端口
http.port: 9201
#内部节点之间沟通端⼝
transport.tcp.port: 9400
#es7.x 之后新增的配置,写候选主节点的设备地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["192.168.80.130:9300","192.168.80.130:9400","192.168.80.130:9500"]
#es7.x 之后新增的配置,初始化⼀个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["node-1", "node-2","node-3"] #数据和存储路径
path.data: /home/work/data
path.logs: /home/work/logs

节点3
#集群名称
cluster.name: my-application
#节点名称
node.name: node-3 #是不是有资格主节点
node.master: true
#是否存储数据
node.data: true
#最大集群节点数
node.max_local_storage_nodes: 3
#网关地址
network.host: 0.0.0.0
#端口
http.port: 9202
#内部节点之间沟通端⼝
transport.tcp.port: 9300
#es7.x 之后新增的配置,写候选主节点的设备地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["192.168.80.130:9300","192.168.80.130:9400","192.168.80.130:9500"]
#es7.x 之后新增的配置,初始化⼀个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["node-1", "node-2","node-3"] #数据和存储路径
path.data: /home/work/data
path.logs: /home/work/logs

Kibana

进入kibana目录(安装步骤请自行查找非常简单)
编辑kibana.yml

[work@localhost ~]$ cd kibana-7.2.0-linux-x86_64
[work@localhost kibana-7.2.0-linux-x86_64]$ cd c
-bash: cd: c: 没有那个文件或目录
[work@localhost kibana-7.2.0-linux-x86_64]$ cd config/
[work@localhost config]$ ls
kibana.yml
[work@localhost config]$ vim kibana.yml 

取消默认注释修改为

elasticsearch.hosts: ["http://localhost:9200","http://localhost:9201","http://localhost:9202"]

保存退出。

启动kibana

[work@localhost kibana-7.2.0-linux-x86_64]$ cd bin/
[work@localhost bin]$ sh kibana

启动成功提示

  log   [07:37:32.955] [info][status][plugin:kibana@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:32.963] [info][status][plugin:elasticsearch@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:32.965] [info][status][plugin:xpack_main@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:32.974] [info][status][plugin:graph@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:32.985] [info][status][plugin:monitoring@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:32.987] [info][status][plugin:spaces@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:32.995] [warning][security] Generating a random key for xpack.security.encryptionKey. To prevent sessions from being invalidated on restart, please set xpack.security.encryptionKey in kibana.yml
  log   [07:37:32.997] [warning][security] Session cookies will be transmitted over insecure connections. This is not recommended.
  log   [07:37:33.019] [info][status][plugin:security@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.020] [info][status][plugin:searchprofiler@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.026] [info][status][plugin:ml@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.061] [info][status][plugin:tilemap@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.063] [info][status][plugin:watcher@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.072] [info][status][plugin:grokdebugger@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.077] [info][status][plugin:dashboard_mode@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.081] [info][status][plugin:logstash@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.088] [info][status][plugin:beats_management@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.103] [info][status][plugin:apm_oss@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.114] [info][status][plugin:apm@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.115] [info][status][plugin:code@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.118] [info][status][plugin:tile_map@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.120] [info][status][plugin:task_manager@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.123] [info][status][plugin:maps@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.129] [info][status][plugin:interpreter@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.139] [info][status][plugin:canvas@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.145] [info][status][plugin:license_management@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.147] [info][status][plugin:cloud@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.148] [info][status][plugin:index_management@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.160] [info][status][plugin:console@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.162] [info][status][plugin:console_extensions@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.169] [info][status][plugin:notifications@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.171] [info][status][plugin:index_lifecycle_management@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.182] [info][status][plugin:metrics@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.209] [info][status][plugin:infra@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.211] [info][status][plugin:rollup@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.219] [info][siem] Plugin initializing
  log   [07:37:33.239] [info][siem] Plugin done initializing
  log   [07:37:33.240] [info][status][plugin:siem@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.245] [info][status][plugin:remote_clusters@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.249] [info][status][plugin:cross_cluster_replication@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.259] [info][status][plugin:translations@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.269] [info][status][plugin:upgrade_assistant@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.281] [info][status][plugin:uptime@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.285] [info][status][plugin:oss_telemetry@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.287] [warning][encrypted_saved_objects] Generating a random key for xpack.encrypted_saved_objects.encryptionKey. To be able to decrypt encrypted saved objects attributes after restart, please set xpack.encrypted_saved_objects.encryptionKey in kibana.yml
  log   [07:37:33.287] [info][status][plugin:encrypted_saved_objects@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.296] [info][status][plugin:snapshot_restore@7.2.0] Status changed from uninitialized to yellow - Waiting for Elasticsearch
  log   [07:37:33.298] [info][status][plugin:data@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.312] [info][status][plugin:ui_metric@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.402] [info][status][plugin:timelion@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:33.671] [info][status][plugin:elasticsearch@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.706] [info][license][xpack] Imported license information from Elasticsearch for the [data] cluster: mode: basic | status: active
  log   [07:37:33.713] [info][status][plugin:xpack_main@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.713] [info][status][plugin:graph@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.715] [info][status][plugin:searchprofiler@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.715] [info][status][plugin:ml@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.716] [info][status][plugin:tilemap@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.717] [info][status][plugin:watcher@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.717] [info][status][plugin:grokdebugger@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.717] [info][status][plugin:logstash@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.718] [info][status][plugin:beats_management@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.719] [info][status][plugin:index_management@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.719] [info][status][plugin:index_lifecycle_management@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.720] [info][status][plugin:rollup@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.720] [info][status][plugin:remote_clusters@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.720] [info][status][plugin:cross_cluster_replication@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.721] [info][status][plugin:snapshot_restore@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:33.721] [info][kibana-monitoring][monitoring] Starting monitoring stats collection
  log   [07:37:33.763] [info][status][plugin:maps@7.2.0] Status changed from yellow to green - Ready
  log   [07:37:34.305] [warning][browser-driver][reporting] Enabling the Chromium sandbox provides an additional layer of protection.
  log   [07:37:34.343] [warning][reporting] Generating a random key for xpack.reporting.encryptionKey. To prevent pending reports from failing on restart, please set xpack.reporting.encryptionKey in kibana.yml
  log   [07:37:34.350] [info][status][plugin:reporting@7.2.0] Status changed from uninitialized to green - Ready
  log   [07:37:34.547] [info][listening] Server running at http://0.0.0.0:5602
  log   [07:37:34.557] [info][status][plugin:spaces@7.2.0] Status changed from yellow to green - Ready

访问 ip:5602 进入kibana
在这里插入图片描述

点击
在这里插入图片描述
进入后
在这里插入图片描述
在这里插入图片描述
证明集群搭建成功。

设置索引分片,保证每个服务上都要有一个主分片

创建索引(指定分⽚数量)

"settings": { "number_of_shards": 3, "number_of_replicas": 1 },

在这里插入图片描述

手动移动分片

在这里插入图片描述

修改副分片数量

在这里插入图片描述

查看集群健康状态

status :集群的状态,red红表示集群不可⽤,有故障。yellow⻩表示集群不可靠但可⽤,
⼀般单节点时就是此状态。green正常状态,表示集群⼀切正常。
node.total :节点数,这⾥是3,表示该集群有三个节点。
node.data :数据节点数,存储数据的节点数,这⾥是3。
shards :表示我们把数据分成多少块存储。
pri :主分⽚数,primary shards
active_shards_percent :激活的分⽚百分⽐,这⾥可以理解为加载的数据分⽚数,只有加
载所有的分⽚数,集群才算正常启动,在启动的过程中,如果我们不断刷新这个⻚⾯,我们会发
现这个百分⽐会不断加⼤。

查看集群索引数

http://ip:9200/_cat/indices?v
在这里插入图片描述

health : 索引健康,green为正常,yellow表示索引不可靠(单节点),red索引不可⽤。
与集群健康状态⼀致。
status : 状态表明索引是否打开,只索引是可以关闭的。
index : 索引的名称
uuid : 索引内部分配的名称,索引的唯⼀表示
pri : 集群的主分⽚数量
docs.count : 这⾥统计了⽂档的数量。
docs.deleted : 这⾥统计了被删除⽂档的数量。
store.size : 索引的存储的总容量
pri.store.size : 主分别的容量

查看磁盘分配情况

http://ip:9200/_cat/allocation?v
在这里插入图片描述

shards : 该节点的分⽚数量
disk.indices : 该节点中所有索引在该磁盘所点的空间。
disk.used : 该节点已经使⽤的磁盘容量
disk.avail : 该节点可以使⽤的磁盘容量
disk.total : 该节点的磁盘容量

查看集群的节点信息

http://ip:9200/_cat/nodes?v

在这里插入图片描述
ip : ip地址
heap.percent : 堆内存使⽤情况
ram.percent : 运⾏内存使⽤情况
cpu : cpu使⽤情况
master : 是否是主节点

查看集群其他信息

http://ip:9200/_cat
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值