网站Logo 欢迎来到我的博客

麒麟系统部署EFK架构

zhang
119
2025-08-11

ElasticSearch环境准备

主机名 IP 服务 配置
kylin-elk01 10.0.0.91 ElasticSearch+kibana 2C4G
kylin-elk02 10.0.0.92 ElasticSearch+Filebeat 2C4G
kylin-elk03 10.0.0.93 ElasticSearch 2C4G

下载ElasticSearch软件包

#下载地址
wget  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.29-x86_64.rpm
#安装软件包
rpm -ivh elasticsearch-7.17.29-x86_64.rpm 

ElasticSearch配置文件

#修改配置文件
[root@kylin-elk01 ~]# vim /etc/elasticsearch/elasticsearch.yml 
#查看修改信息
[root@kylin-elk01 ~]# egrep -nv "^#|^$"  /etc/elasticsearch/elasticsearch.yml 
18:cluster.name: zhangmx-linux99-singe
33:path.data: /var/lib/elasticsearch
37:path.logs: /var/log/elasticsearch
57:network.host: 0.0.0.0
62:http.port: 9200
65:discovery.type: single-node

同步EFK集群配置文件

[root@kylin-elk01 ~]# scp /etc/elasticsearch/elasticsearch.yml root@10.0.0.92:/etc/elasticsearch/
[root@kylin-elk01 ~]# scp /etc/elasticsearch/elasticsearch.yml root@10.0.0.93:/etc/elasticsearch/

同步启动ElasticSearch服务

[root@kylin-elk01 ~]# systemctl enable --now elasticsearch
[root@kylin-elk01 ~]# ss -lntup |  egrep "92|300"
tcp     LISTEN   0        128                    *:9300                *:*       users:(("java",pid=55773,fd=294))                                            
tcp     LISTEN   0        128                    *:9200                *:*       users:(("java",pid=55773,fd=321))      

验证集群状态

[root@kylin-elk01 ~]# curl 10.0.0.93:9200/_cat/nodes

kibana环境部署

下载kibana软件包

##下载地址
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.17.29-x86_64.rpm
#安装软件包
rpm -ivh rpm -ivh filebeat-7.17.29-x86_64.rpm

修改配置文件

[root@kylin-elk01 ~]# egrep -vn "^#|^$"  /etc/kibana/kibana.yml 
2:server.port: 5601
7:server.host: "0.0.0.0"
32:elasticsearch.hosts: ["http://10.0.0.91:9200","http://10.0.0.92:9200","http://10.0.0.93:9200"]
115:i18n.locale: "zh-CN"

启动kibana服务

[root@kylin-elk01 ~]# systemctl status kibana.service 
[root@kylin-elk01 ~]# ss -lntup | grep 5601
tcp     LISTEN   0        128              0.0.0.0:5601          0.0.0.0:*       users:(("node",pid=56464,fd=51)) 

网页访问测试

10.0.0.91:5601

Filebeat部署

下载Filebeat软件包

#下载软件
wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.17.29-x86_64.rpm
#安装软件包
rpm -ivh elasticsearch-7.17.29-x86_64.rpm

修改Filebeat配置文件

#创建配置文件目录(默认没有)
[root@kylin-elk02 ~]# mkdir /etc/filebeat/config
#配置文件
[root@kylin-elk02 ~]#  vim /etc/filebeat/config/01-tcp-to-es.yaml
#查看配置文件修改信息
filebeat.inputs:
- type: tcp
  host: "0.0.0.0:9000"

#output.console:
#  pretty: true

# 将数据写入到ES集群
output.elasticsearch:
  # 指定ES集群地址
  hosts: ["http://10.0.0.91:9200","http://10.0.0.92:9200","http://10.0.0.93:9200"]
  # 指定ES的索引名称
  index: zhangmx-filebeat-tcp-haha

# 禁用索引的生命周期,否则自定义索引名称无效
setup.ilm.enabled: false
# 定义索引模板
setup.template.name: "zhangmx-filebeat-tcp"
# 定义索引模板的匹配模式
setup.template.pattern: "zhangmx-filebeat-tcp*"
# 如果索引模板已经存在是否覆盖
setup.template.overwrite: false
# 配置索引模板
setup.template.settings:
  # 指定分片数量
  index.number_of_shards: 3
  # 指定副本数量
  index.number_of_replicas: 0

启动Filebeat程序

filebeat -e -c /etc/filebeat/config/01-tcp-to-es.yaml 

发送测试数据

[root@kylin-elk03 ~]#  echo www.oldboyedu.com | nc 10.0.0.92 9000
[root@kylin-elk03 ~]#  echo zhangmianxin | nc 10.0.0.92 9000