環境 : 一臺 centos 6.7 IP地址:192.168.88.250php
軟件版本 : ElasticSearch 2.1.0 Logstash 2.1.1 Kibana 4.3.1 JDK 1.8.0.77html
JDK 我這裏沒有地址 就不鏈接了 下載好JDK 放在路徑/usr/local/java編輯配置文件 /etc/profilejava
export JAVA_HOME=/usr/local/java/jdk1.8.0_77linux
export PATH=$JAVA_HOME/bin:$PATHnginx
加入這兩句之後 而後 source /etc/profile web
確認生效 java -versionshell
[root@master ~]# java -versionjson
java version "1.8.0_77"vim
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)centos
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
一、 搭建 ElasticSearch
wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.1.0/elasticsearch-2.1.0.tar.gz tar xf elasticsearch-2.1.0.tar.gz cd /usr/local/elasticsearch-2.1.0/bin ./plugin -install mobz/elasticsearch-head # web集羣管理插件 安裝好了之後能夠在plugin文件發現多了一個head ./elasticsearch -Des.insecure.allow.root=true #加這個參數才能夠root啓動 curl -X GET 192.168.88.250:9200 #curl 測試 { "name" : "Reeva Payge", "cluster_name" : "elasticsearch", "version" : { "number" : "2.1.0", "build_hash" : "72cd1f1a3eee09505e036106146dc1949dc5dc87", "build_timestamp" : "2015-11-18T22:40:03Z", "build_snapshot" : false, "lucene_version" : "5.3.1" }, "tagline" : "You Know, for Search" } web地址 http://192.168.88.250:9200/_plugin/head/
二、搭建NGINX
wget 搭建nginx以前須要安裝 pcre tar xf nginx-1.7.8.tar.gz cd /usr/local/nginx vim /usr/local/nginx/conf/nginx.conf #user nobody; worker_processes 1; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { upstream kibana4 { #對Kibana作代理 server 127.0.0.1:5601 fail_timeout=0; } include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; log_format json '{"@timestamp":"$time_iso8601",' #配置NGINX的日誌格式 json '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"responsetime":$request_time,' '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' '"http_host":"$host",' '"url":"$uri",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"agent":"$http_user_agent",' '"status":"$status"}'; access_log /var/log/nginx/access.log_json json; #配置日誌路徑 json格式 error_log /var/log/nginx/error.log; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} server { listen *:80; server_name kibana_server; access_log /var/log/nginx/kibana.srv-log-dev.log; error_log /var/log/nginx/kibana.srv-log-dev.error.log; location / { root /var/www/kibana; index index.html index.htm; } location ~ ^/kibana4/.* { proxy_pass http://kibana4; rewrite ^/kibana4/(.*) /$1 break; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; auth_basic "Restricted"; auth_basic_user_file /etc/nginx/conf.d/kibana.myhost.org.htpasswd; } } }
三、搭建 Logstash
wget https://download.elastic.co/logstash/logstash/logstash-2.1.1.tar.gz tar xf logstash-2.1.1.tar.gz cd /usr/local/logstash-2.1.1/bin vim stdin.conf #編寫配置文件 input{ file { path => "/var/log/nginx/access.log_json" #NGINX日誌地址 json格式 codec => "json" json編碼 } } filter { mutate { split => ["upstreamtime", ","] } mutate { convert => ["upstreamtime", "float"] } } output{ elasticsearch { hosts => ["192.168.88.250:9200"] #elasticsearch地址 index => "logstash-%{type}-%{+YYYY.MM.dd}" #索引 document_type => "%{type}" workers => 1 flush_size => 20000 #傳輸數量 默認500 idle_flush_time => 10 #傳輸秒數 默認1秒 template_overwrite => true } } ./logstash -f stdin.conf & #後臺啓動 啓動成功之後 打開剛纔搭建的web服務器 es就能看到數據
四、搭建Kibana
wget https://download.elastic.co/kibana/kibana/kibana-4.3.1-linux-x64.tar.gz tar xf kibana-4.3.1-linux-x64.tar.gz cd /usr/local/kibana-4.3.1-linux-x64/ vim ./config/kibana.yml elasticsearch.url: " 只須要修改URL爲ElasticSearch的IP地址 ./kibana & 後臺啓動 啓動成功之後 會監聽 5601端口
所有搭建好了之後就能夠用Kibana查看
地址 : 192.168.88.250:5601
若是create灰色的 說明沒有建立索引 打開你的nginx服務器 刷新幾下 採集一下數據
而後 選擇 左上角的 Discover
數據可能會出不來 那是由於 Kibana 是根據時間來匹配的 而且 由於 Logstash的採集時間使用的UTC 永遠早8個小時
因此設置時間 要設置晚8個小時之後
設置好了時間之後 。數據基本就會看的到
這裏能夠設置你想看到的任意 數據 選擇 add 就能看到的 不想看 能夠remove
還有後面的 Visualize 也能夠個性化定製圖標
基本就到此結束了,另外若是 Kibana出不來數據 通常都是由於時間設置不正確。