在CentOS上配置Filebeat与Logstash集成,可以按照以下步骤进行:
首先,确保你的CentOS系统已经更新到最新状态:
sudo yum update -y
然后,安装Elastic的YUM仓库:
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
echo "[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
autorefresh=1
type=rpm-md" | sudo tee -a /etc/yum.repos.d/elasticsearch.repo
接下来,安装Filebeat:
sudo yum install filebeat -y
编辑Filebeat的配置文件 /etc/filebeat/filebeat.yml:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.logstash:
hosts: ["localhost:5044"]
这个配置文件指定了Filebeat从 /var/log/*.log 目录读取日志,并将日志发送到本地的Logstash实例(默认端口为5044)。
如果你还没有安装Logstash,可以使用以下命令安装:
sudo yum install logstash -y
编辑Logstash的配置文件 /etc/logstash/conf.d/filebeat.conf:
input {
beats {
port => 5044
}
}
filter {
# 根据需要添加过滤器
# 例如,解析JSON格式的日志:
# json {
# source => "message"
# }
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "filebeat-%{+YYYY.MM.dd}"
}
}
启动Logstash:
sudo systemctl start logstash
sudo systemctl enable logstash
启动Filebeat并设置开机自启:
sudo systemctl start filebeat
sudo systemctl enable filebeat
确保Logstash正在运行并且可以接收来自Filebeat的数据。你可以使用以下命令查看Logstash的日志:
sudo tail -f /var/log/logstash/logstash-plain.log
同时,检查Elasticsearch中的索引是否在增长:
curl -X GET "localhost:9200/_cat/indices?v&pretty"
你应该能看到名为 filebeat-* 的索引。
通过以上步骤,你就成功地在CentOS上配置了Filebeat与Logstash的集成。根据实际需求,你可能需要调整配置文件中的路径、端口和其他参数。