ubuntu

Filebeat如何与Kibana配合使用在Ubuntu

小樊
49
2025-10-25 10:59:11
栏目: 智能运维

1. 环境准备
在Ubuntu系统上安装ElasticsearchKibanaFilebeat(建议版本兼容,如均使用7.x或8.x系列)。Elasticsearch作为数据存储与搜索引擎,Kibana作为可视化工具,Filebeat作为轻量级日志收集器。

2. 安装Filebeat
通过APT包管理器安装Filebeat(以Ubuntu 22.04为例):

sudo apt update
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -  # 添加Elastic官方GPG密钥
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list  # 添加Elastic APT仓库
sudo apt update
sudo apt install filebeat -y  # 安装Filebeat

安装完成后,Filebeat配置文件默认位于/etc/filebeat/filebeat.yml

3. 配置Filebeat收集日志
编辑/etc/filebeat/filebeat.yml,完成以下核心配置:

4. 启动Filebeat服务
保存配置文件后,启动Filebeat并设置为开机自启:

sudo systemctl start filebeat  # 启动服务
sudo systemctl enable filebeat # 开机自启

通过以下命令验证Filebeat运行状态:

sudo systemctl status filebeat  # 查看服务状态(应为"active (running)")
sudo journalctl -u filebeat -f  # 实时查看Filebeat日志(排查启动错误)

若日志显示"Successfully started Filebeat",说明Filebeat已正常运行。

5. 安装并配置Kibana
通过APT包管理器安装Kibana:

sudo apt install kibana -y

编辑Kibana配置文件/etc/kibana/kibana.yml,设置连接Elasticsearch并允许远程访问:

server.host: "0.0.0.0"         # 允许所有IP访问Kibana(生产环境建议限制为特定IP)
elasticsearch.hosts: ["http://localhost:9200"]  # 指向本地Elasticsearch实例

启动Kibana并设置为开机自启:

sudo systemctl start kibana  # 启动服务
sudo systemctl enable kibana # 开机自启

验证Kibana是否运行:访问http://<Ubuntu服务器IP>:5601,若出现Kibana登录页面(默认用户名/密码为elastic/changeme,首次登录需修改密码),说明配置成功。

6. 在Kibana中创建索引模式
索引模式是Kibana识别Filebeat数据的关键,用于在Discover、Visualize等功能中查询日志。

7. 使用Kibana Discover查看日志

8. 可选:使用Filebeat模块快速可视化
若启用了Filebeat模块(如system),可通过以下命令自动加载模块的Kibana仪表板和可视化:

sudo filebeat setup --dashboards  # 加载模块的Kibana仪表板
sudo filebeat setup --index-management  # 设置索引生命周期管理(可选)

执行后,Kibana的**Dashboard(仪表板)**中会出现模块对应的可视化面板(如系统日志的CPU、内存使用率图表),无需手动创建。

注意事项

0
看了该问题的人还看了