配置logstash收集单个日志到redis
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@web01 ~]# vim /etc/logstash/conf.d/file_redis.conf input { file { path => "/var/log/nginx/access.log" start_position => "end" codec => "json" } } output { redis { host => "172.16.1.81" port => "6379" key => "nginx_log" data_type => "list" } } |
配置logstash收集多个日志到redis
1)配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
[root@web01 ~]# cat /etc/logstash/conf.d/file_redis.conf input { file { type => "nginx_log" path => "/var/log/nginx/access.log" start_position => "end" codec => "json" } file { type => "tomcat_log" path => "/usr/local/tomcat/logs/tomcat_access_json.*.log" start_position => "end" codec => "json" } } output { if [type] == "nginx_log" { redis { host => "172.16.1.81" port => "6379" key => "nginx_log" data_type => "list" db => "0" } } if [type] == "tomcat_log" { redis { host => "172.16.1.81" port => "6379" key => "tomcat_log" data_type => "list" db => "1" } } } |
2)启动
1 2 |
[root@web01 ~]# logstash -f /etc/logstash/conf.d/file_redis.conf |
配置logstash取出redis数据写入ES
1)配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
[root@redis02 ~]# vim /etc/logstash/conf.d/redis_es.conf input { redis { host => "172.16.1.81" port => "6379" data_type => "list" key => "nginx_log" db => "0" } redis { host => "172.16.1.81" port => "6379" data_type => "list" key => "tomcat_log" db => "1" } } output { if [type] == "nginx_log" { elasticsearch { hosts => ["10.0.0.71:9200"] index => "nginx_redis_es_%{+YYYY-MM-dd}" } } if [type] == "tomcat_log" { elasticsearch { hosts => ["10.0.0.71:9200"] index => "tomcat_redis_es_%{+YYYY-MM-dd}" } } } |
2)启动
1 2 |
[root@redis02 ~]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/redis_es.conf |