阅读量:2
以下是在Ubuntu上使用Filebeat分析日志数据的步骤:
-
安装Filebeat
从Elastic官网下载对应版本的安装包,通过包管理器安装: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 /etc/apt/sources.list.d/elastic-7.x.list sudo apt-get update && sudo apt-get install filebeat -
配置Filebeat
编辑配置文件/etc/filebeat/filebeat.yml:- 指定日志路径:在
filebeat.inputs中添加要监控的日志文件路径,如:filebeat.inputs: - type: log enabled: true paths: - /var/log/*.log - 设置输出目标:若需发送到Elasticsearch,配置如下:
若需经Logstash处理,启用Logstash输出并配置地址:output.elasticsearch: hosts: ["localhost:9200"] index: "filebeat-%{+yyyy.MM.dd}"output.logstash: hosts: ["localhost:5044"]
- 指定日志路径:在
-
启用模块(可选)
Filebeat内置模块(如System、Nginx)可简化日志解析,启用方式:sudo filebeat modules enable system # 启用系统日志模块 sudo filebeat modules enable nginx # 启用Nginx日志模块 -
启动服务
sudo systemctl start filebeat sudo systemctl enable filebeat -
可视化分析
- 安装Kibana并配置索引模式:
sudo apt-get install kibana sudo vim /etc/kibana/kibana.yml # 添加 Elasticsearch 地址 elasticsearch.hosts: ["http://localhost:9200"] - 启动Kibana后,在浏览器访问
http://localhost:5601,通过“Discover”查看日志,或使用“Visualize”创建图表。
- 安装Kibana并配置索引模式:
-
高级配置(可选)
- 多行日志合并:在
filebeat.yml中配置multiline选项,如:filebeat.inputs: - type: log multiline.pattern: '^\[' # 匹配以[开头的行 multiline.negate: true multiline.match: after - JSON日志解析:若日志为JSON格式,启用
json.keys_under_root选项自动解析字段。
- 多行日志合并:在
参考来源:
以上就是关于“如何用Ubuntu Filebeat分析日志数据”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm