介绍 本教程客户端API关闭HTTPS认证,但传输使用HTTPS。(为了接入日志监控 )
主要介绍了ES集群的搭建。ELK单机使用可参考:https://songxwn.com/elk/  
Elasticsearch版本:8.x
系统版本:Rocky Linux 8.7 (关闭SE Linux和防火墙)
配置要求:建议4核8G以上,存储空间按照存储的文档大小规划。
Elasticsearch 集群建议至少要有三个节点,两个以上的master节点。
本教程也同样适用于也适用于其他RHEL8-9版本衍生版系统:如Centos stream、AlmaLinux等。
概念 (1)集群(Cluster): ES可以作为一个独立的单个搜索服务器。不过,为了处理大型数据集,实现容错和高可用性,ES可以运行在许多互相合作的服务器上。这些服务器的集合称为集群。
(2)节点(Node): 形成集群的每个服务器称为节点。
(3)索引(index): 在 ES 中, 索引是一组文档的集合。
(4)分片(shard)
当有大量的文档时,由于内存的限制、磁盘处理能力不足、无法足够快的响应客户端的请求等,一个节点可能不够。这种情况下,数据可以分为较小的分片。每个分片放到不同的服务器上。
当你查询的索引分布在多个分片上时,ES会把查询发送给每个相关的分片,并将结果组合在一起,而应用程序并不知道分片的存在。即:这个过程对用户来说是透明的。
(5)副本(Replia)
为提高查询吞吐量或实现高可用性,可以使用分片副本。
副本是一个分片的精确复制,每个分片可以有零个或多个副本。ES中可以有许多相同的分片,其中之一被选择更改索引操作,这种特殊的分片称为主分片。
当主分片丢失时,如:该分片所在的数据不可用时,集群将副本提升为新的主分片。
区别 分片与副本的区别在于:
当你分片设置为5,数据量为30G时,es会自动帮我们把数据均衡地分配到5个分片上,即每个分片大概有6G数据,当你查询数据时,ES会把查询发送给每个相关的分片,并将结果组合在一起。
而副本,就是对分布在5个分片的数据进行复制。因为分片是把数据进行分割而已,数据依然只有一份,这样的目的是保障查询的高效性,副本则是多复制几份分片的数据,这样的目的是保障数据的高可靠性,防止数据丢失。
注意
索引建立后,分片个数是不可以更改的。
安装 系统参数调整 修改虚拟内存大小 1 2 3 4 5 6 7 8 9 cat  >> /etc/sysctl.conf <<EOF vm.max_map_count=655360 fs.file-max=655360 EOF 
修改所有用户限制 1 2 3 4 5 6 7 8 9 cat  >> /etc/security/limits.conf <<EOF * soft nofile 924000 * hard nofile 924000 * soft nproc 4096 * hard nproc 4096 EOF 
正式安装 yum源配置 1 2 3 4 5 6 7 8 9 10 11 12 vim /etc/yum.repos.d/elasticsearch.reponame =Elasticsearch repository for  8.x packagesbaseurl =https://mirrors.tuna.tsinghua.edu.cn/elasticstack/8.x/yumgpgcheck =0enabled =1autorefresh =1type =rpm-md
集群规划,集群名字为ES-CU1 
节点名字 
IP 
角色规划 
 
 
ES-01 
100.64.128.101 
master、data 
 
ES-02 
100.64.128.102 
master、data 
 
ES-03 
100.64.128.103 
master、data 
 
1 2 3 4 5 6 7 8 9 vim /etc/hosts100.64.128.101  ES-01 100.64.128.102  ES-02 100.64.128.103  ES-03 
安装 1 2 3 4 dnf install  elasticsearch logstash kibana -y
关闭HTTPS认证(每台节点配置) 1 2 3 4 5 6 7 8 9 10 vim  /etc/elasticsearch/elasticsearch.yml xpack.security.http.ssl: enabled:  false 
 xpack.security.http.ssl 改为false,并注释证书路径。
 
配置集群(每台节点配置,但node.name和IP需要修改) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 ##ES-01 配置#################################################-01 100.64 .128 .101 100.64 .128 .101 100.64 .128 .101 "100.64.128.101:9300" ,"100.64.128.102:9300" ,"100.64.128.103:9300" ]"ES-01" ]-02 配置#################################################-02 100.64 .128 .102 100.64 .128 .102 100.64 .128 .102 "100.64.128.101:9300" ,"100.64.128.102:9300" ,"100.64.128.103:9300" ]"ES-01" ]-03 配置#################################################-03 100.64 .128 .103 100.64 .128 .103 100.64 .128 .103 "100.64.128.101:9300" ,"100.64.128.102:9300" ,"100.64.128.103:9300" ]"ES-01" ]9200  和 9300 端口。
cluster.name为集群名字,集群内所有节点必须统一。 
node.name为节点名字,每个节点不能一样。 
http.host、transport.host、network.host配置为主机的IP地址。 
node.roles: [master,data],为配置节点角色,目前为主节点和存储节点。说明文档  
discovery.seed_hosts 配置发现其他节点,一般写所有节点的地址,后面加上传输节点的端口号。默认为9300. 
cluster.initial_master_nodes节点初始化默认主节点选定。 
 
启动ES-01,验证并配置其他节点同步证书。 ES-01 (第一个启动,其他节点先不要启动。使用ES-01自动生成的证书) 1 2 3 4 5 6 7 8 9 10 11 12 systemctl enable elasticsearch.service // 100.64 .128.101 :9200 
注意:安装之后其他节点不能启动,要等配置好集群配置和证书后启动。
如果启动过了,建议按照教程最后的教程清理按照。
ES-02 SCP教程 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 scp -r ES-01 :/etc/ elasticsearch/certs/  /etc/ elasticsearch/01 :/etc/ elasticsearch/elasticsearch.keystore / etc/elasticsearch/ // 100.64 .128.102 :9200 
ES-03 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 scp -r ES-01 :/etc/ elasticsearch/certs/  /etc/ elasticsearch/01 :/etc/ elasticsearch/elasticsearch.keystore / etc/elasticsearch/ // 100.64 .128.103 :9200 
默认文件目录说明 配置文件目录 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 tree -L 2  /etc/ elasticsearch//etc/ elasticsearch/
程序目录 1 2 3 4 5 6 7 8 9 10 11 12 13 14 tree -L 1  /usr/ share/elasticsearch/usr/ share/elasticsearch
日志目录 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 tree -L 1  /var/log /elasticsearch/log /elasticsearch/log log log log .00 
数据存储目录 1 2 3 4 5 6 7 8 9 10 tree -L 1  /var/ lib/elasticsearch/ /var/ lib/elasticsearch/ 
重置管理员密码和验证集群数量 重置密码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 usr/share/ elasticsearch/bin/ elasticsearch-reset-password -u elastic/usr/ share/elasticsearch/ bin/elasticsearch-reset-password -u kibana_system// 100.64 .128.101 :9200 for  user 'elastic' :"name"  : "ES-01" ,"cluster_name"  : "ES-CU1" ,"cluster_uuid"  : "UNCqtG1YTeuHSNgDHOHkIw" ,"version"  : {"number"  : "8.7.0" ,"build_flavor"  : "default" ,"build_type"  : "rpm" ,"build_hash"  : "09520b59b6bc1057340b55750186466ea715e30e" ,"build_date"  : "2023-03-27T16:31:09.816451435Z" ,"build_snapshot"  : false,"lucene_version"  : "9.5.0" ,"minimum_wire_compatibility_version"  : "7.17.0" ,"minimum_index_compatibility_version"  : "7.0.0" "tagline"  : "You Know, for Search" // 100.64 .128.101 :9200 /_cat/ nodes?vfor  user 'elastic' :100.64 .128.102             5           92    1     0.01     0.03      0.00  dm        -      ES-02 100.64 .128.101            18           93    5     0.20     0.35      0.17  dm        *      ES-01 100.64 .128.103            17           89    1     0.02     0.05      0.02  dm        -      ES-03 
配置Kibana接入集群 默认配置 默认为 5601 端口,默认绑定为127.0.0.1 地址。使用HTTP协议。
可以修改kibana.yml 文件修改绑定地址,或者使用Nginx反向代理。
修改语言和监听IP 1 2 3 4 5 6 7 8 9 10 11 12 vim  /etc/kibana/kibana.yml   i18n.locale:  "zh-CN" server.host:  "0.0.0.0" systemctl  enable  --now  kibana.service 
基本认证配置 1 2 3 4 5 6 7 8 9 10 11 12 vim  /etc/kibana/kibana.yml  elasticsearch.hosts:  ["http://100.64.128.101:9200" ,"http://100.64.128.102:9200" ,"http://100.64.128.103:9200" ]elasticsearch.username:  "kibana_system" elasticsearch.password:  "EVecudsC4vvlcR6QT4mR" 
修改文件,配置ES所有访问地址,配置系统默认账号kibana_system的密码,填入配置文件。(必须为此账号)
使用systemctl restart kibana.service重启服务,使配置生效。
在Kibana上查看和监测ES集群 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 vim /etc/ kibana/kibana.yml /usr/ share/elasticsearch/ bin/elasticsearch-reset-password -u beats_system/etc/m etricbeat/metricbeat.yml "http://100.64.128.101:9200" ,"http://100.64.128.102:9200" ,"http://100.64.128.103:9200" ]"beats_system" "[emailprotected] " 
访问 http://100.64.128.101:5601/app/monitoring路径
即可查看监控,使用elastic账号登录。
彻底清理卸载ES 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 systemctl stop elasticsearch/var/ lib/elasticsearch/etc/ elasticsearch/usr/ share/elasticsearch/var/ log/elasticsearch
相关教程 单机部署ELK,接收syslogr日志 
接入ES做日志告警系统 
配置接收SNMP-Trap日志 
参考 https://qiita.com/mingchun_zhao/items/b229addd5697ad571d94  
https://www.zsjweblog.com/2022/03/09/elasticsearch8-1-0%E9%9B%86%E7%BE%A4%E6%90%AD%E5%BB%BA/  
https://blog.51cto.com/feirenraoyuan/5716392  
http://dbaselife.com/doc/831/