聲明:原創(chuàng)文章,轉(zhuǎn)載請注明出處。http://www.reibang.com/u/e02df63eaa87
1、Logstash使用
Logstash是一個(gè)完全開源的工具,他可以對你的日志進(jìn)行收集萎攒、分析,并將其存儲供以后使用矛绘。
1.1 Logstash安裝(JDK 1.8環(huán)境下)
下載Logstash 2.3.4耍休,并解壓。
1.2 Logstash配置
配置logstash.conf
input {
file {
type => "log-file"
path => "/root/test/log/log.log"
}
}
output {
stdout {
codec => rubydebug
}
}
其中input
為Logstash的輸入源蔑歌,當(dāng)前配置是監(jiān)控root/test/log/log.log
文件羹应,并將該日志類型置為log-file
。
其中output
為Logstash的輸出源次屠,當(dāng)前配置為直接輸出到終端园匹。
1.3 Logstash啟動
./bin/logstash -f logstash.conf
1.4 Logstash使用
- 首先啟動Logstash服務(wù)
- 啟動打印日志的程序,并將日志輸出到
root/test/log/log.log
- 觀察Logstash終端的輸出劫灶,可以看到Logstash抓取到了監(jiān)控路徑下的日志裸违,并進(jìn)行處理和輸出。
{
"message" => "[INFO][uid:1491031249][name:Gloria Harrison][ip:36.59.236.198][date:2017-04-01T15:20:49.703+0800]",
"@version" => "1",
"@timestamp" => "2017-04-01T07:20:50.644Z",
"path" => "/root/test/log/log.log",
"host" => "0.0.0.0",
"type" => "log-file"
}
{
"message" => "[INFO][uid:14910312497][name:Ralph Martinez][ip:36.58.103.37][date:2017-04-01T15:20:49.704+0800]",
"@version" => "1",
"@timestamp" => "2017-04-01T07:20:50.645Z",
"path" => "/root/test/log/log.log",
"host" => "0.0.0.0",
"type" => "log-file"
}
2本昏、Elasticsearch使用
ElasticSearch是一個(gè)基于Lucene的搜索服務(wù)器供汛。它提供了一個(gè)分布式多用戶能力的全文搜索引擎,基于RESTful web接口涌穆。Elasticsearch是用Java開發(fā)的怔昨,并作為Apache許可條款下的開放源碼發(fā)布,是當(dāng)前流行的企業(yè)級搜索引擎宿稀。設(shè)計(jì)用于云計(jì)算中趁舀,能夠達(dá)到實(shí)時(shí)搜索,穩(wěn)定祝沸,可靠矮烹,快速,安裝使用方便罩锐。
2.1 Elasticsearch安裝(JDK 1.8環(huán)境下)
下載elasticsearch 2.3.4奉狈,并解壓。
2.2 Elasticsearch配置
配置config/elasticsearch.yml
# host設(shè)置
network.host: 172.17.203.210
2.3 Elasticsearch常用插件安裝
- head :是集群管理工具涩惑、數(shù)據(jù)可視化仁期、增刪改查工具。
# 安裝命令
./bin/plugin install mobz/elasticsearch-head
訪問路徑:http://localhost:9200/_plugin/head/
- kopf:是一個(gè)ElasticSearch的管理工具,它也提供了對ES集群操作的API蟀拷。
# 安裝命令
./bin/plugin install lmenezes/elasticsearch-kopf
訪問路徑:http://localhost:9200/_plugin/kopf/
- hq:對于ElasticSearch實(shí)例和集群進(jìn)行監(jiān)視和管理Web應(yīng)用程序碰纬。
# 安裝命令
./bin/plugin install royrusso/elasticsearch-HQ
訪問路徑:http://localhost:9200/_plugin/hq/
2.4 Elasticsearch啟動
./bin/elasticsearch -d -p pid
2.5 Elasticsearch使用
- HQ插件
3、Kibana使用
Kibana 也是一個(gè)開源和免費(fèi)的工具问芬,他可以幫助您匯總、分析和搜索重要數(shù)據(jù)日志并提供友好的web界面寿桨。他可以為 Logstash 和 ElasticSearch 提供的日志分析的 Web 界面此衅。
logstash index將日志收集在一起交給全文搜索服務(wù)ElasticSearch,可以用ElasticSearch進(jìn)行自定義搜索亭螟,通過Kibana 來結(jié)合自定義搜索進(jìn)行頁面展示挡鞍。
3.1 Kibana安裝(JDK 1.8環(huán)境)
下載kibana 4.5.2,并解壓预烙。
3.2 Kibana配置
# Kibana is served by a back end server. This controls which port to use. Web界面的端口號
port: 5601
# The host to bind the server to. Web訪問的host
host: "127.0.0.1"
# The Elasticsearch instance to use for all your queries. ES的訪問路徑
elasticsearch_url: elasticsearch.url: "http://127.0.0.1:9200"
3.3 Kibana啟動
nohup ./bin/kibana &
3.4 Kibana使用
3.4.1 訪問Kibana地址
127.0.0.1:5601
3.4.2 創(chuàng)建index pattern
- Index contains time-based events:ES索引帶有時(shí)間列
-
Use event times to create index names
如果這2個(gè)都不選的情況下墨微,可以直接添加ES的索引名字。