zoukankan      html  css  js  c++  java
  • ELK之logstash收集日志写入redis及读取redis

    logstash->redis->logstash->elasticsearch

    1.安装部署redis

    cd /usr/local/src
    wget http://download.redis.io/releases/redis-3.2.8.tar.gz
    tar xf redis-3.2.8.tar.gz
    cd redis-3.2.8/
    make
    ln -s /usr/local/src/redis-3.2.8 /usr/local/redis
    cd /usr/local/redis/
    
    vim redis.conf 
    bind 10.0.0.22
    daemonize yes
    save ""
    #save 900 1
    #save 300 10
    #save 60 10000
    requirepass root123
    
    cp src/redis-server /usr/bin/
    cp src/redis-cli /usr/bin/
    redis-server /usr/local/redis/redis.conf
    

    登录redis需要认证

    配置logstash的systemlog_to_redis.conf

    vim systemlog_to_redis.conf
    input {
      file {
        path => "/var/log/messages"
        type => "systemlog"
        start_position => "beginning"
        stat_interval => "2"
      }
    }
    
    output {
      if [type] == "systemlog" {
        redis {
          data_type => "list"
          host => "10.0.0.22"
          db => "1"
          port => "6379"
          password => "root123"
          key => "systemlog"
        }
      }
    }
    systemctl restart logstash
    # 手动写入messages日志
    cat /etc/hosts >> /var/log/messages
    echo "helloword" >> /var/log/messages
    

    登陆redis查看

    2.配置logstash从reids中取出数据到elasticsearch

    # 使用linux-elk2(10.0.0.33)上的logstash从redis取数据
    vim redis-es.conf 
    input {
      redis {
        data_type => "list"
        host => "10.0.0.22"
        db => "1"
        port => "6379"
        key => "systemlog"
        password => "root123"
      }
    }
    
    output {
      elasticsearch {
        hosts => ["10.0.0.33:9200"]
        index => "redis-systemlog-%{+YYYY.MM.dd}"
      }
    }
    systemctl restart logstash
    

    logstash统计日志,有两个以上的key时,就必须加判断

    收集日志写入redis及读取redis:http://blog.51cto.com/jinlong/2056563

  • 相关阅读:
    自动化部署之jenkins及简介
    gitlab的备份与恢复与迁移
    P2561 [AHOI2002]黑白瓷砖
    P2042 [NOI2005]维护数列
    P2156 [SDOI2009]细胞探索
    P2154 [SDOI2009]虔诚的墓主人
    P2148 [SDOI2009]E&D
    2019.2.26考试T2 矩阵快速幂加速DP
    loj #6485. LJJ 学二项式定理 (模板qwq)
    P3224 [HNOI2012]永无乡
  • 原文地址:https://www.cnblogs.com/fawaikuangtu123/p/10360142.html
Copyright © 2011-2022 走看看