小编给大家分享一下logstash实现日志文件同步elasticsearch的方法是什么,希望大家阅读完这篇文章后大所收获、下面让我们一起去探讨吧!
引言:
之前博文介绍过了mysql/oracle与ES之间的同步机制。而logstash最初始的日志同步功能还没有介绍。本文就logstash同步日志到ES做下详细解读。
<强> 1、目的:
强>
将本地磁盘存储的日志文件同步(全量同步,实时增量同步)到ES中。
<强> 2、源文件:
强>
[root@5b9dbaaa148a test_log] #噢 -rwxrwxrwx 1根根170年7月5日08:02 logmachine.sh -rw-r - r - 1根根66年7月5日08:25 MProbe01.log -rw-r - r - 1根根74年7月5日08:28 MProbe02。日志
<强> 3,增量实时同步脚本:强>
[root@5b9dbaaa148a test_log] #猫logmachine.sh # !/bin/bash icnt=0; 而(真) 做 回声“(调试)[20160703 - 15:00)“美元icnt祝辞祝辞MProbe01.log 回声“[错误][20160704 - 17点]“美元icnt祝辞祝辞MProbe02.log icnt=$ ((icnt + 1)); 以前做><强> 4,logstash配置文件:
强>[root@5b9dbaaa148a logstash_jdbc_test] #猫log_test.conf 输入{ 文件{ 路径=比;(“/usr/地方/logstash/bin/test_log/MProbe01.log", “/usr/地方/logstash/bin/test_log/MProbe02.log"] #编解码器=在多行{ #模式=比;“^ \ s" “#=什么;previous" #} 和“type=; probe_log"#类型名称 #标签=祝辞(“XX.XX.XX.XX") } } # # #过滤 {#过滤器 #神交{ #匹配=比;(“message"“mailmonitor"] # add_tag=比;(mailmonitor) #} #神交{ #匹配=比;(“message"“smsmonitor"] # add_tag=比;(smsmonitor) #} # .... #} # # #输出 输出{ elasticsearch { 主机=比;“10.8.5.101:9200" 指数=比;“mprobe_index"#索引名称 # template_name=比;“mprobelog" # document_id=比;“% {id}“; } stdout{编解码器=比;json_lines} }<强> 5,同步测试:强>
(root@5b9dbaaa148a本)#。//logstash_jdbc_test/log_test logstash - f。参看
引用>
设置:默认管道工人:24
管道主要开始
{“message":“(调试)[20160305 - 15:35]testing02",“@version":“1“,“@timestamp":“2016 - 07 - 05 - t07:26:08.043z",“path":“/usr/地方/logstash/bin/test_log/MProbe01.log",“host":“5 b9dbaaa148a"
<强> 6,结果验证强>
(1)日志记录:
[root@5b9dbaaa148a test_log] # tail - f MProbe01。日志
引用>
(调试)[20160305 - 15:35]testing02
(调试)[20160305 - 15:35]testing01
C ^
[root@5b9dbaaa148a test_log] # tail - f MProbe02。日志
(调试)[20160305 - 15:35]testing02_001
(调试)[20160305 - 15:35]testing02_003
(2) ES记录
看完了这篇文章,相信你对logstash实现日志文件同步elasticsearch的方法是什么有了一定的了解,想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!
logstash实现日志文件同步elasticsearch的方法是什么