• 使用filebeat发送nginx日志到kafka


    1.配置filebeat_nginx.yml

    filebeat.modules:
    - module: nginx
      access:
        enabled: true
        var.paths: ["/var/log/nginx/access.log*"]
      error:
        enabled: true
        var.paths: ["/var/log/nginx/error.log*"]
    
    #----------------------------------Kafka output--------------------------------#
    output.kafka:
      version: "1.0.1"
      enabled: true
      hosts: ['xxx:9092', 'xxx:9092', 'xxx:9092']
      topic: 'temp'
      required_acks: 1  #default
      compression: gzip #default
      max_message_bytes: 1000000 #default
      codec.format:
        string: '%{[message]}'
    

    2.启动filebeat

    ./filebeat -e -c filebeat_nginx.yml
    

    3.访问nginx

    tail -f /var/log/nginx/access.log
    

    日志文件输出

    {"ts":"2019-10-14 10:53:22","host":"127.0.0.1","clientip":"127.0.0.1","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"localhost","url":"/index.html","domain":"localhost","xff":"-","referer":"-","status":"304"}
    {"ts":"2019-10-14 10:53:23","host":"127.0.0.1","clientip":"127.0.0.1","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"localhost","url":"/index.html","domain":"localhost","xff":"-","referer":"-","status":"304"}
    {"ts":"2019-10-14 10:53:23","host":"127.0.0.1","clientip":"127.0.0.1","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"localhost","url":"/index.html","domain":"localhost","xff":"-","referer":"-","status":"304"}
    {"ts":"2019-10-14 10:53:30","host":"127.0.0.1","clientip":"127.0.0.1","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"localhost","url":"/index.html","domain":"localhost","xff":"-","referer":"-","status":"304"}
    {"ts":"2019-10-14 10:53:31","host":"127.0.0.1","clientip":"127.0.0.1","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"localhost","url":"/index.html","domain":"localhost","xff":"-","referer":"-","status":"304"}
    

    kafka输出

    {"ts":"2019-10-14 10:53:23","host":"127.0.0.1","clientip":"127.0.0.1","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"localhost","url":"/index.html","domain":"localhost","xff":"-","referer":"-","status":"304"}
    {"ts":"2019-10-14 10:53:23","host":"127.0.0.1","clientip":"127.0.0.1","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"localhost","url":"/index.html","domain":"localhost","xff":"-","referer":"-","status":"304"}
    {"ts":"2019-10-14 10:53:22","host":"127.0.0.1","clientip":"127.0.0.1","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"localhost","url":"/index.html","domain":"localhost","xff":"-","referer":"-","status":"304"}
    {"ts":"2019-10-14 10:53:30","host":"127.0.0.1","clientip":"127.0.0.1","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"localhost","url":"/index.html","domain":"localhost","xff":"-","referer":"-","status":"304"}
    {"ts":"2019-10-14 10:53:31","host":"127.0.0.1","clientip":"127.0.0.1","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"localhost","url":"/index.html","domain":"localhost","xff":"-","referer":"-","status":"304"}
    

     如果要采集多个log,并发送到不同的topic的话,参考

    https://blog.csdn.net/Z_GodGirl/article/details/81328000
    
  • 相关阅读:
    日报 18/06/21
    collection
    日报 18/06/20
    getTickCount()函数 VS GetTickCount()函数
    临时变量不能作为非const类型引用形参的实参
    关于Char类型数据做cout输出
    静态局部变量、静态全局变量、extern全局变量、自动变量 札记
    cvKMeans2函数用法概述
    操作系统 庞丽萍 第五章
    操作系统 庞丽萍 第四章
  • 原文地址:https://www.cnblogs.com/tonglin0325/p/11670456.html
Copyright © 2020-2023  润新知