确保Debian系统已更新至最新版本,并安装wget、vim等基础工具(可选但推荐):
sudo apt update && sudo apt upgrade -y
sudo apt install wget vim -y
通过Debian官方仓库安装Filebeat(推荐,便于后续更新):
sudo apt install filebeat -y
安装完成后,Filebeat默认配置文件位于/etc/filebeat/filebeat.yml,二进制文件位于/usr/share/filebeat。
同样通过Debian官方仓库安装Logstash:
sudo apt install logstash -y
安装后,Logstash主配置目录为/etc/logstash,默认日志文件位于/var/log/logstash。
编辑Filebeat配置文件/etc/filebeat/filebeat.yml,完成以下关键配置:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/syslog # 系统日志
- /var/log/auth.log # 认证日志
5044):output.logstash:
hosts: ["localhost:5044"] # 若Logstash在远程服务器,替换为"remote_ip:5044"
output.logstash:
hosts: ["localhost:5044", "remote_ip:5044"]
workers: 2 # 发送线程数
loadbalance: true # 负载均衡
在Logstash中创建自定义配置文件(如/etc/logstash/conf.d/filebeat.conf),定义输入→过滤→输出管道:
5044):input {
beats {
port => 5044
}
}
filter {
if [fileset][module] == "system" {
grok {
match => { "message" => "%{SYSLOGTIMESTAMP:timestamp} %{SYSLOGHOST:hostname} %{DATA:program}(?:\[%{POSINT:pid}\])?: %{GREEDYDATA:message}" }
}
date {
match => [ "timestamp", "MMM dd HH:mm:ss", "ISO8601" ]
}
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "filebeat-%{+YYYY.MM.dd}" # 按日期生成索引
}
stdout { codec => rubydebug } # 控制台输出(调试用,生产环境可注释)
}
依次启动Filebeat和Logstash,并设置为开机自启:
# 启动Logstash(需先启动,否则Filebeat无法连接)
sudo systemctl start logstash
sudo systemctl enable logstash
# 启动Filebeat
sudo systemctl start filebeat
sudo systemctl enable filebeat
sudo systemctl status filebeat
sudo systemctl status logstash
sudo journalctl -u filebeat -f
sudo tail -f /var/log/logstash/logstash-plain.log
curl -X GET "localhost:9200/_cat/indices?v"
应能看到类似filebeat-2025.10.24的索引(日期随当前时间变化)。ping、telnet),确认端口5044是否开放(sudo ufw allow 5044)。sudo filebeat test config -e
测试Logstash配置:sudo logstash -f /etc/logstash/conf.d/filebeat.conf --config.test_and_exit
通过以上步骤,即可完成Debian系统下Filebeat与Logstash的联调,实现日志的收集、处理与存储。