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的更多相关文章

  1. ELK快速入门(三)logstash收集日志写入redis

    ELK快速入门三-logstash收集日志写入redis 用一台服务器部署redis服务,专门用于日志缓存使用,一般用于web服务器产生大量日志的场景. 这里是使用一台专门用于部署redis ,一台专 ...

  2. ELK之logstash收集日志写入redis及读取redis

    logstash->redis->logstash->elasticsearch 1.安装部署redis cd /usr/local/src wget http://download ...

  3. ELK快速入门(四)filebeat替代logstash收集日志

    ELK快速入门四-filebeat替代logstash收集日志 filebeat简介 Filebeat是轻量级单用途的日志收集工具,用于在没有安装java的服务器上专门收集日志,可以将日志转发到log ...

  4. ELK快速入门(二)通过logstash收集日志

    ELK快速入门二-通过logstash收集日志 说明 这里的环境接着上面的ELK快速入门-基本部署文章继续下面的操作. 收集多个日志文件 1)logstash配置文件编写 [root@linux-el ...

  5. ELKStack入门篇(一)之ELK部署和使用

    一.ELKStack简介 1.ELK介绍 中文指南:https://www.gitbook.com/book/chenryn/elk-stack-guide-cn/details ELK Stack包 ...

  6. 【SSRS】入门篇(三) -- 为报表定义数据集

    原文:[SSRS]入门篇(三) -- 为报表定义数据集 通过前两篇文件 [SSRS]入门篇(一) -- 创建SSRS项目 和 [SSRS]入门篇(二) -- 建立数据源 后, 我们建立了一个SSRS项 ...

  7. ELK之filebeat替代logstash收集日志

    filebeat->redis->logstash->elasticsearch 官网下载地址:https://www.elastic.co/downloads/beats/file ...

  8. ELKStack入门篇(二)之Nginx、Tomcat、Java日志收集以及TCP收集日志使用

    1.收集Nginx的json格式日志 1.1.Nginx安装 [root@linux-node1 ~]# yum install nginx -y [root@linux-node1 ~]# vim ...

  9. ELKStack入门篇(四)之Filebeat

    Filebeat是轻量级单用途的日志收集工具,用于在没有安装java的服务器上专门收集日志,可以将日志转发到logstash.elasticsearch或redis等场景中进行下一步处理. 官方文档: ...

随机推荐

  1. Dockerfile.md

    Docker 使用 前提条件 Docker目前只能在64位CPU架构的计算机上运行(目前只能是x86_64 .amd64). Linux 3.8 或 更高版本的内核.3.8之前的版本也能运行,但效果不 ...

  2. 消息中间件--"rocketmq"02之QuickStart

    依赖 <dependency> <groupId>com.alibaba.rocketmq</groupId> <artifactId>rocketmq ...

  3. StackExchange.Redis学习笔记(一) Redis的使用初探

    Redis Redis将其数据库完全保存在内存中,仅使用磁盘进行持久化. 与其它键值数据存储相比,Redis有一组相对丰富的数据类型. Redis可以将数据复制到任意数量的从机中 Redis的安装 官 ...

  4. 判断是否POST提交

    if(strtolower($_SERVER['REQUEST_METHOD']) == 'post'){} //判断是否POST提交

  5. POJ 1157 LITTLE SHOP OF FLOWERS (超级经典dp,两种解法)

    You want to arrange the window of your flower shop in a most pleasant way. You have F bunches of flo ...

  6. CCF认证201803-2 碰撞的小球 java代码实现。

    问题描述 数轴上有一条长度为L(L为偶数)的线段,左端点在原点,右端点在坐标L处.有n个不计体积的小球在线段上,开始时所有的小球都处在偶数坐标上,速度方向向右,速度大小为1单位长度每秒. 当小球到达线 ...

  7. 【星云测试】开发者测试(2)-采用精准测试工具对J2EE Guns开发框架进行测试

    配置测试Guns Guns简介 Guns是一个近几年来基于SpringBoot的开源便利且较新的JavaEE项目开发框架,它整合了springmvc + shiro + mybatis-plus + ...

  8. RunLoop 之初探

    你好2019!一起努力呀! 1.什么是runloop runloop是通过内部维护的事件循环对事件/消息进行管理的一个对象. 事件循环(Event loop):通俗的解释:没有消息处理的时候,休眠以避 ...

  9. koa2学习笔记03 - 给koa2配置session ——koa2结构分层、配置数据库、接口

    前言 这一章写的很没有底气,因为我完全不懂一个正经的后台应用是怎么结构分层的, 所有只能按照我自己的理解去写,即使这样也仅仅只分离出了controller层, 至于所谓的service层,dao层,完 ...

  10. Ubuntu install 错误 E:Unable to locate package

    今天在 Ubuntu 上执行 sudo apt install sl 命令,结果报错:E:Unable to locate package sl 上网查询了一下,先更新一下 apt-get,执行:su ...