zoukankan      html  css  js  c++  java
  • 日志收集之filebeat

    一,软件介绍

      Filebeat是一个轻量级日志传输Agent,可以将指定日志转发到Logstash、Elasticsearch、Kafka、Redis等中。Filebeat占用资源少,而且安装配置也比较简单,Filebeat附带了内部模块(auditd、Apache、Nginx、System和MySQL),这些模块简化了普通日志格式的聚集、解析和可视化。结合使用基于操作系统的自动默认设置,使用Elasticsearch Ingest Node的管道定义,以及Kibana仪表盘来实现这一点。

    二,部署安装

      本机测试环境

        存在  redis 数据库,减轻压力

        nginx web服务器 

       下载filebeat 

    1 wget https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-6.6.0-linux-x86_64.tar.gz
    2 
    3     tar zxvf filebeat-6.6.0-linux-x86_64.tar.gz
    4 
    5     ln -s filebeat-6.6.0-linux-x86_64 filebeat

      启动命令filebeat

    三,配置文件

       编写配置文件

    filebeat.inputs:
    - type: log
      enabled: true
      paths:
        - /var/log/*.log
        - /var/log/messages #配置收集的日志路径
      - /application/nginx/logs/*.log
    exclude_lines
    : ['^DBG',"^$"] ##排除的内容,正则排除 document_type: filesystem-log-5612 #设置类型 filebeat.config.modules: path: ${path.config}/modules.d/*.yml reload.enabled: false setup.template.settings: index.number_of_shards: 3 setup.kibana: output.file: path: "/tmp" filename: "text.txt"

        测试启动服务

    ./filebeat -e -c filebeat.yml -d "Publish"

       测试连接logstash连接

      

      已经存在日志文件了

        后台启动:

        

    nohup ./filebeat -e -c filebeat.yml >/dev/null 2>&1 &

        启动后立刻查看日志

     tail -f /tmp/text.txt

        再终端输入:

    echo "666666666666666" >> /var/log/messages

        

      数据已经记录了

    四,连接redis  

      配置前保证redis局域网能够连接!!

        

      结束进程:  kill 对应的pid即可    

       配置文件重新配置:  

    filebeat.inputs:
    - type: log
      enabled: true
      paths:
        - /var/log/*.log
        - /var/log/messages
        - /application/nginx/logs/*.log
      exclude_lines: ['^DBG',"^$"]
      document_type: filesystem-log-5612
    filebeat.config.modules:
      path: ${path.config}/modules.d/*.yml
      reload.enabled: false
    setup.template.settings:
      index.number_of_shards: 3
    setup.kibana:
    output.redis:
      hosts: "10.0.0.7"
      db: "1"
      port: "6379"
      password: "123"
      key: "filesystem-log-5612"

        启动

     nohup ./filebeat -e -c filebeat.yml > /dev/null 2>&1

        再redis上查看数据

       

    [root@elk-master config]# redis-cli -h 10.0.0.7 -p 6379 -a 123
    10.0.0.7:6379> keys *
    (empty list or set)
    10.0.0.7:6379> keys *
    (empty list or set)
    10.0.0.7:6379> select 1
    OK
    10.0.0.7:6379[1]> KEYS *  查看内容
    1) "filesystem-log-5612"
    10.0.0.7:6379[1]> llen filesystem-log-5612  里面文件长度
    (integer) 7
    10.0.0.7:6379[1]> llen filesystem-log-5612
    (integer) 7
    10.0.0.7:6379[1]> llen filesystem-log-5612
    (integer) 7
    10.0.0.7:6379[1]> llen filesystem-log-5612
    (integer) 7
    10.0.0.7:6379[1]> llen filesystem-log-5612
    (integer) 9
    10.0.0.7:6379[1]> KEYS *
    1) "filesystem-log-5612"
    10.0.0.7:6379[1]>

    五, logstash节点拉取数据

         logstash配置文件:

        

    input {
        redis {
            data_type => "list"
            host => "10.0.0.7"
            db => "1"
            port => "6379"
            password => "123"
            key => "filesystem-log-5612"
    
        }
    }
    
    output {
        elasticsearch {
            hosts => ["10.0.0.223:9200"]
            index => "filesystem-log-5612-%{+YYYY.MM.dd}"
        }
    }

       语法检测:

    /elk/logstash/bin/logstash -f /elk/logstash/config/logstash.conf -t

      

    没问题.启动logstash 

    /elk/logstash/bin/logstash -f /elk/logstash/config/logstash.conf &

    成功  

    六,head查看

      

    七, >>>>>>>

      

    为了监控Redis的队列长度,可以写一个监控脚本对redis进行监控,并增加zabbix报警
    
    [root@elk-master ~]# vim redis-test.py 
    #!/usr/bin/env python
    import redis
    def redis_conn():
            pool=redis.ConnectionPool(host="10.0.0.7",port=6379,db=1,password=123)
            conn = redis.Redis(connection_pool=pool)
            data = conn.llen('filesystem-log-5612')
            print(data)
    redis_conn()
    [root@elk-master ~]# python redis-test.py     #当前redis队列长度为0
    0

             

     

  • 相关阅读:
    JAVA基础复习-输入、输出缓冲字节流整合(实现图片复制)
    JAVA基础复习一 字节输入、输出流整合(实现图片复制)
    JAVA基础复习-FileRead与FileWriter结合使用示例:字符输入、输出流整合(实现文本类文件的复制)
    JAVA基础复习- 字符流FileWriter
    JAVA基础复习-字符流FileRead
    JAVA基础复习一 File类的常用功能
    mysql设置大小写敏感
    Understanding the Settlement Mechanism in Microsoft Dynamics AX
    AX2012导入导出excel
    Changes in Microsoft Dynamics AX 2012 InventTrans data model
  • 原文地址:https://www.cnblogs.com/kingle-study/p/10365631.html
Copyright © 2011-2022 走看看