以下是在Ubuntu上集成Filebeat与Elasticsearch的教程:
更新系统包列表,添加Elastic官方GPG密钥和APT仓库,然后安装Filebeat。具体命令如下:
sudo apt update
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 update
sudo apt install filebeat
编辑配置文件/etc/filebeat/filebeat.yml
。指定要监控的日志文件路径,如filebeat.inputs
部分;设置Elasticsearch输出信息,包括主机地址、端口、索引名称等,如output.elasticsearch
部分。示例配置如下:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
output.elasticsearch:
hosts: ["localhost:9200"]
index: "filebeat-%{[agent.version]}-%{+yyyy.MM.dd}"
使用以下命令启动Filebeat服务并设置为开机自启:
sudo systemctl start filebeat
sudo systemctl enable filebeat
通过查看Filebeat状态和日志,以及检查Elasticsearch中的索引来验证集成是否成功。命令如下:
sudo systemctl status filebeat
journalctl -u filebeat -f
curl -X GET "localhost:9200/_cat/indices?v"