開源實時日志分析 ELK 平臺能夠完美的解決我們上述的問題, ELK 由 ElasticSearch 、 Logstash 和 Kiabana 三個開源工具組成。官方網(wǎng)站: https://www.elastic.co/products
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:空間域名、網(wǎng)絡(luò)空間、營銷軟件、網(wǎng)站建設(shè)、彌渡網(wǎng)站維護、網(wǎng)站推廣。
l Elasticsearch 是個開源分布式搜索引擎,它的特點有:分布式,零配置,自動發(fā)現(xiàn),索引自動分片,索引副本機制, restful 風格接口,多數(shù)據(jù)源,自動搜索負載等。
l Logstash 是一個完全開源的工具,他可以對你的日志進行收集、分析,并將其存儲供以后使用(如,搜索)。
l kibana 也是一個開源和免費的工具,他 Kibana 可以為 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以幫助您匯總、分析和搜索重要數(shù)據(jù)日志。
工作原理如下如所示:
開源實時日志分析ELK平臺部署流程:
( 1 )安裝 Logstash 依賴包 JDK
Logstash 的運行依賴于 Java 運行環(huán)境, Logstash 1.5 以上版本不低于 java 7 推薦使用最新版本的 Java 。由于我們只是運行 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 只需將它解壓的對應(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 后,解壓到對應(yīng)的目錄就完成 Elasticsearch 的安裝。
# tar -zxf elasticsearch-1.6.0.tar.gz -C /usr/local/
啟動 Elasticsearch
# /usr/local/elasticsearch-1.6.0/bin/elasticsearch
如果使用遠程連接的 Linux 的方式并想后臺運行 elasticsearch 執(zhí)行如下命令:
# nohup /usr/local/elasticsearch-1.6.0/bin/elasticsearch >nohup &
確認 elasticsearch 的 9200 端口已監(jiān)聽,說明 elasticsearch 已成功運行
# 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 后,解壓到對應(yīng)的目錄就完成 kibana 的安裝
# tar -zxf kibana-4.1.1-linux-x64.tar.gz -C /usr/local/
啟動 kibana
# /usr/local/kibana-4.1.1-linux-x64/bin/kibana
使用 http://kibanaServerIP : 5601 訪問 Kibana ,登錄后,首先,配置一個索引,默認, Kibana 的數(shù)據(jù)被指向 Elasticsearch ,使用默認的 logstash-* 的索引名稱,并且是基于時間的,點擊“ 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
效果如圖:
新聞標題:ELK分析nginx日志
分享地址:http://muchs.cn/article44/gdohee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、靜態(tài)網(wǎng)站、搜索引擎優(yōu)化、企業(yè)網(wǎng)站制作、品牌網(wǎng)站制作、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)