Redis做消息队列

1.连接从Redis中获取日志文件并存储到ES中

[root@Logstash ~]# vim /usr/local/logstash/config/redis.conf

input {

    beats {

    port => "5044"

     }

    redis {

    data_type => "list"

        key => "220"

        host => "192.168.200.134"

        port => 6379

        db => 0

        threads => 1

    }

}

filter {

    if [type] == "nginx"{

    grok {

    match => { "message" => "%{NGINXACCESS}" }

 

  }

 

  }

 

  date {

    match => [ "timestamp", "dd/MMM/yyyy:HH:mm:ss Z" ]

    target => ["datetime"]

  }

  geoip {

    source => "clientip"

  }

 

}

 

output {

 if [fields][logsource] == "220nginx_access"{

     elasticsearch {

      hosts => ["192.168.200.130:9200"]

      index => "220nginx_access"

     }

}

   if [fields][logsource] == "220nginx_error"{

     elasticsearch {

      hosts => ["192.168.200.130:9200"]

      index => "220nginx_error"

     }

  }

 

        stdout { codec => rubydebug }

}

 

2.将Nginx访问日志和错误日志推送到Redis消息队列中。

[root@mobanji filebeat]# egrep -v "#|^$" filebeat.yml

filebeat.prospectors:

- type: log

  fields:

    logsource: 220nginx_access

    log_type: access_log

    fields_under_root: true

  paths:

    - /usr/local/nginx/logs/access.log

- type: log

  fields:

    logsource: 220nginx_error

    log_type: error_log

  paths:

    - /usr/local/nginx/logs/error.log

output.redis:

  hosts: ["192.168.200.134"]

  port: 6379

  db: 0

  timeout: 5

  key: "220"

3.收集Nginx和Tomcat日志:

[root@mobanji ~]# egrep -v "#|^$" /usr/local/filebeat/filebeat.yml

filebeat.prospectors:

- type: log

  fields:

    logsource: 220nginx_access

    log_type: access_log

    fields_under_root: true

  paths:

    - /usr/local/nginx/logs/access.log

- type: log

  fields:

    logsource: 220nginx_error

    log_type: error_log

  paths:

    - /usr/local/nginx/logs/error.log

- type: log

  fields:

    logsource: 220tomcat_out

    log_type: tomcat_out

  paths:

    - /usr/local/tomcat/logs/catalina.out

output.redis:

  hosts: ["192.168.200.134"]

  port: 6379

  db: 0

  timeout: 5

  key: "220"

 

转载于:https://www.cnblogs.com/momenglin/p/10877378.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值