ELK快速入门三-logstash收集日志写入redis

用一台服务器部署redis服务,专门用于日志缓存使用,一般用于web服务器产生大量日志的场景。

这里是使用一台专门用于部署redis ,一台专门部署了logstash,在linux-elk1ELK集群上面进行日志收集存到了redis服务器上面,然后通过专门的logstash服务器去redis服务器里面取出数据在放到kibana上面进行展示

部署redis

下载安装redis

[root@linux-redis ~]# wget http://download.redis.io/releases/redis-5.0.0.tar.gz
[root@linux-redis ~]# tar -xvzf redis-5.0..tar.gz
[root@linux-redis ~]# mv redis-5.0. /usr/local/src/
[root@linux-redis ~]# ln -sv /usr/local/src/redis-5.0. /usr/local/redis
"/usr/local/redis" -> "/usr/local/src/redis-5.0.0"
[root@linux-redis ~]# cd /usr/local/redis/
[root@linux-redis ~]# make distclean
[root@linux-redis ~]# make

配置redis

[root@linux-redis redis]# vim redis.conf
daemonize yes
bind 192.168.1.30
requirepass [root@linux-redis redis]# cp /usr/local/redis/src/redis-server /usr/bin/
[root@linux-redis redis]# cp /usr/local/redis/src/redis-cli /usr/bin/
[root@linux-redis redis]# redis-server /usr/local/redis/redis.conf
:C Jul ::30.367 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
:C Jul ::30.367 # Redis version=5.0., bits=, commit=, modified=, pid=, just started
:C Jul ::30.367 # Configuration loaded [root@linux-redis redis]# netstat -nlutp |grep
tcp 192.168.1.30: 0.0.0.0:* LISTEN /redis-server

测试redis

[root@linux-redis redis]# redis-cli -h 192.168.1.30
192.168.1.30:> AUTH
OK
192.168.1.30:> ping
PONG
192.168.1.30:> KEYS *
(empty list or set)
192.168.1.30:> quit

配置logstash将日志写入redis

将系统日志的通过logstash收集之后写入redis,然后通过另外的logstashredis服务器的数据取出来。

配置logstash的配置文件

[root@linux-elk1 ~]# vim /etc/logstash/conf.d/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.1.30"
password => ""
port => ""
db => ""
key => "systemlog"
}
}
}

检查logstash配置语法是否正确

[root@linux-elk1 ~]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/system.conf -t
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
[WARN ] -- ::46.324 [LogStash::Runner] multilocal - Ignoring the 'pipelines.yml' file because modules or command line options are specified
Configuration OK [root@linux-elk1 ~]# systemctl restart logstash

写入messages日志测试

[root@linux-elk1 ~]# echo "redis-test" >> /var/log/messages
[root@linux-elk1 ~]# echo "systemlog" >> /var/log/messages

登录redis进行查看

[root@linux-redis ~]# redis-cli -h 192.168.1.30
192.168.1.30:> AUTH
OK
192.168.1.30:> SELECT
OK
192.168.1.30:> KEYS *
) "systemlog"
192.168.1.30:> LLEN systemlog
(integer)

配置logstash从redis中取出数据到elasticsearch

配置专门logstash服务器从redis服务器读取指定的key的数据,并写入到elasticsearch

编辑logstash配置文件

[root@logstash ~]# vim /etc/logstash/conf.d/redis-read.conf
input {
redis {
data_type => "list"
host => "192.168.1.30"
password => ""
port => ""
db => ""
key => "systemlog"
}
} output {
elasticsearch {
hosts => ["192.168.1.31:9200"]
index => "redis-systemlog-%{+YYYY.MM.dd}"
}
}

测试logstash配置是否正确

[root@logstash ~]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/redis-read.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
[INFO ] -- ::50.576 [main] writabledirectory - Creating directory {:setting=>"path.queue", :path=>"/usr/share/logstash/data/queue"}
[INFO ] -- ::50.649 [main] writabledirectory - Creating directory {:setting=>"path.dead_letter_queue", :path=>"/usr/share/logstash/data/dead_letter_queue"}
[WARN ] -- ::51.498 [LogStash::Runner] multilocal - Ignoring the 'pipelines.yml' file because modules or command line options are specified
Configuration OK [root@logstash ~]# systemctl restart logstash

验证redis的数据是否被取出

[root@linux-redis ~]# redis-cli -h 192.168.1.30
192.168.1.30:> AUTH
OK
192.168.1.30:> SELECT
OK
192.168.1.30:> KEYS *
(empty list or set) #这里数据已经为空
192.168.1.30:> SELECT
OK
192.168.1.30:[]> KEYS *
(empty list or set) #这里数据已经为空

head插件上验证数据

kibana界面创建索引模式并查看数据

ELK快速入门(三)logstash收集日志写入redis的更多相关文章

  1. ELKStack入门篇(三)之logstash收集日志写入redis

    1.部署Redis 1.1.下载redis [root@linux-node2 ~]# wget http://download.redis.io/releases/redis-4.0.6.tar.g ...

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

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

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

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

  4. ELK 使用filebeat替代Logstash收集日志

    使用beats采集日志 之前也介绍过beats是ELK体系中新增的一个工具,它属于一个轻量的日志采集器,以上我们使用的日志采集工具是logstash,但是logstash占用的资源比较大,没有beat ...

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

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

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

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

  7. ELK快速入门(一)基本部署

    ELK快速入门一-基本部署 ELK简介 什么是ELK?通俗来讲,ELK是由Elasticsearch.Logstash.Kibana 三个开源软件组成的一个组合体,这三个软件当中,每个软件用于完成不同 ...

  8. ELK快速入门(五)配置nginx代理kibana

    ELK快速入门五-配置nginx代理kibana 由于kibana界面默认没有安全认证界面,为了保证安全,通过nginx进行代理并设置访问认证. 配置kibana [root@linux-elk1 ~ ...

  9. elk快速入门-Logstash

    Logstash1.功能:数据输入,数据筛选,数据输出2.特性:数据来源中立性,支持众多数据源:如文件log file,指标,网站服务日志,关系型数据库,redis,mq等产生的数据3.beats:分 ...

随机推荐

  1. ELK原理

    为什么要使用Elasticsearch?​ 因为在我们中的数据,会随着时间变的非常多,若采用以往的模糊查询,模糊查询前置通配符,如:"%aa%",会放弃索引,导致数据表查询将变成全 ...

  2. [原创]Emmagee V2.4工具使用介绍

    [原创]Emmagee V2.4工具使用介绍 1 Emmagee 介绍 Emmagee 是网易杭州研究院 QA团队开发的一款简单易上手的Android性能监控App,主要用于监控单个App的CPU.内 ...

  3. nginx+keepalived高可用及双主模式【h】

    高可用有2中方式. 1.Nginx+keepalived 主从配置 这种方案,使用一个vip地址,前端使用2台机器,一台做主,一台做备,但同时只有一台机器工作,另一台备份机器在主机器不出现故障的时候, ...

  4. Spring Cloud config之三:config-server因为server端和client端的健康检查导致服务超时阻塞问题

    springcloud线上一个问题,当config-server连不上git时,微服务集群慢慢的都挂掉. 在入口层增加了日志跟踪问题: org.springframework.cloud.config ...

  5. DRF框架和Vue框架阅读目录

    Vue框架目录 (一)Vue框架(一)——Vue导读.Vue实例(挂载点el.数据data.过滤器filters).Vue指令(文本指令v-text.事件指令v-on.属性指令v-bind.表单指令v ...

  6. Java.util.Math类--数学相关的工具类

    Math类--数学相关的工具类 java.util.Math类是数学相关的工具类,里面提供了大量的静态方法,完成与数学运算相关的操作. public static double abs(double ...

  7. go 学习笔记---chan

    如果说 goroutine 是 Go语言程序的并发体的话,那么 channels 就是它们之间的通信机制.一个 channels 是一个通信机制,它可以让一个 goroutine 通过它给另一个 go ...

  8. NETCore执行Shell修改Centos系统IP信息

    原文:NETCore执行Shell修改Centos系统IP信息 目录 shell代码 NETCore执行Shell文件 注意事项 shell代码 首先通过find命令找到/etc/sysconfig/ ...

  9. SQL怎么实现SLEEP功能(等待时间) -(转载)

    语法格式: WAITFOR DELAY N'小时数:分钟数:秒数.毫秒数' 等待100毫秒: SELECT GETDATE() WAITFOR DELAY N'00:00:00.100' SELECT ...

  10. 局域网访问PHP项目网站 用IP地址进入

    先在apache中的 httpd.conf中将 Allow from 127.0.0.1 修改为Allow from all 如果你的是Allow from all的话就不需要改 然后再将 Docum ...