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. Java虚拟机9:垃圾收集(GC)-4(垃圾收集器)

    1.前言 垃圾收集器是前一章垃圾收集算法理论知识的具体实现了,不同虚拟机所提供的垃圾收集器可能会有很大差别,另外我们必须提前说明一个道理:没有最好的垃圾收集器,更加没有万能的收集器,只能选择对具体应用 ...

  2. 反向ajax实现

    在过去的几年中,web开发已经发生了很大的变化.现如今,我们期望的是能够通过web快速.动态地访问应用.在这一新的文章系列中,我们学习如何使用反 向Ajax(Reverse Ajax)技术来开发事件驱 ...

  3. java从字符串中提取数字的简单实例

    随便给你一个含有数字的字符串,比如: String s="eert343dfg56756dtry66fggg89dfgf"; 那我们如何把其中的数字提取出来呢?大致有以下几种方法, ...

  4. Java8 Stream()关于在所有用户的所有上传记录中,找出每个用户最新上传记录

    原创文章:转载请标明出处 https://www.cnblogs.com/yunqing/p/9504196.html 首先分析相当于如下,在所有的猫中,每个名字的猫都保留年龄最小的一个 import ...

  5. rocketmq搭建

    maven参数:  mvn -Prelease-all -DskipTests clean install -U

  6. nDPI 的论文阅读和机制解析

    nDPI: Open-Source High-Speed Deep Packet Inspection Wireless Communications & Mobile Computing C ...

  7. Java语言实现通过Ajax抓取后台数据及图片

    1.Java语言实现通过Ajax抓取后台数据及图片信息 1.1数据库设计: create table picture( pic_id number not null, pic_name )not nu ...

  8. git add用法

    git add命令是将工作区内容添加到暂存区.git commit 将暂存区内容添加到版本库. git add -A  提交所有变化 git add -u  提交被修改(modified)和被删除(d ...

  9. Web | JavaScript的引用数据类型强制转换类型

    我在这里主要的想提下的是JavaScript中的引用类型进行强制转换类型.因为对于基本数据类型的变换大多都是雷同的,很容易熟知,但是引用数据类型有一点小插曲. JavaScript的引用类型主要为对象 ...

  10. code#5 P3 我有矩阵,你有吗?

    我有矩阵,你有吗?   时间限制: 1.0 秒 空间限制: 128 MB 相关文件: 题目目录 题目描述 企鹅豆豆手里有两个 01 矩阵 A 和 B.他可以进行两种操作: 选择 A 矩阵的一行,然后把 ...