博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
logstash 操作redis
阅读量:4878 次
发布时间:2019-06-11

本文共 4451 字,大约阅读时间需要 14 分钟。

在实际应用中,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\"}"

转载于:https://www.cnblogs.com/zhaoyangjian724/p/6199346.html

你可能感兴趣的文章
window.frameElement的使用
查看>>
nl命令
查看>>
如何使用jQuery $.post() 方法实现前后台数据传递
查看>>
Using Flash Builder with Flash Professional
查看>>
jsp/post中文乱码问题
查看>>
C# 插入或删除word分页符
查看>>
数据库数据的查询----连接查询
查看>>
html图片设置fixed消失,为什么fixed后,DIV7消失了,怎么显示出来?
查看>>
html5隐藏自定义控制按钮,用仿ActionScript的语法来编写html5——第七篇,自定义按钮...
查看>>
找不到可安装的ISAM ,asp.net读取数据丢失,解决的一列里有字符与数字的
查看>>
Java学习笔记三(对象的基本思想一)
查看>>
Bezier贝塞尔曲线的原理、二次贝塞尔曲线的实现
查看>>
Java程序(文件操作)
查看>>
Alignment (DP基础--最长上升子序列)
查看>>
SPF(图的割点)
查看>>
KMP算法的Next数组详解
查看>>
Brackets (区间DP)
查看>>
Tarjan算法
查看>>
Strategic Game(树形DP)
查看>>
迷宫城堡 (求强连通)
查看>>