1. 初始准备
首先更新系统软件包列表并升级已安装的包,确保系统环境最新:
sudo apt update && sudo apt upgrade -y
2. 安装Filebeat
Filebeat在Debian上的安装主要有三种方式,可根据需求选择:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
sudo apt-get update && sudo apt-get install filebeat
sudo apt update && sudo apt install snapd
sudo snap install filebeat --classic
filebeat-8.6.2-amd64.deb):curl -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-8.6.2-amd64.deb
dpkg命令安装:sudo dpkg -i filebeat-8.6.2-amd64.deb
sudo apt-get install -f
3. 配置Filebeat
Filebeat的主配置文件位于/etc/filebeat/filebeat.yml,需根据实际需求修改以下核心参数:
启用log类型的输入,指定要监控的日志文件路径(如系统日志/var/log/*.log或自定义应用日志/var/log/myapp/*.log):
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log # 监控所有系统日志
# - /var/log/myapp/*.log # 可选:监控自定义应用日志
将日志发送到Elasticsearch(本地或远程),需替换hosts中的地址为实际Elasticsearch实例地址:
output.elasticsearch:
hosts: ["localhost:9200"] # 若Elasticsearch在远程服务器,替换为IP或域名
# 可选:配置索引名称(动态生成日期后缀)
index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
加载Filebeat预定义的索引模板,提升日志存储和查询效率:
sudo filebeat setup --index-management -E output.logstash.enabled=false -E 'output.elasticsearch.hosts=["localhost:9200"]'
4. 启动与启用Filebeat服务
sudo systemctl start filebeat
sudo systemctl enable filebeat
5. 验证部署状态
active (running)即为正常):sudo systemctl status filebeat
sudo tail -f /var/log/filebeat/filebeat.log
curl -X GET "localhost:9200/_cat/indices?v" # 查看所有索引,确认是否有filebeat-*索引
注意事项
filebeat.inputs.paths(监控特定目录或文件)、output.elasticsearch.hosts(Elasticsearch地址)等参数;output.elasticsearch.ssl)和认证(配置elasticsearch.username/elasticsearch.password),提升数据传输安全性。