分布式实时日志处理平台ELK
这三样东西分别作用是:日志收集、索引与搜索、可视化展现
l logstash
这张架构图可以看出logstash只是collect和index的地方,运行时传入一个.conf文件,配置分三部分:input ,filter,output。
l redis
redis在这里是作为日志收集与索引之间解耦作用
l elasticsearch
核心组件,用来搜索。主要特点:real-time,distributed,Highly Available,document oriented,schema free,RESTful
kibana
可视化日志组件,让数据交互变得更容易
部署
需要的组件
- logstash https://download.elasticsearch.org/logstash/logstash/logstash-1.4.2.tar.gz
- redis http://download.redis.io/releases/redis-stable.tar.gz
- elasticsearch https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.2.zip
- kibana https://github.com/elasticsearch/kibana
Logstash
logstash 10 分钟教程 :http://logstash.net/docs/1.4.2/tutorials/10-minute-walkthrough/
下载最新logstash版本并解压
编辑logstash.conf配置文件
logstash用户说明文档:http://logstash.net/docs/1.4.2/
log4j server配置实例:log4j.conf
|
input { log4j { data_timeout => 5 # mode => "server" # port => 4560 } } filter { json { source => "message" remove_field => ["message","class","file","host","method","path","priority","thread","type","logger_name"] } } output{ #stdout { codec => json } redis { host => "redis.internal.173" port => 6379 data_type => "list" key => "soalog" } } |
logstash输出elasticsearch配置实例:soalog-es.conf
|
input { redis { host => "redis.internal.173" port => "6379" key => "soalog" data_type => "list" } } filter { json { source => "message" remove_field => ["message","type"] } } output { elasticsearch { #host => "es1.internal.173,es2.internal.173,es3.internal.173" cluster => "soaes" index => "soa_logs-%{+YYYY.MM.dd}" } } |
这里filter配置source => message,是把message里json串解析出来,作为索引字段,然后配置remove_field 把不需要字段删除
启动
./logstash -f soalog-es.conf --verbose -l ../soalog-es.log &
./logstash -f log4j.conf --verbose -l ../log4j.log &
Elastcisearch
下载最新版本elasticsearch并解压
bin/elasticsearch -d 后端运行
验证
elasticsearch集群配置:
编辑 config/elasticsearch.yml
#指定你的集群名称,默认是elasticsearch,在使用客户端连接集群模式会用到
cluster.name: soaes
#指定数据存储目录,可以多个磁盘 /path/to/data1,/path/to/data2
path.data: /mnt/hadoop/esdata
#指定日志存储目录
path.logs: /mnt/hadoop/eslogs
#集群主节点列表,执行发现新节点
discovery.zen.ping.unicast.hosts: ["hadoop74", "hadoop75"]
配置es模板 ,可以指定字段是否索引,以及存储类型
在config目录下创建templates目录
增加模板文件template-soalogs.json
|
{ "template-soalogs" : { "template" : "soa_logs*", "settings" : { "index.number_of_shards" : 5, "number_of_replicas" : 1, "index" : { "store" : { "compress" : { "stored" : true, "tv": true } } } }, "mappings" : { "logs" : { "properties" : { "providerNode" : { "index" : "not_analyzed", "type" : "string" }, "serviceMethod" : { "index" : "not_analyzed", "type" : "string" }, "appId" : { "index" : "not_analyzed", "type" : "string" }, "status" : { "type" : "long" }, "srcAppId" : { "index" : "not_analyzed", "type" : "string" }, "remark" : { "type" : "string" }, "serviceVersion" : { "index" : "not_analyzed", "type" : "string" }, "srcServiceVersion" : { "index" : "not_analyzed", "type" : "string" }, "logSide" : { "type" : "long" }, "invokeTime" : { "type" : "long" }, "@version" : { "type" : "string" }, "@timestamp" : { "format" : "dateOptionalTime", "type" : "date" }, "srcServiceInterface" : { "index" : "not_analyzed", "type" : "string" }, "serviceInterface" : { "index" : "not_analyzed", "type" : "string" }, "retryCount" : { "type" : "long" }, "traceId" : { "index" : "not_analyzed", "type" : "string" }, "processTime" : { "type" : "long" }, "consumerNode" : { "index" : "not_analyzed", "type" : "string" }, "rpcId" : { "index" : "not_analyzed", "type" : "string" }, "srcServiceMethod" : { "index" : "not_analyzed", "type" : "string" } } } } } } |
kibana
进入elasticsearch目录
bin/plugin -install elasticsearch/kibana
验证:http://localhost:9200/_plugin/kibana
kibana需要配置查询索引规则
这里index是soa_logs,按天分索引格式需要指定为YYYY-MM-DD
logstash时差8小时问题
logstash在按每天输出到elasticsearch时,因为时区使用utc,造成每天8:00才创建当天索引,而8:00以前数据则输出到昨天的索引
修改logstash/lib/logstash/event.rb 可以解决这个问题
第226行
.withZone(org.joda.time.DateTimeZone::UTC)
修改为
.withZone(org.joda.time.DateTimeZone.getDefault())
log4j.properties配置
#remote logging
log4j.additivity.logstash=false
log4j.logger.logstash=INFO,logstash
log4j.appender.logstash =
org.apache.log4j.net.SocketAppender
log4j.appender.logstash.RemoteHost
= localhost
log4j.appender.logstash.Port =
4560
log4j.appender.logstash.LocationInfo
= false
java日志输出
private static final
org.slf4j.Logger logstash = org.slf4j.LoggerFactory.getLogger("logstash");
logstash.info(JSONObject.toJSONString(rpcLog));
KOPF
elasticsearch集群监控
bin/plugin -install
lmenezes/elasticsearch-kopf
http://localhost:9200/_plugin/kopf
logstash接入tomcat日志示例:
logstash代理端配置tomcat.conf
|
input { file { type=> "usap" path=> 17173/apache-tomcat-7.0.50-8085/logs/catalina.out","/opt/17173/apache-tomcat-6.0.37-usap-image/logs/catalina.out"] codec=> multiline { pattern => what=> "previous" } } } filter { grok { #match => { "message" => match => [ "message", remove_field => ["message"] } } output { # stdout{ codec => rubydebug } redis {host => "redis.internal.173" data_type => "list" } |
修改logstash/patterns/grok-patterns
增加tomcat日志过滤正则
|
#tomcat log JAVACLASS (?:[a-zA-Z0-9-]+\:)+[A-Za-z0-9$]+ JAVALOGMESSAGE (.*) THREAD [A-Za-z0-9\-\[\]]+ # MMM dd, yyyy HH:mm:ss eg: Jan 9, 2014 7:13:13 AM CATALINA_DATESTAMP %{MONTH} %{MONTHDAY}, 20%{YEAR} # yyyy-MM-dd HH:mm:ss,SSS ZZZ eg: 2014-01-09 TOMCAT_DATESTAMP 20%{YEAR}-%{MONTHNUM}-%{MONTHDAY} LOG_TIME %{HOUR}:?%{MINUTE}(?::?%{SECOND}) CATALINALOG %{CATALINA_DATESTAMP:timestamp} # #TOMCATLOG %{LOG_TIME:timestamp} %{THREAD:thread} TOMCATLOG %{TOMCAT_DATESTAMP:timestamp} |
启动 tomcat 日志代理:
./logstash -f tomcat.conf --verbose -l
../tomcat.log &
tomcat日志存入es
配置tomcat-es.conf
|
input { redis { host => 'redis.internal.173' data_type => 'list' port => "6379" key => 'usap' #type => 'redis-input' #codec => json } } output { # stdout { codec => rubydebug } elasticsearch { #host => "es1.internal.173,es2.internal.173,es3.internal.173" cluster => index => } } |
启动tomcat日志存储
./logstash -f tomcat-es.conf --verbose -l
../tomcat-es.log &
logstash接入nginx\syslog日志示例
logstash代理端配置nginx.conf
|
input { file{ type => "linux-syslog" path => [ "/var/log/*.log", } file { type => "nginx-access" path => } file { type => "nginx-error" path => } } output { # stdout{ codec => rubydebug } redis {host => "redis.internal.173" data_type => "list" } |
启动nginx日志代理
./logstash -f nginx.conf --verbose -l
../nginx.log &
nginx日志存入es
配置nginx-es.conf
|
input { redis { host => 'redis.internal.173' data_type => 'list' port => "6379" key => 'nginx' #type => 'redis-input' #codec => json } } filter { grok { type => "linux-syslog" pattern => "%{SYSLOGLINE}" } grok { type => "nginx-access" pattern => "%{IPORHOST:source_ip} - r} %{QS:http_user_agent}" } } output { # stdout { codec => rubydebug } elasticsearch { #host => "es1.internal.173,es2.internal.173,es3.internal.173" cluster => index => } } |
启动nginx日志存储
./logstash -f nginx-es.conf --verbose -l
../nginx-es.log &
分布式实时日志处理平台ELK的更多相关文章
- 分布式实时日志分析解决方案ELK部署架构
一.概述 ELK 已经成为目前最流行的集中式日志解决方案,它主要是由Beats.Logstash.Elasticsearch.Kibana等组件组成,来共同完成实时日志的收集,存储,展示等一站式的解决 ...
- ELK实时日志分析平台环境部署--完整记录
在日常运维工作中,对于系统和业务日志的处理尤为重要.今天,在这里分享一下自己部署的ELK(+Redis)-开源实时日志分析平台的记录过程(仅依据本人的实际操作为例说明,如有误述,敬请指出)~ ==== ...
- ELK实时日志分析平台环境部署--完整记录(转)
在日常运维工作中,对于系统和业务日志的处理尤为重要.今天,在这里分享一下自己部署的ELK(+Redis)-开源实时日志分析平台的记录过程(仅依据本人的实际操作为例说明,如有误述,敬请指出)~ ==== ...
- asp.net core结合NLog搭建ELK实时日志分析平台
0.整体架构 整体架构目录:ASP.NET Core分布式项目实战-目录 一.介绍ELK 1.说明(此篇ELK采用rpm的方式安装在服务器上)-牛刀小试 承接上一篇文章的内容准备部署ELK来展示asp ...
- ELK搭建实时日志分析平台
ELK搭建实时日志分析平台 导言 ELK由ElasticSearch.Logstash和Kiabana三个开源工具组成,ELK平台可以同时实现日志收集.日志搜索和日志分析的功能.对于生产环境中海量日志 ...
- ELK搭建实时日志分析平台之二Logstash和Kibana搭建
本文书接前回<ELK搭建实时日志分析平台之一ElasticSearch> 文:铁乐与猫 四.安装Logstash logstash是一个数据分析软件,主要目的是分析log日志. 1)下载和 ...
- ELK搭建实时日志分析平台之一ElasticSearch搭建
文:铁乐与猫 系统:CentOS Linux release 7.3.1611 (Core) 注:我这里为测试和实验方便,ELK整套都装在同一台服务器环境中了,生产环境的话,可以分开搭建在不同的服务器 ...
- 手把手教你搭建 ELK 实时日志分析平台
本篇文章主要是手把手教你搭建 ELK 实时日志分析平台,那么,ELK 到底是什么呢? ELK 是三个开源项目的首字母缩写,这三个项目分别是:Elasticsearch.Logstash 和 Kiban ...
- 集中式日志分析平台 - ELK Stack - 安全解决方案 X-Pack
大数据之心 关注 0.6 2017.02.22 15:36* 字数 2158 阅读 16457评论 7喜欢 9 简介 X-Pack 已经作为 Elastic 公司单独的产品线,前身是 Shield, ...
随机推荐
- 淘宝(阿里百川)手机客户端开发日记第六篇 Service详解(六)
Service和Thread的关系 不少初学者都可能会有这样的疑惑,Service和Thread到底有什么关系呢?什么时候应该用Service,什么时候又应该用Thread? 答案是Service和T ...
- HDU 4857 逃生 (优先队列+反向拓扑)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4857 解题报告:有n个点,有m个条件限制,限制是像这样的,输入a b,表示a必须排在b的前面,如果不 ...
- setVolumeControlStream(int streamType)
Android中有如下几种音频流: AudioManager.STREAM_MUSIC /** The audio stream for music playback */ AudioManager ...
- DICOM医学图像处理:storescp.exe与storescu.exe源码剖析,学习C-STORE请求
转载:http://blog.csdn.net/zssureqh/article/details/39213817 背景: 上一篇专栏博文中针对PACS终端(或设备终端,如CT设备)与RIS系统之间w ...
- 2014.7建兰NOIP模拟Day1 Running
突然间翻到着题,想想那时的我真是垃圾,这么简单的tarjan缩点+树上倍增都不会..还想了3h+.. 什么时候写了它吧...
- SSM框架Web程序的流程(Spring SpringMVC Mybatis)
SSM框架的Web程序主要用到了三个技术: Spring:用到了注解和自动装配,就是Spring的两个精髓IOC(反向控制)和 AOP(面向切面编程). SpringMVC:用到了MVC模型,将逻辑代 ...
- AWS AutoScaling
origin_from: http://blog.csdn.net/libing_thinking/article/details/48327189 AutoScaling 是 AWS 比较核心的一个 ...
- Ubuntu系统如何查看硬件配置信息
查看ubuntu硬件信息 1, 主板信息 .查看主板的序列号 -------------------------------------------------- #使用命令 dmidecode | ...
- MVC ViewBag和ViewData的区别
在MVC3开始,视图数据可以通过ViewBag属性访问,在MVC2中则是使用ViewData.MVC3中保留了ViewData的使用.ViewBag 是动态类型(dynamic),ViewData 是 ...
- 《ASP.NET1200例》<ItemTemplate>标签在html里面有什么具体的作用
严格的来说 <ItemTemplate> 在html中无意义,他只是针对诸如 Repeater.DataList.GridView中的一个模板 至于里面的含义,你可以这样想,既然Repea ...