zoukankan      html  css  js  c++  java
  • Filebeat使用模块收集日志

    1.先决条件

    在运行Filebeat模块之前:

    • 安装并配置Elastic stack
    • 完成Filebeat的安装
    • 检查Elasticsearch和Kibana是否正在运行,以及Elasticsearch是否准备好从Filebeat那里接收数据

    2.配置Nginx模块

    nginx模块解析Nginx创建的access和error日志

    当你运行模块的时候,它在底层执行一些任务:

    • 设置默认的日志文件路径
    • 确保将每个多行日志事件作为单个事件发送
    • 使用ingest节点解析和处理日志行,将数据塑造成适合在Kibana中可视化的结构
    • 部署显示日志数据的dashboards

    这个模块需要 ingest-user-agent 和 ingest-geoip 两个Elasticsearch插件

    你可以在Elasticsearch主目录下运行下列命令来安装这些插件:

    elasticsearch-plugin install ingest-geoip
    elasticsearch-plugin install ingest-user-agent

    然后,重启Elasticsearch

     启用nginx模块

    filebeat modules enable nginx

    修改/etc/filebeat/modules.d/nginx.yml文件

    - 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: ["/var/log/openresty/*.access.log"]
    
      # 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/openresty/*.error.log"]

     然后重启filebeat

    查看启用或者禁用的模块列表

    filebeat modules list

     3.如果要搭配Logstash使用

    1.安装插件

    /usr/share/logstash/bin/logstash-plugin install logstash-filter-geoip

    2.编辑配置文件/etc/logstash/conf.d/beats.conf

    input {
        beats {
            port => 5044
        }
    }
    
    filter {
        grok {
            match => { "message" => "%{HTTPDATE:timestamp}|%{IP:remote_addr}|%{IPORHOST:http_host}|(?:%{DATA:http_x_forwarded_for}|-)|%{DATA:request_method}|%{DATA:request_uri}|%{DATA:server_protocol}|%{NUMBER:status}|(?:%{NUMBER:body_bytes_sent}|-)|(?:%{DATA:http_referer}|-)|%{DATA:http_user_agent}|(?:%{DATA:request_time}|-)|"}
        }
        mutate {
            convert => ["status","integer"]
            convert => ["body_bytes_sent","integer"]
            convert => ["request_time","float"]
        }
        geoip {
            source=>"remote_addr"
        }
        date {
            match => [ "timestamp","dd/MMM/YYYY:HH:mm:ss Z"]
        }
        useragent {
            source=>"http_user_agent"
        }
    }
    
    output {
        elasticsearch {
          hosts => ["127.0.0.1:9200"]
                index => "nginx-%{+YYYY.MM.dd}"
        }
        stdout { codec => rubydebug }

    然后启动logstash

    参考:

    https://www.cnblogs.com/cjsblog/p/9495024.html

     
  • 相关阅读:
    PureBasic 打开一个一行有多个数据的文件并读取其中某个数据
    正则表达式的30分钟教程
    【编程珠玑】读书笔记 第一章 开篇
    while ((ch = getchar()) != EOF)中ch定义为char还是int型?cin、scanf等如何结束键盘输入
    itoa函数的实现(不同进制)
    atoi函数的实现(考虑不同进制、溢出)
    函数重载二义性:error C2668: 'pow' : ambiguous call to overloaded function
    strcat与strncat的C/C++实现
    strcpy函数的C/C++实现
    strlen的C/C+++实现
  • 原文地址:https://www.cnblogs.com/wsl222000/p/10113535.html
Copyright © 2011-2022 走看看