• 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

     
  • 相关阅读:
    vue 中 vue-router、transition、keep-alive 怎么结合使用?
    vue 对列表数组删除和增加
    eclipse如何快速查找某个类
    在 eclipse 中设置每行的字数
    如何查看某个端口被谁占用
    sql只修改第一二行数据
    android真机自动化测试
    appium自动化测试中获取toast消息的解决方法【转】
    eclipse下python的selenium自动化环境的搭建
    Xpath用法官方手册
  • 原文地址:https://www.cnblogs.com/wsl222000/p/10113535.html
Copyright © 2020-2023  润新知