Filebeat 配置测试笔记
测试 Filebeat 配置 :
./filebeat test config -c ./filebeat.yml
启动 Filebeat :
./filebeat -e -c ./filebeat.yml
check is health
# 方法1:查看 filebeat 进程
ps aux | grep filebeat
# 方法2:使用 pgrep 查找进程
pgrep -f filebeat
# 方法3:检查进程树
pstree | grep filebeat
front
# 在 filebeat 目录下运行
./filebeat -e -c filebeat.yml
# 或者指定详细日志级别
./filebeat -e -c filebeat.yml -d "*"
nohup
# 后台运行
nohup ./filebeat -c filebeat.yml > filebeat.log 2>&1 &
# 查看进程
ps aux | grep filebeat
# 查看日志
tail -f filebeat.log
使用 systemd 服务(推荐生产环境)
sudo nano /etc/systemd/system/filebeat.service
[Unit]
Description=Filebeat sends log files to Logstash or directly to Elasticsearch.
Documentation=https://www.elastic.co/products/beats/filebeat
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/path/to/filebeat/filebeat -c /path/to/filebeat/filebeat.yml
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
# 重新加载 systemd
sudo systemctl daemon-reload
# 启动服务
sudo systemctl start filebeat
# 设置开机自启
sudo systemctl enable filebeat
# 查看状态
sudo systemctl status filebeat
# 查看日志
sudo journalctl -u filebeat -f
检查 Filebeat 日志
# 如果是前台运行,直接查看输出
# 如果是后台运行
tail -f filebeat.log
# 如果是 systemd 服务
sudo journalctl -u filebeat -f
常见问题排查
如果 Filebeat 无法启动:
# 检查配置文件权限
ls -la filebeat.yml
# 检查日志目录权限
ls -la /data/hmapp/hm-server/logs/
# 检查端口连通性
telnet localhost 12201
如果没有数据传输:
# 检查日志文件是否存在且有内容
ls -la /data/hmapp/hm-server/logs/*.log
# 检查 Filebeat 是否有权限读取日志文件
sudo -u filebeat cat /data/hmapp/hm-server/logs/your-log-file.log
License:
CC BY 4.0