共计 2715 个字符,预计需要花费 7 分钟才能阅读完成。
场景:生产环境可集中式分析特定日志,便于管理,以及快速解决程序问题等。
常见:nginx、apache 的访问日志,错误日志 catalina.out 日志等。可以把错误日志提取出并解决。
安装方式:
1)编译安装 常用组合 ELK+Reids+ 插件
1.1)优点:方便管理
1.2)缺点:需要手动安装配置,相对 yum 繁琐
2)yum 安装
2.1)优点:安装配置方便
2.2)缺点:相对编译不太好管理(依赖关系等因素)
——————————————————————————–
My eg:
注意事项:elk 安装比较简单,但是要注意最低配置。这里我个人用的是编译安装,并且自己写的脚本。yum 安装脚本可直接用。
[root@elk config]# /etc/init.d/node-elasticsearch status
node(elasticsearch) is running…
[root@elk config]# /etc/init.d/elasticsearch status
elasticsearch is already running…
[root@elk config]# Java -version
java version “1.8.0_112”
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
[root@elk config]# /etc/init.d/kibana status
kibana is running…
[root@elk config]#
注意地方:
elasticsearch.yml:
[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: “*”
[root@elk config]#
#elasticsearch 配置允许跨域访问,这样 head 插件可以访问 es。
#http.cors.enabled: true
#http.cors.allow-origin: “*”
kibana.yml:
[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]#
[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}
}
[root@elk config]#
启动: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: –
基于 CentOS 6.9 搭建 ELK 环境指南 http://www.linuxidc.com/Linux/2017-07/145636.htm
Linux 日志分析 ELK 环境搭建 http://www.linuxidc.com/Linux/2017-07/145494.htm
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-09/146994.htm