ELK的安装和配置,简单演示监控tomcat日志记录
1.安装,地址
logstash:
https://www.elastic.co/products/logstash
elasticsearch:
https://www.elastic.co/products/elasticsearch
版本: logstash:
5.2.0 elasticsearch:
5.2.0 kibana:
5.2.0
环境:windows10
jdk:jdk8
2.配置
----logstash
1)logstash-5.2.0\bin目录下创建Logstash.conf文件,内容如下:
input {
file {
path => ["E:/apache-tomcat-7.0.55/logs/localhost_access_log.*.txt"]
start_position => "beginning"
}
}
filter {
date {
match => [ "timestamp" , "YYYY-MM-dd HH:mm:ss" ]
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
}
stdout {
codec => rubydebug
}
}
运行命令:logstash.bat -f logstash.conf
----elasticsearch
基本不用配置
运行命令 :elasticsearch.bat
地址:http://localhost:9200
----kibana
1)kibana\config目录下,修改kibana.yml文件,打开elasticsearch.url: "http://localhost:9200"
运行命令:kibana.bat
地址:http://localhost:5601
3.效果
4.注意事项
----需要jdk8
----elasticsearch的配置默认是2G,我的电脑配置比较低,如果不改的话,运行会报错,所以修改成512m,运行成功,详见附件1
----可以查询elasticsearch的index信息,浏览器输入:http://localhost:9200/_cat/indices?v
----kibana运行起来之后,需要先设置index,这里需要elasticsearch中有index,否则无法设置kibana的index。笔者就卡在这里很久,后来才找到原因,原来是logstash.conf中input的file属性中,path的值后缀应该是.txt,但是我写成了.log,导致logstash没有文件可以给elasticsearch,所以elasticsearch中没有index,进而使kibana无法设置index
附件
附件1:
修改elasticsearch默认配置,防止出现heap溢出,具体错误:
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap
1)elasticsearch\config目录下,修改jvm.options文件的22,23行,
由 -Xms2g
-Xmx2g
改成-Xms512m
-Xmx512m