ELKStack入门篇(三)之logstash收集日志写入redis
1、部署Redis
1.1、下载redis
[root@linux-node2 ~]# wget http://download.redis.io/releases/redis-4.0.6.tar.gz
[root@linux-node2 ~]# tar -zxvf redis-4.0..tar.gz
[root@linux-node2 ~]# mv redis-4.0. /usr/loca/src
[root@linux-node2 ~]# cd /usr/local/src/redis-4.0.
[root@linux-node2 redis-4.0.]# make
[root@linux-node2 redis-4.0.]# ln -sv /usr/local/src/redis-4.0. /usr/local/redis
[root@linux-node2 redis-4.0.]# cd /usr/local/redis
1.2、配置redis
[root@linux-node2 redis]# vim redis.conf
bind 192.168.56.12
daemonize yes
save ""
requirepass #开启认证
[root@linux-node2 redis]# cp /usr/local/src/redis-4.0./src/redis-server /usr/bin/
[root@linux-node2 redis]# cp /usr/local/src/redis-4.0./src/redis-cli /usr/bin/
[root@linux-node2 redis]# redis-server /usr/local/redis/redis.conf
:C Jan ::26.801 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
:C Jan ::26.801 # Redis version=4.0., bits=, commit=, modified=
:C Jan ::26.801 # Configuration loaded
1.3、测试redis
[root@linux-node2 ~]# netstat -tulnp |grep
tcp 192.168.56.12: 0.0.0.0:* LISTEN /redis-server
[root@linux-node2 redis]# redis-cli -h 192.168.56.12
192.168.56.12:> KEYS *
(error) NOAUTH Authentication required.
192.168.56.12:> auth
OK
192.168.56.12:> KEYS *
(empty list or set)
192.168.56.12:> quit
2、配置logstash将日志写入redis
2.1、配置logstash的system.conf
[root@linux-node1 conf.d]# vim system.conf
input {
file {
path => "/var/log/messages"
type => "systemlog"
start_position => "beginning"
stat_interval => ""
}
} output {
if [type] == "systemlog" {
redis {
data_type => "list"
host => "192.168.56.12"
db => ""
port => ""
password => ""
key => "systemlog"
}
} }
2.2、检测配置语法
[root@linux-node1 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/sy
OpenJDK -Bit Server VM warning: If the number of processors is expected to increase CThreads=N
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or
Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properti
Configuration OK
[root@linux-node1 conf.d]# systemctl restart logstash
2.3、写入messages日志测试
[root@linux-node1 conf.d]# cat /etc/hosts >> /var/log/messages
[root@linux-node1 conf.d]# echo "helloword" >> /var/log/messages
2.4、登陆redis中查看
[root@linux-node2 ~]# redis-cli -h 192.168.56.12
192.168.56.12:> KEYS *
(error) NOAUTH Authentication required.
192.168.56.12:> AUTH
OK
192.168.56.12:>
192.168.56.12:> select
OK
192.168.56.12:[]> KEYS *
) "systemlog"
192.168.56.12:[]> LLEN systemlog #查看key的长度
(integer)
192.168.56.12:[]> LLEN systemlog
(integer)
192.168.56.12:[]> LPOP systemlog #展示一条记录会减少一条
"{\"@version\":\"1\",\"host\":\"linux-node1\",\"path\":\"/var/log/messages\",\"@timestamp\":\"2018-01-02T03:04:40.424Z\",\"type\":\"systemlog\",\"tags\":[\"_geoip_lookup_failure\"]}"
192.168.56.12:[]> LLEN systemlog
(integer)
3、配置logstash从reids中取出数据到elasticsearch
3.1、使用linux-node2上的logstash从redis取数据
[root@linux-node2 conf.d]# vim redis-es.conf
input {
redis {
data_type => "list"
host => "192.168.56.12"
db => ""
port => ""
key => "systemlog"
password => ""
}
} output {
elasticsearch {
hosts => ["192.168.56.11:9200"]
index => "redis-systemlog-%{+YYYY.MM.dd}"
}
}
[root@linux-node2 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/redis-es.conf -t
OpenJDK -Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properties. Using default config which logs errors to the console
Configuration OK
[root@linux-node2 conf.d]# systemctl restart logstash
3.2、从linux-node1上写入数据查看
[root@linux-node1 conf.d]# cat /etc/passwd >> /var/log/messages
[root@linux-node2 ~]# redis-cli -h 192.168.56.12
192.168.56.12:> KEYS *
(error) NOAUTH Authentication required.
192.168.56.12:> AUTH
OK
192.168.56.12:> select
OK
192.168.56.12:[]> KEYS *
) "systemlog"
192.168.56.12:[]> LLEN systemlog #查看数据长度为38
(integer)
192.168.56.12:[]> LLEN systemlog #配置成功logstash从redis中取完数据,redis长度变成0
(integer)
3.3、head插件和Kibana添加索引查看
ELKStack入门篇(三)之logstash收集日志写入redis的更多相关文章
- ELK快速入门(三)logstash收集日志写入redis
ELK快速入门三-logstash收集日志写入redis 用一台服务器部署redis服务,专门用于日志缓存使用,一般用于web服务器产生大量日志的场景. 这里是使用一台专门用于部署redis ,一台专 ...
- ELK之logstash收集日志写入redis及读取redis
logstash->redis->logstash->elasticsearch 1.安装部署redis cd /usr/local/src wget http://download ...
- ELK快速入门(四)filebeat替代logstash收集日志
ELK快速入门四-filebeat替代logstash收集日志 filebeat简介 Filebeat是轻量级单用途的日志收集工具,用于在没有安装java的服务器上专门收集日志,可以将日志转发到log ...
- ELK快速入门(二)通过logstash收集日志
ELK快速入门二-通过logstash收集日志 说明 这里的环境接着上面的ELK快速入门-基本部署文章继续下面的操作. 收集多个日志文件 1)logstash配置文件编写 [root@linux-el ...
- ELKStack入门篇(一)之ELK部署和使用
一.ELKStack简介 1.ELK介绍 中文指南:https://www.gitbook.com/book/chenryn/elk-stack-guide-cn/details ELK Stack包 ...
- 【SSRS】入门篇(三) -- 为报表定义数据集
原文:[SSRS]入门篇(三) -- 为报表定义数据集 通过前两篇文件 [SSRS]入门篇(一) -- 创建SSRS项目 和 [SSRS]入门篇(二) -- 建立数据源 后, 我们建立了一个SSRS项 ...
- ELK之filebeat替代logstash收集日志
filebeat->redis->logstash->elasticsearch 官网下载地址:https://www.elastic.co/downloads/beats/file ...
- ELKStack入门篇(二)之Nginx、Tomcat、Java日志收集以及TCP收集日志使用
1.收集Nginx的json格式日志 1.1.Nginx安装 [root@linux-node1 ~]# yum install nginx -y [root@linux-node1 ~]# vim ...
- ELKStack入门篇(四)之Filebeat
Filebeat是轻量级单用途的日志收集工具,用于在没有安装java的服务器上专门收集日志,可以将日志转发到logstash.elasticsearch或redis等场景中进行下一步处理. 官方文档: ...
随机推荐
- iOSUI的绘图事务--Core Animation Pipeline--BackBoard(render server)
Core Animation Pipeline 流水线 在 iOS上,动画和视图的渲染其实是在另外一个进程做的(下面我们叫这个进程 render server),在 iOS 5 以前这个进程叫 Spr ...
- Client/Server 模型 与socket
Client/Server 模型 Sockets 是以 Client 和 Server 交互通信方式来使用的.典型的系统配置是把 Server 放在一台机器中,而把 Client 放在另一台机器中, ...
- virtualbox+vagrant学习-4-Vagrantfile-3-Minimum Vagrant Version
Minimum Vagrant Version 可以在Vagrantfile中指定一组vagrant版本需求,以强制人们使用带有Vagrantfile文件的vagrant特定版本.这可以帮助解决使用带 ...
- 转载:monkeyrunner之eclipse中运行monkeyrunner脚本之环境搭建(四)
转载自:lynnLi 的monkeyrunner之eclipse中运行monkeyrunner脚本之环境搭建(四) monkeyrunner脚本使用Python语法编写,但它实际上是通过Jython来 ...
- jquery全选 反选
//全选 反选 $('#chkAll').on('click',function(){ $('input.chkbox').prop('checked',$(this).prop('checked') ...
- .NET获取IIS7.0及以上版本托管服务信息
近期写了个扫描IIS托管站点然后定期注册到Consul的小工具,随意网上拷贝了个帮助类,搞完本机测试没问题,扔到服务器发现硕大的一个异常.. System.Runtime.InteropService ...
- HTML小记
1.页面内跳转 当<a>元素用于页面内的锚点跳转时,应该先为该页面设置一些锚点,而定义锚点有两种办法: 通过<a>元素的name属性来定义,如:<a name=" ...
- 排列组合:01转换法之lua实现
c++ 版连接 https://blog.csdn.net/canguanxihu/article/details/46363375 因为项目用的是lua脚本,看了C++版后自己写了一个lua版本的, ...
- iOS:手势与矩形、点运算相关(18-01-24更)
1.矩形.点运算 1.获取当前的View在Window的frame 2.包含判断 3.获取点击在响应者 touchesBegan 的位置 4.UIScrollView.UITableView 实时 位 ...
- css 中的 initial inherit unset 意思
写css时,在对属性进行选值,经常遇到unset , initial,inherit三个值.这几个值的含义. 1.inherit 可继承性 继承的意思. 每一个 CSS 属性都有一个特性就是,这个属性 ...