三、kibana可視化
kibana簡介
Kibana 核心產品搭載了一批經典功能:柱狀圖、線狀圖、餅
圖、旭日圖,等等。
將地理數據融入任何地圖
精選的時序性 UI,對您Elasticsearch 中的數據執行高級時間
序列分析。
利用 Graph 功能分析數據間的關係
Kibana 開發工具爲開發人員提供了多種強大方法來幫助其與
Elastic Stack 進行交互。
目前,大部分企業都把kibana當作門戶去對待,與企業的各種服務進行整合。
我們在開啓一臺server5主機安裝kibana
kibana安裝與配置
[root@server5 ~]# rpm -ivh kibana-7.6.1-x86_64.rpm
[root@server5 ~]# vim /etc/kibana/kibana.yml
server.por t: 5601 #服務端口
server.hos t: "172.25.0.5" #服務監聽地址
elasticsearch.hos ts : ["http://172.25.0.4:9200"] #ES集羣地址
kibana.index: ".kibana" #kibana在ES中創建的索引
i18n.locale: "zh -CN" #使用中文
啓動服務:
[root@server5 ~]# systemctl start kibana.service
[root@server5 ~]# netstat -tnlp |grep 560
tcp 0 0 172.25.254.5:5601 端口打開
去網頁訪問:
點使用樣例數據。
添加web log ,點及儀表板查看
這就是一些樣例數據。
kibana使用
我們自己創建一個儀表板,把 ES 的apache的數據放過來。
點擊管理,創建索引:
它已經幫我們讀取到了ES中的數據
使用時間戳。
然後我們去發現裏面看一下;
可以找到ES中的數據並進行篩選。
創建一個新的可視化
選擇指標,點擊apachelog-*
點擊保存,起個名字。
然後我們將它放到一個儀表板裏面,創建儀表板;
在添加面板中放入我們的web 指標數據:
保存:
這個儀表板就做好了。
它可以全憑看。
還可以設置刷新時間。我們設置5s一次。
然後我們去訪問它:
在來一百條,注意這是我們的logstash還在運行。
[kiosk@rhel7host ~]$ ab -c 1 -n 100 http://172.25.254.3/index.html
就變200 了。
它的流程是:
client -> apache -> save log -> access_log -> logstash -> es -> kibana -> web
客戶端訪問站點,日誌保存在accesslog 中,logstash 做數據採集,放到ES 中,然後再通過kibana展示,整合到web界面中。
我們在創建幾個可視化圖形:
垂直條行圖,對網站的訪問量進行一個排行
我們創建一個X軸,通過ip地址進行劃分。排名5個。
當前我們只有一臺主機訪問了,我們在用其它主機訪問幾次。
yum install httpd-tools.x86_64 -y #安裝工具,然後用ab進行訪問
[root@server2 ~]# ab -c 1 -n 80 http://172.25.254.3/index.html
[root@server1 elasticsearch]# ab -c 1 -n 100 http://172.25.254.3/index.html
[root@server4 _site]# ab -c 1 -n 300 http://172.25.254.3/index.html
就排名了,保存 top 5。
在把它加入到儀表板。
保存。
[root@server4 _site]# ab -c 1 -n 100 http://172.25.254.3/index.html
在加100條
儀表板也再動態的增加。
我們還可以加入餅圖等等。
kibana還有很多的功能模塊,這裏不一一展示。
啓用xpack安全驗證
現在我們任何人都可以連接es,爲了安全起見,集羣模式我們需要先創建證書,並且響相關聯的logstash和kibana也需要做響應的設置:
這裏我們採用的不綁定結點的證書,大家共用一個集羣的證書,我們的ES 爲我們提供了命令:
[root@server4 bin]# ./elasticsearch-certutil ca
The 'ca' mode generates a new 'certificate authority'
This will create a new X.509 certificate and private key that can be used
to sign certificate when running in 'cert' mode.
Use the 'ca-dn' option if you wish to configure the 'distinguished name'
of the certificate authority
By default the 'ca' mode produces a single PKCS#12 output file which holds:
* The CA certificate
* The CA's private key
If you elect to generate PEM format certificates (the -pem option), then the output will
be a zip file containing individual files for the CA certificate and private key
Please enter the desired output file [elastic-stack-ca.p12]: # 輸出文件
Enter password for elastic-stack-ca.p12 : # 這裏爲證書生成密碼,就是每次使用證書,就要輸入密碼,我們這裏不做設定
[root@server4 bin]# ./elasticsearch-certutil cert --ca elastic-stack-ca.p12
這裏也要輸入密碼,我們剛纔沒有設定,直接回車
[root@server4 bin]# cd ..
[root@server4 elasticsearch]# ls
elastic-stack-ca.p12
elastic-certificates.p12 ## 生成了這兩個文件
[root@server4 elasticsearch]# cd /etc/elasticsearch/
[root@server4 elasticsearch]# ll
total 48
-rw------- 1 root elasticsearch 3443 Jun 11 14:54 elastic-certificates.p12
...
-rw------- 1 root elasticsearch 2527 Jun 11 14:54 elastic-stack-ca.p12
## 沒有權限
[root@server4 elasticsearch]# chown elasticsearch elastic-certificates.p12 elastic-stack-ca.p12
# 所以我們把文件安交給elasticsearch
[root@server4 elasticsearch]# ll
total 48
-rw------- 1 elasticsearch elasticsearch 3443 Jun 11 14:54 elastic-certificates.p12
...
-rw------- 1 elasticsearch elasticsearch 2527 Jun 11 14:54 elastic-stack-ca.p12
然後拷貝給其它結點,就都可以使用了,我們沒有綁定主機。然後改變他們的權限,和上面一樣
[root@server4 elasticsearch]# scp elastic-certificates.p12 elastic-stack-ca.p12 server1:/etc/elasticsearch/
[root@server4 elasticsearch]# scp elastic-certificates.p12 elastic-stack-ca.p12 server2:/etc/elasticsearch/
接下來我們去修改每個節點的配置:
在server1,2,4三個es結點中
vim elasticsearch.yml
xpack.security.enabled: true
xpack.security.trans port.ssl.enabled: true
xpack.security.trans port.ssl.veri fication_mode: certificate
xpack.security.trans port.ssl.keys tore.path: /etc/elastics earch/elastic-certificates.p12
xpack.security.trans port.ssl.trus tstore.path: /etc/elasticsearch/elasticcertificates.p12
# 在最後加入這些參數,重啓服務
systemctl restart elasticsearch.service
然後kibana就像我們要密碼:
不輸入的話就會退出,ES也連接不了了。
然後器用xpack安全驗證,設置用戶密碼;
[root@server4 bin]# ./elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana]:
Reenter password for [kibana]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
我這裏爲每個用戶設置了一樣的密碼。
我們刷新
設置kibana連接ES的用戶密碼:
[root@server5 ~]# vim /etc/kibana/kibana.yml
打開連接ES的用戶,重啓,這是就要求我們登陸了
elastic , caoaoyuan。
登陸進去後,點擊儀表板
可以得到數據,就說明連接正常了。
接下來去設置logstash:
[root@server3 conf.d]# vim apache.conf # 編輯它的配置文件
input {
file {
path => "/var/log/httpd/access_log"
start_position => "beginning"
}
}
filter{
grok {
match => { "message" => "%{HTTPD_COMBINEDLOG}" }
}
}
output {
elasticsearch {
hosts => "172.25.254.4:9200"
index => "apachelog-%{+YYYY.MM.dd}"
user => "elastic" # 加上連接的用戶和密碼
password => "caoaoyuan"
}
}
[root@server3 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/apache.conf #再啓動
[kiosk@rhel7host ~]$ ab -c 1 -n 100 http://172.25.254.3/index.html
# 在訪問100次
增加了,說明logstash 和es的連接也好了。
但是我們的ES 依然是訪問不了的,
我們需要去配置一下:
[root@server4 bin]# vim /etc/elasticsearch/elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type # 加上這一行
[root@server4 bin]# systemctl restart elasticsearch.service
然後再訪問的時候加上用戶和密碼就行了。
http://172.25.254.4:9100/?auth_user=elastic&auth_password=caoaoyuan
這就是 elk 的一個整體架構就做好了。