FileBeat 收集 nginx 日志做数据可视化

  • 2021-09 目前Beats包含八种工具:
    • Filebeat:日志文件(收集文件数据)
    • Packetbeat:网络数据(收集网络流量数据)
    • Winlogbeat:Windows事件日志(收集Windows事件日志数据)
    • Metricbeat:指标(收集系统、进程和文件系统级别的CPU和内存使用情况等数据)
    • Heartbeat:运行时间监控(收集系统运行时的数据)
    • Auditbeat:审计数据(收集审计日志)
    • Functionbeat: 处理云数据Cloud data(让其直接将数据流从 Amazon Simple Queue Service (SQS) 传送至 Elastic Stack,便于您进行统一监测。)
    • Journalbeat: Systemd journals 读取journald日志(journalctl命令看到的日志都收集了)

简单版 filebeat 收集 nginx 日志 到 ElasticSearch

请添加图片描述

wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.14.0-linux-x86_64.tar.gz
tar -zxvf filebeat-7.14.0-linux-x86_64.tar.gz

mv filebeat-7.14.0-linux-x86_64 filebeat-7.14.0
cd filebeat-7.14.0
# 备份默认配置文件
mv filebeat.yml filebeat.yml.bak

# 创建新的配置文件
vim filebeat.yml
  • 写入配置
# 加载 filebeat modules.d 下的配置
filebeat.config.modules:
  path: /data/soft/filebeat-7.14.0/modules.d/*.yml
  reload.enabled: true
  reload.period: 10s
  
output.elasticsearch:
  hosts: ["172.15.10.163:9207","172.15.10.163:9208","172.15.10.163:9209"]
  index: "nginx-log-%{[beat.version]}-%{+yyyy.MM}"

setup.kibana:
  host: "172.16.10.163:5601"

# 指定分析索引为 ngnix-log- 开头的 *
setup.template.name: "ngnix-log-"
setup.template.pattern: "ngnix-log-*"
setup.dashboards.index: "nginx-log-*"
#覆盖一个已存在的模板
setup.template.overwrite: true
#禁用自动加载模板
setup.template.enabled: false

# 指定 ngnix-log 索引的 分片与副本
#setup.template.settings:
#  index.number_of_shards: 1
#  index.number_of_replicas: 1
  • 配置 nginx 日志目录
# 查看并激活模块
./filebeat modules list
./filebeat modules enable nginx
./filebeat modules enable elasticsearch

vim modules.d/nginx.yml
- module: nginx
  access:
    enabled: true
    var.paths: ["/var/log/nginx/access.log*"]
  error:
    enabled: true
    var.paths: ["/var/log/nginx/error.log*"]
  • 启动 FileBeat
# 测试配置文件是否正确
./filebeat -c filebeat.yml test config
# 启动 filebeat 
sudo ./filebeat -e -c filebeat.yml > /dev/null &
# 在 kibana 中创建 index-pattern
./filebeat -c filebeat.yml setup
  • 参考 https://www.elastic.co/guide/en/beats/filebeat/7.9/could-not-locate-index-pattern.html

  • 访问项目让 nginx 产生日志

  • 打开 kibana 查看视图
    请添加图片描述

  • 这几个视图都可以用, 我这里打开的是: [Filebeat Nginx] [ML] Remote IP Count Explorer
    请添加图片描述

  • 参考链接

  • https://www.elastic.co/guide/en/beats/filebeat/7.9/could-not-locate-index-pattern.html

  • https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-module-nginx.html#configuring-nginx-module

  • https://blog.csdn.net/weixin_43999932/article/details/106836786

  • https://www.shuzhiduo.com/A/8Bz89mm1Jx/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值