ELK-logstash--到redis存取日志

搭建Redis服务

[root@test ~]# rpm -q gcc || yum -y install gcc
[root@test ~]# tar -zxvf redis-4.0.8.tar.gz   	#上传
[root@test ~]# cd redis-4.0.8/
[root@test redis-4.0.8]#  make && make install
[root@test redis-4.0.8]# ./utils/install_server.sh   //初始化,一路enter
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port           : 6379
Config file    : /etc/redis/6379.conf
Log file       : /var/log/redis_6379.log
Data dir       : /var/lib/redis/6379
Executable     : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

配置密码

[root@test ~]# vim /etc/redis/6379.conf 
bind 192.168.1.11
daemonize yes
save ""
#save 900 1
#save 300 10
#save 60 10000
requirepass root123   //配置密码

启动

[root@test ~]# /etc/init.d/redis_6379  restart
[root@test ~]# ss -ntulp | grep 6379
tcp    LISTEN     0      128    127.0.0.1:6379  *:*    users:(("redis-server",..
[root@test ~]# redis-cli
127.0.0.1:6379> get key
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK

配置logstash

[root@logstash ~]# yum -y install logstash-2.3.4-1.noarch.rpm
[root@logstash ~]# yum -y install java
[root@logstash ~]# redis-cli -h 192.168.1.11 -p 6379
192.168.1.11:6379> auth 123456
OK

配置logstash的messegelog_to_redis.conf

[root@logstash ~]# cat messegelog_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 => "192.168.1.11"
      db => "0"
      port => "6379"
      password => "123456"
      key => "systemlog"
    }
  }
}
[root@logstash ~]# /opt/logstash/bin/logstash -f messegelog_to_redis.conf &
[1] 1549

测试存入

[root@logstash ~]# redis-cli -h 192.168.1.11 -p 6379
192.168.1.11:6379> auth 123456
OK
192.168.1.11:6379> select 0
OK
192.168.1.11:6379> llen systemlog
(integer) 9813
[root@logstash ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@logstash ~]# cat /etc/hosts >> /var/log/messages
[root@logstash ~]# redis-cli -h 192.168.1.11 -p 6379
192.168.1.11:6379> auth 123456
OK
192.168.1.11:6379> select 0
OK
192.168.1.11:6379> llen systemlog
(integer) 9815

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

[root@logstash2 ~]# vim redis-es.conf 
input {
  redis {
    data_type => "list"
    host => "192.168.1.11"
    db => "0"
    port => "6379"
    key => "systemlog"
    password => "123456"
  }
}

output {
  elasticsearch {
    hosts => ["192.168.1.16:9200"]
    index => "redis-systemlog-%{+YYYY.MM.dd}"
  }
}
[root@logstash2 ~]# /opt/logstash/bin/logstash -f  redis-es.conf  &
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值