运用Filebeat module分析nginx日志

在同一台主机上事先安装好filebeat,elasticsearch和kibana

filebeat配置

安装完Filebeat后,可以看到在Filebeat的安装目录下有一个叫做filebeat.yml的配置文件,还有一个叫做modules.d的文件夹。在filebeat.yml中,我们做如下的修改:

setup.kibana:
  host: "localhost:5601"
 
output.elasticsearch:
  hosts: ["localhost:9200"]

注意:filebeat.yml文件中的其他配置不需要修改

拓展:
显示Filebeat支持的模块:./filebeat modules list
启动某一个模块:./filebeat modules enable 模块名
关闭某一个模块:./filebeat modules disenable 模块名

启动nginx模块:./filebeat modules enable nginx

查看在modules.d目录下的文件变化,可以看到nginx.yml文件的最后没有“disabled”字样,表明它已经被启动成功。我们进一步编辑这个nginx.yml文件:

# Module: nginx
# Docs: https://www.elastic.co/guide/en/beats/filebeat/7.3/filebeat-module-nginx.html
 
- module: nginx
  # Access logs
  access:
    enabled: true
 
    # Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    var.paths: ["/usr/local/src/nginx_log_file/nginx.log"] # 根据nginx日志所在路径实际修改
 
  # Error logs
  error:
    enabled: true
 
    # Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    #var.paths: ["/var/log/nginx/error.log"]

为了能够使得我们的nginx模块能够正确地被Kibana显示,我们必须运行如下的命令:

[root@bogon filebeat-7.5.0-linux-x86_64]# ./filebeat setup
Index setup finished.
Loading dashboards (Kibana must be running and reachable)
Loaded dashboards
Loaded machine learning job configurations
Loaded Ingest pipelines

注意:在安装或升级Filebeat时,或在启用新模块后,必须执行setup命令

运行:./filebeat -e

已经通过./filebeat setup命令,把针对nginx的模块仪表盘导入到Kibana中了。就可以使用标准的dashboard来对nginx数据进行展示及分析。

运用Filebeat module分析nginx日志

上一篇:图片上传(前端显示预览,后端php接收)


下一篇:2020秋招金九银十程序员离职跳槽指南,作为过来人想对你们说这几点