在CentOS上配置Filebeat与Logstash配合使用步骤如下:
安装组件:
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo tee /etc/yum.repos.d/elasticsearch.repo <<EOF
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
EOF
sudo yum install logstash kibana
sudo systemctl start elasticsearch && sudo systemctl enable elasticsearch
sudo systemctl start kibana && sudo systemctl enable kibana
sudo yum install filebeat
配置Filebeat:
编辑 /etc/filebeat/filebeat.yml,设置输出到Logstash:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log # 日志路径,可自定义
output.logstash:
hosts: ["localhost:5044"] # Logstash地址及端口
配置Logstash:
创建 /etc/logstash/conf.d/filebeat.conf,定义输入、过滤和输出:
input {
beats {
port => 5044
}
}
filter {
# 示例:解析JSON格式日志(按需添加)
# if [type] == "json" {
# json { source => "message" }
# }
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "filebeat-%{+YYYY.MM.dd}"
}
}
启动服务:
sudo systemctl start filebeat && sudo systemctl enable filebeat
sudo systemctl start logstash && sudo systemctl enable logstash
验证配置:
sudo systemctl status filebeat
sudo systemctl status logstash
tail -f /var/log/logstash/logstash-plain.log
说明:
localhost 替换为对应服务器IP,并确保防火墙放行端口(5044、9200等)。