介绍
场景:生产环境可集中式分析特定日志,便于管理,以及快速解决程序问题等。
常见:nginx、apache的访问日志,错误日志 catalina.out日志等。可以把错误日志提取出并解决。
安装方式:
1)编译安装 常用组合 ELK+Reids+插件
1.1)优点:方便管理
1.2)缺点:需要手动安装配置,相对yum繁琐
2)yum安装
2.1)优点:安装配置方便
2.2)缺点:相对编译不太好管理(依赖关系等因素)
注意地方:
[root@elk config]# cat elasticsearch.yml|grep -v"$^"|grep -v "#"
cluster.name: elk
node.name: node1
network.host: 0.0.0.0
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
#elasticsearch配置允许跨域访问,这样head插件可以访问es。
#http.cors.enabled: true
#http.cors.allow-origin: "*"
kibana配置
[root@elk config]# cat kibana.yml |grep elasticsearch.url
#elasticsearch.url: “http://localhost:9200”
elasticsearch.url: “http://192.168.1.225:9200”
#url访问
logstash获取日志样板:(重点)
[root@elk config]# cat catalinalog.conf
input {
file {
path => "/usr/local/tomcat-7.x/logs/catalina.out" #tomcat的Catalina.out日志路径
start_position => "beginning"
}
}
filter {
if [path] =~ "access" {
mutate { replace => { "type" => "tomcat catalina.out" } }
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
}
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
}
output {
elasticsearch {
hosts => ["192.168.1.225:9200"] #elasticsearch地址
}
stdout { codec => rubydebug }
}
启动:logstash -f catalinalog.conf (测试)
kibana访问:
摘取tomcat最后启动成功状态日志:
January 11th 2017, 15:39:52.990path:/usr/local/tomcat-7.x/logs/catalina.out @timestamp:January 11th 2017, 15:39:52.990 @version:1 host:0.0.0.0 message:信息: Destroying ProtocolHandler ["ajp-bio-8009"] tags: _id:AVmMeAegJ7ojQvedm4_L _type:logs _index:logstash-2017.01.11 _score: -
January 11th 2017, 15:39:52.989path:/usr/local/tomcat-7.x/logs/catalina.out @timestamp:January 11th 2017, 15:39:52.989 @version:1 host:0.0.0.0 message:信息: Stopping ProtocolHandler ["ajp-bio-8009"] tags: _id:AVmMeAegJ7ojQvedm4_H _type:logs _index:logstash-2017.01.11 _score: -
January 11th 2017, 15:39:52.989path:/usr/local/tomcat-7.x/logs/catalina.out @timestamp:January 11th 2017, 15:39:52.989 @version:1 host:0.0.0.0 message:信息: Stopping ProtocolHandler ["http-bio-80"] tags: _id:AVmMeAegJ7ojQvedm4_F _type:logs _index:logstash-2017.01.11 _score: -
参考链接 :
ELK分析tomcat的Catalina.out日志 :https://blog.51cto.com/iyull/1892522