ELK5.X搭建並收集Nginx日誌

ELK5.X搭建並收集Nginx日誌

ELK

 

本文轉載https://www.i4t.com

 


ELK Stack 是 Elasticsearch、Logstash、Kibana 三個開源軟件的組合。在實時數據檢索和分析場合,三者通常是配合共用,而且又都先後歸於 Elastic.co 公司名下,故有此簡稱。

ELK Stack 在最近兩年迅速崛起,成爲機器數據分析,或者說實時日誌處理領域,開源界的第一選擇。和傳統的日誌處理方案相比,ELK Stack 具有如下幾個優點:

• 處理方式靈活。Elasticsearch 是實時全文索引,不需要像 storm 那樣預先編程才能使用;
• 配置簡易上手。Elasticsearch 全部採用 JSON 接口,Logstash 是 Ruby DSL 設計,都是目前業界最通用的配置語法設計;
• 檢索性能高效。雖然每次查詢都是實時計算,但是優秀的設計和實現基本可以達到全天數據查詢的秒級響應;
• 集羣線性擴展。不管是 Elasticsearch 集羣還是 Logstash 集羣都是可以線性擴展的;
• 前端操作炫麗。Kibana 界面上,只需要點擊鼠標,就可以完成搜索、聚合功能,生成炫麗的儀表板。

ELK地址:https://www.elastic.co/
Logstash 最佳實踐:http://udn.yyuap.com/doc/logstash-best-practice-cn/index.html
Elasticsearch 權威指南:http://www.learnes.net/index.html
ELKStack中文社區:https://kibana.logstash.es/content/
更多ELK文章:https://www.i4t.com/category/elkstack/

 

  對於日誌來說,最常見的需求就是收集、存儲、查詢、展示,開源社區正好有相對應的開源項目:logstash(收集)、elasticsearch(存儲+搜索)、kibana(展示),我們將這三個組合起來的技術稱之爲ELKStack,所以說ELKStack指的是Elasticsearch(java)、Logstash(jruby)、Kibana技術棧的結合,一個通 用的架構如下圖所示:
image_1d3o2hl6ltsp1gnk1p1c13nnvalm.png-136.7kB
圖片解釋:elk 前面主要靠logstash來進行收集日誌,logstash將日誌上傳到broker上,後面還有一個logstash用來讀取broker中的日誌,在將日誌存儲到es裏面,最後用kibana練到es上進行展示

提示:我們可以將Elasticsearch簡稱爲es

1.Elasticsearch介紹
ElasticSearch是一個基於Lucene的搜索服務器。它提供了一個分佈式多用戶能力的全文搜索引擎,基於RESTful web接口。Elasticsearch是用Java開發的,並作爲Apache許可條款下的開放源碼發佈,是第二流行的企業搜索引擎。設計用於雲計算中,能夠達到實時搜索,穩定,可靠,快速,安裝使用方便。

2.Logstash介紹

Logstash是一個完全開源的工具,他可以對你的日誌進行收集、分析,並將其存儲供以後使用(如,搜索),您可以使用它。說到搜索,logstash帶有一個web界面,搜索和展示所有日誌。
  kibana也是一個開源和免費的工具,他可以幫助您彙總、分析和搜索重要數據日誌並提供友好的web界面。他可以爲 Logstash 和 ElasticSearch 提供的日誌分析的 Web 界面。

提示:logstash與es沒有任何關係
image_1d3o2ia8t8m11sbn16ouotv11pc13.png-68.9kB

ELK幾個概念


 
  1. INPUT 進
  2. FILTER (支持過濾的功能)
  3. OUTPUT 出

33333333.png-43.3kB
首先LogStash是收集日誌,它收集完日誌就需要把日誌存儲下來,所以我們可以用運輸者的身份來表示LogStash(INPUT or OUTPUT)LogStash可以在日誌發送之前做一個過濾(OUTPUT之前)

3.Kibana簡介
Kibana是爲 Elasticsearch 設計的開源分析和可視化平臺。你可以使用 Kibana 來搜索,查看存儲在 Elasticsearch 索引中的數據並與之交互。你可以很容易實現高級的數據分析和可視化,以圖表的形式展現出來。

Kibana版本使用php、ruby、js、jruby、node.js等不同語言編寫
Kibana 4使用nodejs進行編寫(nodejs號稱全棧,什麼都可以幹)

本段文章截取https://www.i4t.com/category/elkstack/


image_1d3o2gruh4h11npj9akfs0kq59.png-96.2kB

溫馨提示:本次搭建屬於單點,不算是集羣。集羣搭建只需要改相關的配置文件重啓即可

環境 CentOS Linux release 7.4.1708 (Core)
版本 
elasticsearch-5.5.0.tar.gz
kibana-5.5.0-linux-x86_64.tar.gz
logstash-5.5.0.tar.gz

主機
10.4.11.11   Elasticsearch  Kibana
10.4.11.12   logstash nginx
如果Nginx和elk都在一臺,可以都安裝在一臺服務器上!


環境配置
#時間同步
#關閉selinux 及防火牆
#內核優化

一、基礎環境配置及軟件包下載


 
  1. 1.設置yum源
  2. curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  3. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  4. yum makecache
  5. yum install wget vim lsof net-tools lrzsz -y
  6.  
  7.  
  8. 2.時間同步
  9. yum -y install ntp
  10. systemctl enable ntpd
  11. systemctl start ntpd
  12. ntpdate -u cn.pool.ntp.org
  13. hwclock --systohc
  14. timedatectl set-timezone Asia/Shanghai
  15.  
  16. 3.關閉Selinux && 防火牆
  17. systemctl stop firewalld
  18. systemctl disable firewalld
  19. setenforce 0
  20. sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
  21.  
  22. 4.內核優化
  23. echo '
  24. * hard nofile 65536
  25. * soft nofile 65536
  26. * soft nproc 65536
  27. * hard nproc 65536
  28. '>>/etc/security/limit.conf
  29. echo '
  30. vm.max_map_count = 262144
  31. net.core.somaxconn=65535
  32. net.ipv4.ip_forward = 1
  33. '>>/etc/sysctl.conf
  34. sysctl -p

下載軟件包


 
  1. mkdir /root/elk
  2.  
  3. Elasticsearch:
  4. wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.tar.gz
  5. Kibana:
  6. wget https://artifacts.elastic.co/downloads/kibana/kibana-5.5.0-linux-x86_64.tar.gz
  7. Logstash:
  8. wget https://artifacts.elastic.co/downloads/logstash/logstash-5.5.0.tar.gz

安裝Jdk環境


 
  1. 1.源碼安裝
  2.  
  3. 下載安裝http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  4. 配置Java環境
  5. tar zxf jdk-8u91-linux-x64.tar.gz -C /usr/local/
  6. ln –s /usr/local/jdk1.8.0_91 /usr/local/jdk
  7.  
  8. vim /etc/profile
  9. export JAVA_HOME=/usr/local/jdk
  10. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  11. export PATH=$JAVA_HOME/bin:$PATH
  12.  
  13. source /etc/profile
  14.  
  15. 看到如下信息,java環境配置成功
  16. # java -version
  17. java version "1.8.0_91"
  18. Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
  19. Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
  20.  
  21. 2.yum安裝
  22. yum install -y java
  23.  
  24. [[email protected] ~]# java -version
  25. openjdk version "1.8.0_65"
  26. OpenJDK Runtime Environment (build 1.8.0_65-b17)
  27. OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)

二、安裝Elasticsearch

我們elk都使用普通用戶進行啓動管理


 
  1. 新建持久化目錄及logo目錄
  2. mkdir /data1/{es-data,es-logs} -p
  3. tar xf elasticsearch-5.5.0.tar.gz -C /usr/local/
  4. ln -s /usr/local/elasticsearch-5.5.0 /usr/local/elasticsearch
  5.  
  6. 修改配置文件,修改後如下
  7. grep -Ev "^$|#" /usr/local/elasticsearch-5.5.0/config/elasticsearch.yml
  8. node.name: my-es
  9. path.data: /data1/es-data
  10. path.logs: /data1/es-logs
  11. config.reload.automatic: true
  12. config.reload.interval: 10
  13. http.host: "10.4.82.217"
  14. http.cors.enabled: true
  15. http.cors.allow-origin: "*"
  16.  
  17.  
  18. 配置說明
  19. node.name: my-es #設置節點名稱,一般寫主機名
  20. path.data: /data1/es-data #創建logstash 和插件使用的持久化目錄
  21. path.logs: /data1/es-logs #創建es日誌路徑
  22. config.reload.automatic: true #開啓配置文件自動加載
  23. config.reload.interval: 10 #定義配置文件重載時間週期
  24. http.host: "10.4.82.217" #定義訪問主機名,一般爲域名或IP
  25. http.cors.enabled: true #使用head插件需要開啓
  26. http.cors.allow-origin: "*"
  27.  
  28. 更多配置說明:https://blog.csdn.net/ma_shou_feng/article/details/83783213

在運行es之前,我們需要創建用戶,設置屬主屬組


 
  1. useradd elk
  2. chown -R elk /data1/es-*
  3.  
  4. [[email protected] ~]# ll /data1/
  5. 總用量 32
  6. drwxr-xr-x 2 elk root 4096 1月 25 04:48 es-data
  7. drwxr-xr-x 2 elk root 4096 1月 25 04:48 es-logs
  8. drwxr-xr-x 3 root root 4096 8月 24 20:17 etcd
  9. drwxr-xr-x 2 root root 4096 8月 16 11:41 kubelet
  10. drwx------. 2 root root 16384 7月 13 2018 lost+found
  11.  
  12. 設置es服務
  13. chown -R elk /usr/local/elasticsearch-5.5.0/
  14. [[email protected] local]# ll /usr/local/elasticsearch-5.5.0/
  15. 總用量 236
  16. drwxr-xr-x 2 elk root 4096 1月 25 04:49 bin
  17. drwxr-xr-x 2 elk root 4096 1月 25 04:54 config
  18. drwxr-xr-x 2 elk root 4096 7月 1 2017 lib
  19. -rw-r--r-- 1 elk root 11358 7月 1 2017 LICENSE.txt
  20. drwxr-xr-x 13 elk root 4096 7月 1 2017 modules
  21. -rw-r--r-- 1 elk root 194187 7月 1 2017 NOTICE.txt
  22. drwxr-xr-x 2 elk root 4096 7月 1 2017 plugins
  23. -rw-r--r-- 1 elk root 9548 7月 1 2017 README.textile

啓動es服務


 
  1. 啓動之前需要su到普通用戶上
  2. [[email protected] ~]# su - elk
  3. [[email protected] ~]$ /usr/local/elasticsearch/bin/elasticsearch -d
  4.  
  5. # -d 參數爲後臺啓動,第一次安裝好可以不加-d先啓動測試,查看是否有error或者報錯

前臺查看啓動成功,我們就可以加上-d參數讓它後臺運行
image_1d20s2rd61q2545o1fnn175r1bn39.png-827.5kB

檢查是否啓動成功


 
  1. [elk@i4t ~]$ /usr/local/elasticsearch/bin/elasticsearch -d
  2. [elk@i4t~]$ lsof -i:9200
  3. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  4. java 7157 elk 312u IPv6 391237534 0t0 TCP node1:wap-wsp (LISTEN)
  5.  
  6. [elk@i4t ~]$ curl 10.4.82.217:9200
  7. {
  8. "name" : "my-es",
  9. "cluster_name" : "elasticsearch",
  10. "cluster_uuid" : "tXBJMwRhQUyPNrwKETCWgg",
  11. "version" : {
  12. "number" : "5.5.0",
  13. "build_hash" : "260387d",
  14. "build_date" : "2017-06-30T23:16:05.735Z",
  15. "build_snapshot" : false,
  16. "lucene_version" : "6.6.0"
  17. },
  18. "tagline" : "You Know, for Search"
  19. }

Elasticsearch常用命令


 
  1. curl -XDELETE 'http://host.IP.address:9200/logstash-*' 刪除索引(後面爲索引名稱)
  2. curl -XGET 'host.IP.address:9200/_cat/health?v&pretty' 查看集羣狀態
  3. curl -XGET 'host.IP.address:9200/_cat/indices?v&pretty' 查看索引

三、安裝logstash

logstash安裝的Nginx服務器上,並非es服務器


 
  1. 1.解壓安裝logstash
  2. tar xf logstash-5.5.0.tar.gz -C /usr/local/
  3. ln -s /usr/local/logstash-5.5.0 /usr/local/logstash
  4.  
  5. 2.創建配置文件
  6. mkdir /usr/local/logstash/conf/
  7. vim /usr/local/logstash/conf/nginx.conf
  8. input {
  9. file {
  10. path => "/usr/local/nginx/logs/access.log"
  11. start_position => "beginning"
  12. }
  13. }
  14. filter {
  15. }
  16. output {
  17. #stdout { codec=> rubydebug }
  18. elasticsearch {
  19. hosts => ["10.4.82.118:9200"]
  20. index => "static_nginx_access-%{+YYYY.MM.dd}"
  21. }
  22. }
  23.  
  24. #這裏面實際只是定義了一個nginx log路徑
  25. #stdout { codec=> rubydebug } 將內容打印出來,方便測試
  26. #host 填寫es主機
  27. index 索引名稱

四、安裝Kibana


 
  1. wget https://artifacts.elastic.co/downloads/kibana/kibana-5.5.0-linux-x86_64.tar.gz
  2. tar xf kibana-5.5.0-linux-x86_64.tar.gz -C /usr/local/
  3. chown -R elk.elk kibana-5.5.0-linux-x86_64
  4.  
  5. kibana配置文件修改
  6. [root@YZSJHL82-217 ~]# vim /usr/local/kibana-5.5.0-linux-x86_64/config/kibana.yml
  7. server.port: 5601
  8. server.host: "10.4.82.217"
  9. elasticsearch.url: "http://127.0.0.1:9200"
  10.  
  11.  
  12.  
  13. [root@YZSJHL82-217 ~]# grep -Ev "^$|#" /usr/local/kibana-5.5.0-linux-x86_64/config/kibana.yml
  14. server.port: 5601 #kibana端口
  15. server.host: "10.4.82.217" #kibana主機
  16. elasticsearch.url: "http://127.0.0.1:9200" #ES服務器端口
  17.  
  18. 啓動
  19. [root@YZSJHL82-217 ~]# su - elk
  20. 前臺啓動
  21. [elk@i4t kibana-5.5.0-linux-x86_64]$ /usr/local/kibana-5.5.0-linux-x86_64/bin/kibana
  22. 後臺啓動
  23. [elk@i4t kibana-5.5.0-linux-x86_64]$ /usr/local/kibana-5.5.0-linux-x86_64/bin/kibana &
  24.  
  25. 溫馨提示:可以先前臺啓動查看日誌,正常之後在後臺啓動
  26.  
  27.  
  28. 查看端口
  29. [root@i4t ~]# lsof -i:5601
  30. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  31. node 30297 elk 12u IPv4 420317733 0t0 TCP node1:esmagent (LISTEN)
  32. [root@i4t ~]# netstat -lntup|grep 5601
  33. tcp 0 0 10.4.82.217:5601 0.0.0.0:* LISTEN 30297/node

訪問kibana
http://ip:5601
123.png-492kB

因爲現在沒有數據,我們現在配置Nginx進行Nginx的日誌收集

五、安裝並配置Nginx收集日誌

安裝Nginx


 
  1. wget http://nginx.org/download/nginx-1.10.3.tar.gz
  2.  
  3. yum install -y gcc glibc gcc-c++ prce-devel openssl-devel pcre-devel
  4. useradd -s /sbin/nologin www -M
  5. tar xf nginx-1.10.3.tar.gz && cd nginx-1.10.3
  6.  
  7. ./configure --prefix=/usr/local/nginx-1.10.3 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
  8. make && make install
  9. ln -s /usr/local/nginx-1.10.3 /usr/local/nginx
  10.  
  11.  
  12.  
  13.  
  14. 手動啓動
  15. /usr/local/nginx/sbin/nginx
  16.  
  17. 設置開機啓動
  18. echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local
  19.  
  20.  
  21. 查看服務器是否啓動
  22. netstat -lntp|grep nginx
  23. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7058/nginx: master

需要配置在我們要收集的服務器上


 
  1. vim /usr/local/nginx/conf/nginx.conf
  2. worker_processes 1;
  3.  
  4. events {
  5. worker_connections 1024;
  6. }
  7.  
  8.  
  9. http {
  10. include mime.types;
  11. default_type application/octet-stream;
  12. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  13. # '$status $body_bytes_sent "$http_referer" '
  14. # '"$http_user_agent" "$http_x_forwarded_for"';
  15.  
  16. log_format json '{"@timestamp":"$time_iso8601",'
  17. '"host":"$server_addr",'
  18. '"clientip":"$remote_addr",'
  19. '"remote_user":"$remote_user",'
  20. '"request":"$request",'
  21. '"http_user_agent":"$http_user_agent",'
  22. '"size":$body_bytes_sent,'
  23. '"responsetime":$request_time,'
  24. '"upstreamtime":"$upstream_response_time",'
  25. '"upstreamhost":"$upstream_addr",'
  26. '"http_host":"$host",'
  27. '"requesturi":"$request_uri",'
  28. '"url":"$uri",'
  29. '"domain":"$host",'
  30. '"xff":"$http_x_forwarded_for",'
  31. '"referer":"$http_referer",'
  32. '"status":"$status"}';
  33. access_log logs/access.log json;
  34.  
  35.  
  36. sendfile on;
  37. keepalive_timeout 65;
  38.  
  39.  
  40. server {
  41. listen 80;
  42. server_name localhost;
  43. location / {
  44. root html;
  45. index index.html index.htm;
  46. }
  47.  
  48. }
  49.  
  50. }
  51.  
  52. ###########################
  53. 實際上就是添加了json格式的日誌
  54. log_format json '{"@timestamp":"$time_iso8601",'
  55. '"host":"$server_addr",'
  56. '"clientip":"$remote_addr",'
  57. '"remote_user":"$remote_user",'
  58. '"request":"$request",'
  59. '"http_user_agent":"$http_user_agent",'
  60. '"size":$body_bytes_sent,'
  61. '"responsetime":$request_time,'
  62. '"upstreamtime":"$upstream_response_time",'
  63. '"upstreamhost":"$upstream_addr",'
  64. '"http_host":"$host",'
  65. '"requesturi":"$request_uri",'
  66. '"url":"$uri",'
  67. '"domain":"$host",'
  68. '"xff":"$http_x_forwarded_for",'
  69. '"referer":"$http_referer",'
  70. '"status":"$status"}';
  71. access_log logs/access.log json;
  72. 日誌保存在/usr/local/nginx/logs/下

配置完成後,訪問nginx。查看日誌是否修改爲json


 
  1. [root@i4tnginx]# tail -f logs/access.log
  2. {"@timestamp""host":"10.4.82.203","clientip":"10.2.52.15","remote_user":"-","request":"GET / HTTP/1.1","http_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"10.4.82.203","requesturi":"/","url":"/index.html","domain":"10.4.82.203","xff":"-","referer":"-","status":"304"}
  3. {"@timestamp""host":"10.4.82.203","clientip":"10.2.52.15","remote_user":"-","request":"GET / HTTP/1.1","http_user_agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:60.0) Gecko/20100101 Firefox/60.0","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"10.4.82.203","requesturi":"/","url":"/index.html","domain":"10.4.82.203","xff":"-","referer":"-","status":"304"}

測試logstash配置文件是否正常


 
  1. 我們儘量都是用elk用戶,所以需要提前將logstash設置爲elk的屬主屬組
  2. chown -R elk.elk /usr/local/logstash
  3.  
  4. /usr/local/logstash/bin/logstash -f /usr/local/logstash/conf/nginx.conf -t
  5. ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
  6. Sending Logstash's logs to /usr/local/logstash/logs which is now configured via log4j2.properties
  7. Configuration OK
  8. [2019-01-28T11:54:38,481][INFO ][logstash.runner ] Using config.test_and_exit mode. Config Validation Result: OK. Exiting Logstash

image_1d299p9iidpp1d5n1i119t5roc9.png-380.7kB

在Nginx服務器上啓動logstash


 
  1. [root@abcdocker logstash]# su - elk
  2. [elk@abcdocker ~]$ /usr/local/logstash/bin/logstash -f /usr/local/logstash/conf/nginx.conf
  3.  
  4.  
  5. 溫馨提示,一定要確保logs目錄elk有權限寫入,建議我們在啓動elk之前在執行一次chown -R elk.elk /usr/local/logstash

image_1d3njupoc52v1tdv7gqjm814ho1j.png-760.4kB

請確保logstash中的file文件有讀取權限,否則無法在ES中創建索引!

image_1d3nk3m8rjcn1ics196emvql9h2d.png-956.6kB
我們可以查一下索引


 
  1. [root@YZSJHL82-203 local]# curl -XGET '10.4.82.217:9200/_cat/indices?v&pretty'
  2. health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
  3. yellow open .kibana 9l1XmifhTd2187a9Zpkqsw 1 1 1 0 3.2kb 3.2kb
  4. yellow open pro_nginx_access-2019.02.15 Guze8x5hTymSzqzQKu5PTQ 5 1 1315 0 1.3mb 1.3mb

Kibana 配置
目前logstash已經將收集的日誌存儲在es裏面,我們需要用kibana進行展示
image_1d3ntkdt115ht19u47fr1cg248r2q.png-250kB
查看索引命令


 
  1. [root@YZSJHL82-203 local]# curl -XGET '10.4.82.217:9200/_cat/indices?v&pretty'
  2. health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
  3. yellow open .kibana 9l1XmifhTd2187a9Zpkqsw 1 1 1 0 3.2kb 3.2kb
  4. yellow open pro_nginx_access-2019.02.15 Guze8x5hTymSzqzQKu5PTQ 5 1 1315 0 1.3mb 1.3mb

33333.png-134.6kB

Kibana創建索引
image_1d3ntnbmef52v4c1n6l12hm1aj337.png-220.8kB

創建完畢後查看索引
image_1d3nttiqk1bma1oqdbsq1jlkn6t49.png-103.7kB

 

六、Elasticsearch Head插件安裝

image_1d3nvibr01v1v1p4j1t7s1ccn8lm4m.png-54.6kB

elasticsearch-head是一個界面化的集羣操作和管理工具,可以對集羣進行傻瓜式操作。你可以通過插件把它集成到es(首選方式),也可以安裝成一個獨立webapp。

  • 顯示集羣的拓撲,並且能夠執行索引和節點級別操作
  • 搜索接口能夠查詢集羣中原始json或表格格式的檢索數據
  • 能夠快速訪問並顯示集羣的狀態
  • 有一個輸入窗口,允許任意調用RESTful API。這個接口包含幾個選項,可以組合在一起以產生有趣的結果;
    1. 請求方法(get、put、post、delete),查詢json數據,節點和路徑
    2. 支持JSON驗證器
    3. 支持重複請求計時器
    4. 支持使用javascript表達式變換結果
    5. 收集結果的能力隨着時間的推移(使用定時器),或比較的結果
    6. 能力圖表轉換後的結果在一個簡單的條形圖(包括時間序列)

官方的文檔:
https://github.com/mobz/elasticsearch-head

關於Head插件安裝有2中,如果使用的yum安裝es可以直接用es中的plugin install mobz/elasticsearch-head另一種就是需要安裝Node環境
ELKStack 實戰之 Elasticsearch [一]


安裝插件時使用到了npm,所以我們需要安裝npm
二進制安裝npm https://www.i4t.com/2840.html


 
  1. [root@i4t ~]# yum install git npm #安裝git和npm
  2. [root@i4t ~]# cd /usr/local/
  3. [root@i4t elasticsearch-head]# git clone https://github.com/mobz/elasticsearch-head.git #克隆代碼
  4. [root@i4t local]# cd elasticsearch-head/
  5.  
  6. #需要注意的是執行以下命令需要在elasticsearch-head目錄下執行
  7. npm install
  8. npm run start ##這是在前臺運行,如果想讓它在後臺運行npm run start &
  9.  
  10.  
  11.  
  12. 需要提前在elasticsearch.yml配置如下,如果安裝我的文檔安裝都是已經配置好了
  13. vim /usr/local/elasticsearch/elasticsearch.yml
  14. http.cors.enabled: true # elasticsearch中啓用CORS
  15. http.cors.allow-origin: "*" #允許訪問的IP地址段,* 爲所有IP都可以訪問

默認端口是9100,默認監控的主機也是localhost

請目錄結構和我保持一致

image_1d3o1rt0j1lv1ord1ghpr251ns27f.png-143kB
111.png-138.1kB

修改默認端口以及默認連接ES地址
vim elasticsearch-head/Gruntfile.js
修改默認的端口
image_1d3o1gvalajsg2abfa1i1rvj86l.png-28.4kB

因爲head插件默認打開是連接localhost的,我們需要將localhost修改爲我們的ip
vim elasticsearch-head/_site/app.js
將localhost換成es的ip即可
image_1d3o1p7f71hukbn016pq16ugh4272.png-82.5kB
修改完成後直接要npm run start &即可,不需要build
321.png-229.2kB

因爲是單點,所以是Yellow狀態

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章