在CentOS系统上部署Filebeat的步骤如下:
Filebeat通常与Elasticsearch和Kibana一起使用,因此首先需要确保这些组件已经安装并运行。
sudo yum install -y elasticsearch
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
sudo yum install -y kibana
sudo systemctl start kibana
sudo systemctl enable kibana
访问Elastic官方网站下载最新版本的Filebeat。
sudo yum install filebeat
sudo tar -xzf filebeat-<version>-linux-x86_64.tar.gz -C /opt/
cd /opt/filebeat-<version>-linux-x86_64
编辑Filebeat配置文件/opt/filebeat-<version>-linux-x86_64/filebeat.yml。
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
根据你的需求调整输入路径和输出目标。例如,如果你想将日志发送到远程Elasticsearch服务器,可以修改output.elasticsearch.hosts。
sudo /opt/filebeat-<version>-linux-x86_64/filebeat -e -c /opt/filebeat-<version>-linux-x86_64/filebeat.yml
创建一个systemd服务文件来管理Filebeat的开机自启动。
创建服务文件:
sudo vi /etc/systemd/system/filebeat.service
添加以下内容:
[Unit]
Description=Filebeat
After=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
重新加载systemd配置:
sudo systemctl daemon-reload
启用并启动Filebeat服务:
sudo systemctl enable filebeat
sudo systemctl start filebeat
检查Filebeat的日志文件以确保没有错误:
sudo tail -f /var/log/filebeat/filebeat
你也可以通过Kibana界面查看Filebeat收集的数据。
如果你的Elasticsearch和Kibana运行在不同的服务器上,确保防火墙允许相应的端口通信。
sudo firewall-cmd --zone=public --add-port=9200/tcp --permanent
sudo firewall-cmd --zone=public --add-port=5601/tcp --permanent
sudo firewall-cmd --reload
通过以上步骤,你应该能够在CentOS系统上成功部署Filebeat。