在Ubuntu上安装和配置Filebeat的步骤如下:
更新系统包列表
sudo apt update
导入Elastic官方GPG密钥
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
添加Elastic官方APT仓库
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
更新APT包列表
sudo apt update
安装Filebeat
sudo apt install filebeat
启动并启用Filebeat服务
sudo systemctl start filebeat
sudo systemctl enable filebeat
查看Filebeat配置文件位置
filebeat modules enable system
filebeat setup
这将生成默认的配置文件/etc/filebeat/filebeat.yml
。
编辑配置文件 打开配置文件进行编辑:
sudo nano /etc/filebeat/filebeat.yml
以下是一些常见的配置项:
输出到Elasticsearch
output.elasticsearch:
hosts: ["localhost:9200"]
指定日志文件路径
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/*.log
模块配置
如果你启用了某些模块(如system
),可以进一步配置它们:
filebeat.modules:
- module: system
metricsets:
- process
period: 10s
日志级别
logging.level: info
保存并退出编辑器
重启Filebeat服务以应用更改
sudo systemctl restart filebeat
检查Filebeat状态
sudo systemctl status filebeat
查看Filebeat日志
journalctl -u filebeat -f
检查Elasticsearch中的数据 打开Kibana或使用curl命令查看Elasticsearch中是否有Filebeat发送的数据:
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"match_all": {}
}
}
'
通过以上步骤,你应该能够在Ubuntu上成功安装和配置Filebeat,并将其日志发送到Elasticsearch。根据你的具体需求,可以进一步调整和优化配置文件。