1、前言
在快速搭建完各個(gè)組件之后,我們將這幾個(gè)組件串起來搭建一個(gè)簡(jiǎn)單的ELK日志收集系統(tǒng)。本案例以收集一個(gè)springboot的web項(xiàng)目日志作為demo來演示ELK的應(yīng)用場(chǎng)景。
2、ELK流程調(diào)試
2.1、啟動(dòng)Elasticstarch并驗(yàn)證
通過curl命令去驗(yàn)證
[root@test-l27-14-70 ~]# curl http://localhost:9200
{
"name" : "RVNfQjd",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "myUulbUOROS2gqnQcZA-bA",
"version" : {
"number" : "6.2.3",
"build_hash" : "c59ff00",
"build_date" : "2018-03-13T10:06:29.741383Z",
"build_snapshot" : false,
"lucene_version" : "7.2.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
You have new mail in /var/spool/mail/root
[root@test-l27-14-70 ~]#
2.2、啟動(dòng)kibana并驗(yàn)證
nohup ./kibana &

image.png
2.3、配置我們web項(xiàng)目的日志輸出路徑并啟動(dòng)
我們配置了springboot項(xiàng)目的日志輸出路徑并啟動(dòng)
#log配置
logging.path=/usr/local/logs
logging.level.org=INFO
logging.level.com=INFO

image.png
[root@test-l27-14-70 logs]# pwd
/usr/local/logs
[root@test-l27-14-70 logs]# ll
total 128
-rw-r--r-- 1 root root 98310 Aug 12 14:39 spring.log
[root@test-l27-14-70 logs]#
我們啟動(dòng)了web項(xiàng)目,并能看到日志記錄存放到了指定的/usr/local/logs目錄之下
2.4、書寫logstash啟動(dòng)配置并啟動(dòng)對(duì)日志文件的監(jiān)聽
首先,我們logstash的監(jiān)聽問題是/usr/local/log/目錄下的日志文件
其次,我們要把監(jiān)聽到的日志信息寫到我們已經(jīng)準(zhǔn)備好的elasticsearch機(jī)器上去
明白以上兩點(diǎn),我們來書寫logstash的啟動(dòng)配置 web-elk.conf
#輸入
input{
file{
path => "/usr/local/logs/*.log"
}
}
#過濾器
filter{}
#輸出
output{
elasticsearch{
hosts=>["127.0.0.1:9200"]
index => "rc-admin-business-log" #要輸入的elasticsearch的索引,沒有會(huì)自建
}
#并打印到控制臺(tái)
stdout{codec => rubydebug}
}
有了以上啟動(dòng)文件,我們?cè)賮韱?dòng)我們的logstash,鍵入命令:./logstash -f ./web-elk.conf

image.png
我們可以看到logstash的控制臺(tái)已經(jīng)打印出部分日志,剩下的我們就去kibana上看看有沒有進(jìn)elasticsearch呢!

image.png
最終,我們可以在kibana上正常查詢到我們的項(xiàng)目日志。這樣一套簡(jiǎn)單的ELK就搭建完成了。