開源實(shí)時(shí)日志分析 ELK 平臺(tái)能夠完美的解決我們上述的問題, ELK 由 ElasticSearch 、 Logstash 和 Kiabana 三個(gè)開源工具組成。官方網(wǎng)站: https://www.elastic.co/products
雙流ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!l Elasticsearch 是個(gè)開源分布式搜索引擎,它的特點(diǎn)有:分布式,零配置,自動(dòng)發(fā)現(xiàn),索引自動(dòng)分片,索引副本機(jī)制, restful 風(fēng)格接口,多數(shù)據(jù)源,自動(dòng)搜索負(fù)載等。
l Logstash 是一個(gè)完全開源的工具,他可以對(duì)你的日志進(jìn)行收集、分析,并將其存儲(chǔ)供以后使用(如,搜索)。
l kibana 也是一個(gè)開源和免費(fèi)的工具,他 Kibana 可以為 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以幫助您匯總、分析和搜索重要數(shù)據(jù)日志。
工作原理如下如所示:
開源實(shí)時(shí)日志分析ELK平臺(tái)部署流程:
( 1 )安裝 Logstash 依賴包 JDK
Logstash 的運(yùn)行依賴于 Java 運(yùn)行環(huán)境, Logstash 1.5 以上版本不低于 java 7 推薦使用最新版本的 Java 。由于我們只是運(yùn)行 Java 程序,而不是開發(fā),下載 JRE 即可。首先,在 Oracle 官方下載新版 jre ,下載地址: http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
#wget http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.tar.gz# mkdir /usr/local/java # tar -zxf jdk-8u45-linux-x64.tar.gz -C /usr/local/java/# tail -3 ~/.bash_profileexport JAVA_HOME=/usr/local/java/jdk1.8.0_45export PATH=$PATH:$JAVA_HOME/binexportCLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH# java -version java version "1.8.0_45"Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02,mixed mode)( 2 )安裝 Logstash
下載并安裝 Logstash ,安裝 logstash 只需將它解壓的對(duì)應(yīng)目錄即可,例如: /usr/local 下:
# https://download.elastic.co/logstash/logstash/logstash-1.5.2.tar.gz# tar zxf logstash-1.5.2.tar.gz -C /usr/local/# /usr/local/logstash-1.5.2/bin/logstash -e 'input { stdin { } } output { stdout {} }' Logstash startup completed Hello World!2015-07-15T03:28:56.938Z noc.vfast.com Hello World!3 )安裝 Elasticsearch
下載 Elasticsearch 后,解壓到對(duì)應(yīng)的目錄就完成 Elasticsearch 的安裝。
# tar -zxf elasticsearch-1.6.0.tar.gz -C /usr/local/啟動(dòng) Elasticsearch
# /usr/local/elasticsearch-1.6.0/bin/elasticsearch如果使用遠(yuǎn)程連接的 Linux 的方式并想后臺(tái)運(yùn)行 elasticsearch 執(zhí)行如下命令:
# nohup /usr/local/elasticsearch-1.6.0/bin/elasticsearch >nohup &確認(rèn) elasticsearch 的 9200 端口已監(jiān)聽,說明 elasticsearch 已成功運(yùn)行
# netstat -anp |grep :9200tcp 0 0 :::9200 :::* LISTEN 3362/java# cat logstash-es-simple.confinput { stdin { } } output { elasticsearch {host => "localhost" } stdout { codec=> rubydebug } }執(zhí)行如下命令
# /usr/local/logstash-1.5.2/bin/logstash agent -f logstash-es-simple.conf… … Logstash startup completed hello logstash { "message" => "hello logstash", "@version" => "1", "@timestamp" => "2015-07-15T18:12:00.450Z", "host" => "noc.vfast.com"}# curl 'http://localhost:9200/_search?pretty'返回結(jié)果 { "took": 58, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits": { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "logstash-2015.07.15", "_type" : "logs", "_id" : "AU6TWiixxDXYhySMyTkP", "_score" : 1.0, "_source":{"message":"hellologstash","@version":"1","@timestamp":"2015-07-15T20:13:55.199Z","host":"noc.vfast.com"} } ] } }5 )安裝 Kibana
下載 kibana 后,解壓到對(duì)應(yīng)的目錄就完成 kibana 的安裝
# tar -zxf kibana-4.1.1-linux-x64.tar.gz -C /usr/local/啟動(dòng) kibana
# /usr/local/kibana-4.1.1-linux-x64/bin/kibana使用 http://kibanaServerIP : 5601 訪問 Kibana ,登錄后,首先,配置一個(gè)索引,默認(rèn), Kibana 的數(shù)據(jù)被指向 Elasticsearch ,使用默認(rèn)的 logstash-* 的索引名稱,并且是基于時(shí)間的,點(diǎn)擊“ Create ”即可。
至此,ELK環(huán)境部署完成
以下為分析nginx日志的配置:
定義nginx日志格式:
[root@vm10-100-0-5 logstash-1.5.2]# cat /etc/nginx/nginx.conf user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format logstashlog '$http_host ' '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent "$request_body" ' '"$http_referer" "$http_user_agent" "$http_x_forwarded_for" ' '$request_time '; access_log /var/log/nginx/access.log logstashlog; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include conf.d/*.conf; }[root@vm10-100-0-5 logstash-1.5.2]# cat logstash-nginx_log.conf input { file { path => [ "/var/log/nginx/access.log" ] start_position => "beginning" } } filter { grok { patterns_dir => ['/opt/logstash/patterns/'] match => { "message" => "%{NGINXACCESS}" } } geoip { source => "http_x_forwarded_for" target => "geoip" database => "/etc/logstash/GeoLiteCity.dat" add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ] add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ] } mutate { convert => [ "[geoip][coordinates]", "float" ] convert => [ "response","integer" ] convert => [ "bytes","integer" ] replace => { "type" => "nginx_access" } remove_field => "message" } date { match => [ "timestamp","dd/MMM/yyyy:HH:mm:ss Z"] } mutate { remove_field => "timestamp" } } output { elasticsearch { host => "localhost" index => "logstash-nginx-access-%{+YYYY.MM.dd}" } stdout {codec => rubydebug} }[root@vm10-100-0-5 logstash-1.5.2]# cat /opt/logstash/patterns/nginx URIPARAM1 \?[A-Za-z0-9$.+!*'|(){},~@#%&/=:;_?\-\[\]<>]* URIPARAM (?:%{URIPARAM1})? NGINXACCESS %{IPORHOST:http_host} %{IPORHOST:remote_addr} - %{USERNAME:remote_user} \[%{HTTPDATE:time_local}\] "%{WORD:method} %{URIPATH:request}%{URIPARAM:requestparam} HTTP/%{NUMBER:http_version}" %{INT:status} %{INT:body_bytes_sent} %{QS:request_body} %{QS:http_referer} %{QS:http_user_agent} %{QS:http_x_forwarded_for} %{NUMBER:request_time:float}# bin/logstash -f logstash-nginx_log.conf# bin/kibana效果如圖:
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
文章題目:ELK分析nginx日志-創(chuàng)新互聯(lián)
新聞來源:http://jinyejixie.com/article6/ccpdog.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、自適應(yīng)網(wǎng)站、網(wǎng)站導(dǎo)航、網(wǎng)站策劃、網(wǎng)站維護(hù)、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容