在CentOS系统中,通过Filebeat监控日志的步骤如下:
下载并解压Filebeat
tar -xzf filebeat-<version>-linux-x86_64.tar.gz -C /opt/
配置Filebeat
cd /opt/filebeat-<version>-linux-x86_64
filebeat.yml
,通常位于/opt/filebeat-<version>-linux-x86_64/filebeat.yml
。filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
ignore_older: 72h
output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{+yyyy.MM.dd}"
创建Systemd服务文件
sudo vi /etc/systemd/system/filebeat.service
[Unit]
Description=Filebeat
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/opt/filebeat-<version>-linux-x86_64/filebeat -e -c /opt/filebeat-<version>-linux-x86_64/filebeat.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动并启用服务
sudo systemctl start filebeat
sudo systemctl enable filebeat
检查服务状态
sudo systemctl status filebeat
查看日志
sudo tail -f /var/log/filebeat/filebeat
如果你还没有安装Elasticsearch和Kibana,可以参考以下步骤进行安装和配置:
安装Elasticsearch
elasticsearch.yml
文件。安装Kibana
kibana.yml
文件,指定Elasticsearch的地址。打开Kibana界面
http://<your_server_ip>:5601
。创建索引模式
filebeat-*
。查看日志数据
通过以上步骤,你就可以在CentOS系统中成功配置Filebeat来监控日志,并将日志发送到Elasticsearch和Kibana进行可视化和分析。