ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

使用filebeat 替代logstash 收集日志redis

2021-10-07 01:02:06  阅读:149  来源: 互联网

标签:filebeat log redis 2.106 nginx 172.31 root logstash


在web服务器
有就停止

[root@es-web1 ~]# systemctl stop logstash

监控单个日志配置:
上传deb包,安装

[root@es-web1 src]# dpkg -i filebeat-7.12.1-amd64.deb

filebeat改配置文件

root@long:~# grep -v "#" /etc/filebeat/filebeat.yml| grep -v "^$"

filebeat.inputs:
- type: log
  enabled: True
  paths:
    - /apps/nginx/logs/*.log
  fields:
    app: nginx
    group: n124

output.redis:
  hosts: ["172.31.2.106:6379"]
  password: "123456"
  key: "filebeat-m44-log"
  db: 2
  timeout: 5

重启

[root@es-web1 ~]# systemctl restart filebeat

检查redis

root@long:~# redis-cli -h 172.31.2.106
172.31.2.106:6379> auth 123456
172.31.2.106:6379> select 2

172.31.2.106:6379[2]> keys *
1) "filebeat-m44-log"
172.31.2.106:6379[2]> LPOP filebeat-m44-log

logstash配置文件

root@long:~# vim /etc/logstash/conf.d/filebeat-nginx-log-redis.conf

input {
  redis {
    data_type => "list"
    key => "filebeat-m44-log"
    host => "172.31.2.106"
    port => "6379"
    db => "2"
    password => "123456"
  }
}

output {
  if [fields][app] == "nginx-log" {                     
    elasticsearch {
      hosts => ["172.31.2.101:9200"]
      index => "long-filebeat-nginx-errorlog-%{+YYYY.MM.dd}"
  }}
}

重启

root@long:~# systemctl restart logstash

加入kibana

多个的配置,在原来的基础上添加

root@long:~# vim /etc/filebeat/filebeat.yml

- type: log
  enabled: True
  paths:
    - /var/log/nginx/access.log
  fields:
    app: nginx-accesslog         
    group: n125

#=========== Filebeat modules ======================

重启

root@long:~# systemctl restart filebeat

停止

root@long:~# systemctl stop logstash

访问Nginx,
检查redis

root@long:~# redis-cli -h 172.31.2.106
172.31.2.106:6379> auth 123456
172.31.2.106:6379[2]> select 3
172.31.2.106:6379[3]> keys *
1) "m44-nginx-log"

172.31.2.106:6379[3]> LPOP m44-nginx-log

配置修改

root@long:~# vim /etc/logstash/conf.d/filebeat-nginx-log-redis.conf
                                                             
input {
  redis {
    data_type => "list"
    key => "m44-nginx-log"
    host => "172.31.2.106"
    port => "6379"
    db => "2"
    password => "123456"
  }
}

output {
  if [fields][app] == "nginx-errorlog" {
    elasticsearch {
      hosts => ["172.31.2.101:9200"]
      index => "filebeat-nginx-errorlog-%{+YYYY.MM.dd}"
  }}

  if [fields][app] == "nginx-accesslog" {
    elasticsearch {
      hosts => ["172.31.2.101:9200"]
      index => "filebeat-nginx-accesslog-%{+YYYY.MM.dd}"
  }}
}

访问Nginx,还有给Nginx写入错误信息到错误日志文件里
访问

[root@es-web1 ~]# curl 172.31.2.107

写入错误信息

[root@es-web1 ~]# echo "error web 1111" >> /apps/nginx/logs/error.log

[root@es-web1 ~]# echo "error web 2222" >> /apps/nginx/logs/error.log

写入kibana

标签:filebeat,log,redis,2.106,nginx,172.31,root,logstash
来源: https://www.cnblogs.com/xuanlv-0413/p/15374799.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有