logstash 操作redis

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               
在实际应用中,Logstash进程会被氛围两个不同的角色。运行在应用服务器上的尽量减轻运行压力,只做读取和转发,这个角色叫做shipper运行在独立的服务器上完成数据解析处理,负责写入到Elasticsearch的角色,叫做Indexer5.1.1 读取redis 数据:zjtest7-frontend:/usr/local/logstash-2.3.4/config# ../bin/logstash -f redis.comf Settings: Default pipeline workers: 1Pipeline main started{       "message" => "Hello world",          "tags" => [        [0] "_jsonparsefailure"    ],      "@version" => "1",    "@timestamp" => "2016-08-19T06:26:12.854Z"}zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat redis.comf input {    redis {       data_type =>"pattern_channel"       key =>"logstash-*"       host=>"192.168.32.67"       port=>6379       password => "1234567"          }}output { stdout {  codec=>rubydebug{}   }}采用list类型扩展Logstash:127.0.0.1:6379> PUBLISH logstash-list "Hello xxxxxx"(integer) 2127.0.0.1:6379> PUBLISH logstash-list "Hello yyyyy"zjtest7-frontend:/usr/local/logstash-2.3.4/config# ../bin/logstash -f redis.comf Settings: Default pipeline workers: 1Pipeline main started{       "message" => "Hello xxxxxx",          "tags" => [        [0] "_jsonparsefailure"    ],      "@version" => "1",    "@timestamp" => "2016-08-19T07:46:27.031Z"}{       "message" => "Hello yyyyy",          "tags" => [        [0] "_jsonparsefailure"    ],      "@version" => "1",    "@timestamp" => "2016-08-19T07:46:37.365Z"zjtest7-frontend:/usr/local/logstash-2.3.4/config# ../bin/logstash -f redis.comf Settings: Default pipeline workers: 1Pipeline main started{       "message" => "Hello xxxxxx",          "tags" => [        [0] "_jsonparsefailure"    ],      "@version" => "1",    "@timestamp" => "2016-08-19T07:46:26.964Z"}{       "message" => "Hello yyyyy",          "tags" => [        [0] "_jsonparsefailure"    ],      "@version" => "1",    "@timestamp" => "2016-08-19T07:46:37.362Z"}zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat redis.comf input {    redis {       data_type =>"pattern_channel"       key =>"logstash-list"       host=>"192.168.32.67"       port=>6379       password => "1234567"          }}output { stdout {  codec=>rubydebug{}   }}两个终端同时启动logstash -f redis.conf 进程,结果会是两个终端都输出消息。这个时候,就需要用list 类型,在这种类型中,数据输入到Redis 服务器上暂存,Logstash 则连上Redis 服务器取走(BLPOP命令,所以只要logstash不堵塞,redis 服务器上也不会有数据堆积占用空间)数据。1.配置示例:zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat redis.comf input {    redis {       data_type =>"list"       key =>"logstash-list"       host=>"192.168.32.67"       port=>6379       password => "1234567"          }}output { stdout {  codec=>rubydebug{}   }}这时候可以看到, 只有一个终端输出了结果连续RPUSH几次, 可以看到两个终端近乎各自输出一半条目。3.批量推送:RPUSH 支持batch 方式,修改Logstash 配置中的batch_count值,5.1.3  输出到Redis:1.配置示例zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat inputredis.conf input {stdin {} }     output {     redis {          data_type =>"channel"          key=>"logstash-chan-%{+yyyy.MM.dd}"          host=>"192.168.32.67"          port=>6379          password => "1234567" }}127.0.0.1:6379> SUBSCRIBE logstash-chan-2016.08.19Reading messages... (press Ctrl-C to quit)1) "subscribe"2) "logstash-chan-2016.08.19"3) (integer) 11) "message"2) "logstash-chan-2016.08.19"3) "{\"message\":\"\",\"@version\":\"1\",\"@timestamp\":\"2016-08-19T08:27:07.190Z\",\"host\":\"0.0.0.0\"}"1) "message"2) "logstash-chan-2016.08.19"3) "{\"message\":\"\",\"@version\":\"1\",\"@timestamp\":\"2016-08-19T08:27:07.736Z\",\"host\":\"0.0.0.0\"}"1) "message"2) "logstash-chan-2016.08.19"3) "{\"message\":\"\",\"@version\":\"1\",\"@timestamp\":\"2016-08-19T08:27:07.772Z\",\"host\":\"0.0.0.0\"}"1) "message"2) "logstash-chan-2016.08.19"3) "{\"message\":\"\",\"@version\":\"1\",\"@timestamp\":\"2016-08-19T08:27:07.808Z\",\"host\":\"0.0.0.0\"}"1) "message"2) "logstash-chan-2016.08.19"3) "{\"message\":\"\",\"@version\":\"1\",\"@timestamp\":\"2016-08-19T08:27:07.844Z\",\"host\":\"0.0.0.0\"}"1) "message"2) "logstash-chan-2016.08.19"3) "{\"message\":\"\",\"@version\":\"1\",\"@timestamp\":\"2016-08-19T08:27:07.880Z\",\"host\":\"0.0.0.0\"}"1) "message"2) "logstash-chan-2016.08.19"3) "{\"message\":\"\",\"@version\":\"1\",\"@timestamp\":\"2016-08-19T08:27:07.916Z\",\"host\":\"0.0.0.0\"}"1) "message"2) "logstash-chan-2016.08.19"3) "{\"message\":\"hello world\",\"@version\":\"1\",\"@timestamp\":\"2016-08-19T08:27:10.486Z\",\"host\":\"0.0.0.0\"}"1) "message"2) "logstash-chan-2016.08.19"3) "{\"message\":\"what'sup scab\",\"@version\":\"1\",\"@timestamp\":\"2016-08-19T08:27:37.919Z\",\"host\":\"0.0.0.0\"}"

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值