ELK-elkstack-使用消息队列
日志通过logstash收集到redis,之后从logstash从redis读取数据存入到ES


1. logstash使用redis测试
通过标准输入到redis中
logstash配置与启动
[yun@mini03 config]$ pwd
/app/logstash/config
[yun@mini03 config]$ cat redis_test.conf
input{
stdin{}
} filter{
} output{
redis {
data_type => "list"
# 生产环境需要规划
db =>
host => "mini03"
port =>
key => "redis_test"
}
} ### 使用yun用户即可
[yun@mini03 ~]$ /app/logstash/bin/logstash -f /app/logstash/config/redis_test.conf
………… 654321zhags
redis查看
[root@mini03 ~]# redis-cli -h mini03 -p
mini03:> select
OK
mini03:[]> KEYS * # 生产环境禁止使用该命令
) "redis_test"
mini03:[]> type redis_test
list
mini03:[]> llen redis_test
(integer)
mini03:[]> lindex redis_test -
"{\"host\":\"mini03\",\"message\":\"654321zhags\",\"@timestamp\":\"2018-08-29T13:58:02.184Z\",\"@version\":\"1\"}"
2. httpd日志收集到redis中
logstash配置与启动
[yun@mini03 config]$ pwd
/app/logstash/config
[yun@mini03 config]$ cat redis_httpd_test.conf
input{
file{
path => ["/var/log/httpd/access_log"]
type => "httpd-access-log"
start_position => "beginning"
}
} filter{
} output{
redis {
data_type => "list"
# 生产环境需要规划
db =>
host => "mini03"
port =>
key => "apache-access-log"
}
} #### 使用root用户,涉及权限
[root@mini03 ~]# /app/logstash/bin/logstash -f /app/logstash/config/redis_httpd_test.conf # 使用root用户
使用谷歌、火狐或者IE浏览器访问
redis查看
[root@mini03 ~]# redis-cli -h mini03 -p 6379
mini03:6379> select 1
OK
mini03:6379[1]> KEYS *
1) "apache-access-log"
2) "redis_test"
mini03:6379[1]> llen apache-access-log
(integer) 28
mini03:6379[1]> lindex apache-access-log -1
"{\"message\":\"10.0.0.1 - - [29/Aug/2018:22:08:30 +0800] \\\"GET /aaabbb/?aaa=bbb HTTP/1.1\\\" 404 205 \\\"-\\\" \\\"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0\\\"\",\"type\":\"httpd-access-log\",\"path\":\"/var/log/httpd/access_log\",\"host\":\"mini03\",\"@timestamp\":\"2018-08-29T14:08:31.442Z\",\"@version\":\"1\"}"
3. logstash从redis读取数据标准输出
注意:该logstash在mini02上读取mini03上redis的数据
读取之后先使用grok进行过滤
之后进行标准输出【命令行输出】
logstash配置与启动
[yun@mini02 config]$ pwd
/app/logstash/config
[yun@mini02 config]$ cat redis_stdout.conf
input{
redis {
data_type => "list"
db => 1
host => "mini03"
port => 6379
key => "apache-access-log"
}
} filter{
grok {
match => { "message" => "%{HTTPD_COMBINEDLOG}" }
}
} output{
stdout { codec => rubydebug }
} ###### 使用yun用户即可
[yun@mini02 ~]$ /app/logstash/bin/logstash -f /app/logstash/config/redis_stdout.conf
……………………
{
"request" => "/noindex/css/fonts/Bold/OpenSans-Bold.ttf",
"message" => "10.0.0.1 - - [30/Aug/2018:17:22:13 +0800] \"GET /noindex/css/fonts/Bold/OpenSans-Bold.ttf HTTP/1.1\" 404 238 \"http://mini03/noindex/css/open-sans.css\" \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36\"",
"@version" => "1",
"bytes" => "238",
"auth" => "-",
"referrer" => "\"http://mini03/noindex/css/open-sans.css\"",
"response" => "404",
"type" => "httpd-access-log",
"clientip" => "10.0.0.1",
"@timestamp" => 2018-08-30T09:22:13.950Z,
"ident" => "-",
"verb" => "GET",
"path" => "/var/log/httpd/access_log",
"host" => "mini03",
"agent" => "\"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36\"",
"timestamp" => "30/Aug/2018:17:22:13 +0800",
"httpversion" => "1.1"
}
{
"request" => "/?refresh=1m&orgId=1",
"message" => "10.0.0.1 - - [30/Aug/2018:17:22:13 +0800] \"GET /?refresh=1m&orgId=1 HTTP/1.1\" 403 4897 \"-\" \"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36\"",
"@version" => "1",
"bytes" => "4897",
"auth" => "-",
"referrer" => "\"-\"",
"response" => "403",
"type" => "httpd-access-log",
"clientip" => "10.0.0.1",
"@timestamp" => 2018-08-30T09:22:13.949Z,
"ident" => "-",
"verb" => "GET",
"path" => "/var/log/httpd/access_log",
"host" => "mini03",
"agent" => "\"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36\"",
"timestamp" => "30/Aug/2018:17:22:13 +0800",
"httpversion" => "1.1"
}
……………………
4. elkstack-使用redis作为消息队列【汇总】
在mini03的logstash读取httpd的日志,并存储到redis
4.1. mini03的 logstash配置如下:
[yun@mini03 config]$ pwd
/app/logstash/config
[yun@mini03 config]$ cat redis_httpd_test.conf
input{
file{
path => ["/var/log/httpd/access_log"]
type => "httpd-access-log"
start_position => "beginning"
}
} filter{
} output{
redis {
data_type => "list"
# 生产环境需要规划
db =>
host => "mini03"
port =>
key => "apache-access-log"
}
} ######## 使用root用户,涉及权限
[root@mini03 ~]# /app/logstash/bin/logstash -f /app/logstash/config/redis_httpd_test.conf
………………
在mini02的logstash读取redis信息,并存储在ES
4.2. mini02的logstash配置
[yun@mini02 config]$ pwd
/app/logstash/config
[yun@mini02 config]$ cat redis_es.conf
input{
redis {
data_type => "list"
db =>
host => "mini03"
port =>
key => "apache-access-log"
}
} filter{
grok {
match => { "message" => "%{HTTPD_COMBINEDLOG}" }
}
} output{
# es有3台,随便指定一台即可 也可以是多台如 ["127.0.0.1:9200","127.0.0.2:9200"]
elasticsearch {
hosts => ["mini01:9200", "mini02:9200", "mini03:9200"]
index => "httpd-access-log-%{+YYYY.MM.dd}"
}
} ####### 使用yun用户即可
[yun@mini02 ~]$ /app/logstash/bin/logstash -f /app/logstash/config/redis_es.conf
………………
4.3. 浏览器访问httpd
浏览器
# 可以通过谷歌、火狐、IE访问
http://mini03/
http://mini03/indweg.html
Linux命令行访问
[yun@mini02 ~]$ ab -n40 -c http://mini03/
[yun@mini02 ~]$ ab -n40 -c http://mini03/wet/bdhw/
4.4. 信息查看
elasticsearch-head查看

kibana查看

ELK-elkstack-使用消息队列的更多相关文章
- ELKStack之消息队列
redis消息队列 安装redis yum -y install redis 修改配置文件 修改ip 后台运行 启动 systemctl start redis 查看 lsof -i:6379 连接 ...
- ELK之使用kafka作为消息队列收集日志
参考:https://www.cnblogs.com/fengjian2016/p/5841556.html https://www.cnblogs.com/hei12138/p/7805475 ...
- ELK之消息队列选择redis_kafka_rabbitmq
前言描述 生产初级,Service服务较少,访问量较少,随着业务量的不断增加,日志量成倍增长,然后就遇到了消息队列redis被充爆,不能满足应用的情况.针对此情况,我们来分析下可用的消息多列. 官方推 ...
- redis 验证消息队列也是写磁盘的
# 下面的例子将会进行把数据写入磁盘的操作: # 900秒(15分钟)之后,且至少1次变更 # 300秒(5分钟)之后,且至少10次变更 # 60秒之后,且至少10000次变更 # # 注意:你要想不 ...
- 常用的消息队列中间件mq对比
原文地址:https://blog.csdn.net/qq_30764991/article/details/80239076 消息队列中间件是分布式系统中重要的组件,主要解决应用耦合,异步消息,流量 ...
- MQ(1)---消息队列概念和使用场景
消息队列概念和使用场景 声明:本文转自:MQ入门总结(一)消息队列概念和使用场景 写的很好,都不用自己在整理了,非常感谢该作者的用心. 一.什么是消息队列 消息即是信息的载体.为了让消息发送者和消息接 ...
- Java并发编程原理与实战三十六:阻塞队列&消息队列
一.阻塞队列 1.阻塞队列BlockingQueue ---->可以理解成生产者消费者的模式---->消费者要等待到生产者生产出来产品.---->而非阻塞队列ConcurrentLi ...
- RabbitMQ (十六) 消息队列的应用场景 (转)
原贴 : http://blog.csdn.net/cws1214/article/details/52922267 消息队列中间件是分布式系统中重要的组件,主要解决应用耦合,异步消息,流量削锋等问题 ...
- 消息队列 概念 配合SpringBoot使用Demo
转http://www.jianshu.com/p/048e954dab40 概念: 分布式消息队列 ‘分布式消息队列’包含两个概念 一是‘消息队列’,二是‘分布式’ 那么就先看下消息队列的概念,和为 ...
- MQ入门总结(一)消息队列概念和使用场景
一.消息队列 消息即是信息的载体.为了让消息发送者和消息接收者都能够明白消息所承载的信息(消息发送者需要知道如何构造消息:消息接收者需要知道如何解析消息),它们就需要按照一种统一的格式描述消息,这种统 ...
随机推荐
- Java爬取网络博客文章
前言 近期本人在某云上购买了个人域名,本想着以后购买与服务器搭建自己的个人网站,由于需要筹备的太多,暂时先搁置了,想着先借用GitHub Pages搭建一个静态的站,搭建的过程其实也曲折,主要是域名地 ...
- Python中的序列操作
官方手册:https://docs.python.org/3.7/library/stdtypes.html#sequence-types-list-tuple-range 序列简介 序列是指按照位置 ...
- C#函数返回值。
一.params. 可变参数,无论有几个参数,必须出现在参数列表的最后,可以为可变参数直接传递一个对应类型的数组. class Program { static void Main(string[] ...
- 【转载】C#常用数据库Sqlserver通过SQL语句查询数据库以及表的大小
在Sqlserver数据库中,一般我们查看数据库的大小可以通过查找到数据库文件来查看,但如果要查找数据表Table的大小的话,则不可通过此方法,在Sqlserver数据库中,提供了相应的SQL语句来查 ...
- C# 中 FindControl 方法及使用
FindControl 的使用方法 FindControl (String id): 在页命名容器中搜索带指定标识符的服务器控件.(有点类似javascript中的getElementById(st ...
- springbooot2 thymeleaf 配置以及加载资源文件。Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
最近在学习springbooot2 和 thymeleaf 程序文件 application.properties文件配置: #thymeleaf spring.thymeleaf.prefix=cl ...
- 1. volatale 关键字 -内存可见性
package com.gf.demo01; /** * 一.volatile 关键字:但多个线程进行操作共享数据时,可以保证内存中数据可见性. * */ public class TestVolat ...
- Java中net.sf.json包关于JSON与对象互转的坑
在Web开发过程中离不开数据的交互,这就需要规定交互数据的相关格式,以便数据在客户端与服务器之间进行传递.数据的格式通常有2种:1.xml:2.JSON.通常来说都是使用JSON来传递数据.本文正是介 ...
- js的介绍 及用法 常量 变量!
1.js介绍 js全程叫javascript,但不是java 他是一门前台语言 而java是后台语言. js的作者是布兰登 爱奇 前台语言:运行在客户端 后台语言:跟数据库有关的. 2.能干什么? 页 ...
- 自动化运维经验谈,以及为什么Docker是革命性的
互联网+的需要 在信息越来越繁杂的互联网时代,公司所运行的项目越来越多,项目相关服务繁多,服务之间存在复杂的依赖关系,运维与管理任务越来越繁重,手工交付需要花费很多的人力与时间,且安全性和时效性均无法 ...