下載 Elasticsearch仓技、Logstash颁湖、Kibana
官方地址:https://www.elastic.co/cn/products
cd? /usr/local
????wgethttps://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.1.tar.gz
????wget https://artifacts.elastic.co/downloads/logstash/logstash-5.6.1.tar.gz
????wget https://artifacts.elastic.co/downloads/kibana/kibana-5.6.1-linux-x86_64.tar.gz
tar? -zxvfelasticsearch-5.6.1.tar.gz
tar? -zxvf? logstash-5.6.1.tar.gz
tar? -zxvf? kibana-5.6.1-linux-x86_64.tar.gz
啟動(dòng)Elasticsearch
Elasticsearch不能使用root用戶運(yùn)行
useradd elk
sudo su - elk -c? "/usr/local/elasticsearch-5.6.1/bin/elasticsearch"
驗(yàn)證:curlhttp://localhost:9200
啟動(dòng)Logstash
創(chuàng)建配置文件logstash.conf 聲明輸入-input與輸出-output、及文件格式定義-filter
參考:
input {
? ? ? ? beats {
? ? ? ? ? ? ? ? port => 5044
? ? ? ? }
}
output {
? ? ? ? stdout {
? ? ? ? ? ? ? ? codec => rubydebug
? ? ? ? }
? ? ? ? elasticsearch {
? ? ? ? ? ? ? ? hosts => ["192.168.12.235:9200"]
? ? ? ? }
}
啟動(dòng):/usr/local/logstash/bin/logstash? -f? ./logstash.conf
啟動(dòng)Kibana
/usr/local/kibana/bin/kibana
驗(yàn)證:curlhttp://localhost:5601
至此安裝完畢搁胆,具體配置需要在特定的場(chǎng)景進(jìn)行調(diào)整弥搞。
心得:ELK 主要的作用是將日志 標(biāo)準(zhǔn)化邮绿、集中化,最終達(dá)到可視化的效果攀例。
????????搭建極其簡(jiǎn)單船逮,最要的是在配置,整體的規(guī)劃架構(gòu)粤铭。
????????配置的影響: ? ? 例如對(duì)Nginx日志不做處理的挖胃,只能起到日志集中化的作用。傳輸過(guò)來(lái)的日志信息全部被一個(gè)message變量標(biāo)識(shí)著梆惯,無(wú)法去區(qū)分其中的細(xì)節(jié)酱鸭,包括源IP、訪問(wèn)頁(yè)面垛吗、狀態(tài)碼等凹髓。數(shù)據(jù)呈現(xiàn)可視化的效果也將極差。所以需要在日志產(chǎn)生時(shí)就定義其格式怯屉,并在Logstash收集處定義傳輸輸出的日志格式(如源IP蔚舀、訪問(wèn)頁(yè)面、狀態(tài)碼都用變量定義起來(lái))蚀之,再將日志數(shù)據(jù)傳輸Elasticsearch蝗敢。最終在Kibana中對(duì)這些數(shù)據(jù)做可視化。
????????整體規(guī)劃的影響:產(chǎn)品的用戶上一定規(guī)模時(shí)足删,對(duì)服務(wù)端(Elasticsearch及Kibana)收集日子的能力將是一個(gè)非常大的考驗(yàn)寿谴。其中包括抗并發(fā)、日子處理等失受⊙忍可適當(dāng)在中間層級(jí)引進(jìn)緩存技術(shù),也可采取分布式的結(jié)構(gòu)的減少這一壓力拂到。
學(xué)習(xí)資料:https://kibana.logstash.es/content/