X-Pack 已經做爲 Elastic 公司單獨的產品線,前身是 Shield, Watcher, Marvel, Graph, 和 reporting,先來講說這幾個爸爸是作什麼的吧:javascript
再來看看咱們的兒子 X-Pack 是作啥的,哦,他就是他們的兒子,一個大合集,便於安裝、不用爲版本兼容性犯愁,能夠靈活 disable / enable 其中的各個組件。他還多幹了一件事兒,能夠監控 Logstash。html
關於免費和收費版本,版本功能比較能夠查看:https://www.elastic.co/subscriptionsjava
免費版本註冊地址:https://register.elastic.co/xpack_registershell
付費版本(分爲黃金、白金級別)購買地址:https://www.elastic.co/subscriptions/xpack數據庫
默認的免費版本有一個月的 trial 試用期。免費版本試用期只包含 ES 集羣監控、圖分析和可視化,基於角色的 ES 權限控制和搜索用戶信息的功能。不包含:緩存
總的來講免費版本對於安全組件這塊什麼都不支持。安全
安裝 X-Pack 前必須安裝 ES 和 Kibana ,咱們使用的是 5.2.1 版本 集中式日誌分析平臺 - ELK Stack - 部署篇。X-Pack 咱們也使用 5.2.1,咱們來說講如何離線安裝吧。bash
Step1. 下載 X-Pack Zip 文件:https://artifacts.elastic.co/downloads/packs/x-pack/x-pack-5.2.1.zip
(sha1),尼瑪有119MB那麼大。服務器
Step2. 上傳 zip 文件至服務器 /tmp
目錄;oracle
Step3. 在 ES 安裝目錄運行 bin/elasticsearch-plugin install
命令 :
bin/elasticsearch-plugin install file:/tmp/x-pack-5.2.1.zip
如下輸出表示安裝成功:
-> Downloading file:/home/admin/x-pack-5.2.1.zip [=================================================] 100% @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: plugin requires additional permissions @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ * java.lang.RuntimePermission accessClassInPackage.com.sun.activation.registries * java.lang.RuntimePermission getClassLoader * java.lang.RuntimePermission setContextClassLoader * java.lang.RuntimePermission setFactory * java.security.SecurityPermission createPolicy.JavaPolicy * java.security.SecurityPermission getPolicy * java.security.SecurityPermission putProviderProperty.BC * java.security.SecurityPermission setPolicy * java.util.PropertyPermission * read,write * java.util.PropertyPermission sun.nio.ch.bugLevel write * javax.net.ssl.SSLPermission setHostnameVerifier See http://docs.oracle.com/javase/8/docs/technotes/guides/security/permissions.html for descriptions of what these permissions allow and the associated risks. Continue with installation? [y/N]y -> Installed x-pack
Step4. 在 Kibana 安裝目錄運行 bin/kibana-plugin install
命令安裝:
bin/kibana-plugin install file:/tmp/x-pack-5.2.1.zip
如下輸出表示安裝成功:
Attempting to transfer from file:/home/admin/x-pack-5.2.1.zip Transferring 124956667 bytes.................... Transfer complete Retrieving metadata from plugin archive Extracting plugin archive Extraction complete Optimizing and caching browser bundles... Plugin installation complete
Step5. 在 Logstash 安裝目錄運行 bin/logstash-plugin install
命令安裝:
bin/logstash-plugin install file:/tmp/x-pack-5.2.1.zip
如下輸出表示安裝成功:
Installing file: /home/admin/x-pack-5.2.1.zip Install successful
咱們能夠經過如下配置進行功能開關:
Setting | Description |
---|---|
xpack.security.enabled |
設置爲 false 能夠關閉 X-Pack security 功能。須要在 elasticsearch.yml 和 kibana.yml 同時配置。 |
xpack.monitoring.enabled |
設置爲 false 能夠關閉 X-Pack monitoring 功能。 須要在elasticsearch.yml 和 kibana.yml 同時配置。 |
xpack.graph.enabled |
設置爲 false 能夠關閉 X-Pack graph 功能。 須要在elasticsearch.yml 和 kibana.yml 同時配置。 |
xpack.watcher.enabled |
設置爲 false 能夠關閉 Watcher 功能。 只須要在 elasticsearch.yml 配置。 |
xpack.reporting.enabled |
設置爲 false 能夠關閉 reporting 功能。 只須要在 kibana.yml 配置。 |
咱們須要重啓三個服務:
./bin/logstash -f config/logstash.conf 2>&1 & /home/admin/soft/elasticsearch-5.2.1/bin/elasticsearch & ./bin/kibana --verbose > kibana.log 2>&1 &
重啓後發現日誌數據沒法上傳到 ES,filebeat 報錯:
2017-02-22T14:01:27+08:00 ERR Failed to publish events caused by: read tcp 172.16.134.3:56109->172.16.134.2:5044: i/o timeout
logstash 的 5044 端口能夠訪問,查看 logstash 日誌:
[2017-02-22T14:02:21,705][WARN ][logstash.outputs.elasticsearch] UNEXPECTED POOL ERROR {:e=>#<LogStash::Outputs::ElasticSearch::HttpClient::Pool::NoConnectionAvailableError: No Available connections>} [2017-02-22T14:02:21,705][ERROR][logstash.outputs.elasticsearch] Attempted to send a bulk request to elasticsearch, but no there are no living connections in the connection pool. Perhaps Elasticsearch is unreachable or down? {:error_message=>"No Available connections", :class=>"LogStash::Outputs::ElasticSearch::HttpClient::Pool::NoConnectionAvailableError", :will_retry_in_seconds=>64}
調用 ES 服務 curl http://172.16.134.2:9200
:
{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication token for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}}],"type":"security_exception","reason":"missing authentication token for REST request [/]","header":{"WWW-Authenticate":"Basic realm=\"security\" charset=\"UTF-8\""}},"status":401}
發現是出現了認證失敗,筆者推算和 logstash 訪問 ES 未以受權方式進行致使,修改 logstash.conf
在 output
段裏添加:
user => 'elastic' password => 'changeme'
修改 logstash.yml
,添加:
xpack.monitoring.elasticsearch.url: "http://172.16.134.2:9200" xpack.monitoring.elasticsearch.username: "logstash_system" xpack.monitoring.elasticsearch.password: "changeme"
重啓服務後OK。
打開 Kibana 頁面,筆者很尷尬,根本不知道用戶名和密碼是啥,OK 萬能的谷歌告訴咱們了:
username: elastic password: changeme
Kibana 的界面多了以下幾個功能跳轉:Graph
Monitoring
elastic
Logout
。
Graph 能夠根據實時查詢,對給定的 field 獲得圖視角的關聯關係,筆者以一個快速發現集羣中哪臺 host 有明顯 ERROR 爲例講解下如何使用。Index Pattern
咱們選擇 filebeat-*
,咱們添加 兩個 filed:host
log_level
,而後在咱們的搜索框添加 hour:14 AND minute: [20 TO 37]
,獲得如下繪圖:
能夠直觀的看到咱們的兩臺被採集機器和日誌級別的關係,v134003.yn1 INFO 日誌較多,v134008.yn1 ERROR 日誌較多。點擊灰色的邊,咱們能夠看到這個 Link 的概況:
有一個直觀的包含交集圖,還有3個數字,分別表示:
查看 ES 集羣的 health:
Uptime
: 集羣運行時間;Disk Available
:可用磁盤;JVM Heap
: JVM 使用狀況;Indices
:索引數量,至關於數據庫數;Documents
:文檔數量,至關於記錄數;Disk Usage
:磁盤使用狀況;Primary Shards
:分片數;Replica Shards
:冗餘分片數;相較於集羣健康視圖,這裏的指標更多:
Serach Rate (/s)
:近1小時的查詢速率,QPS;Search Latency (ms)
:近1小時的查詢延遲;Index Rate (/s)
:近1小時的索引速率,IPS;Index Latency (ms)
:近1小時的索引延遲;Shard Activity
:對於 Shard 的操做歷史;索引視角的監控視圖,包含如下指標:
Document Count
:文檔數;Data
:數據量;Index Rate
:索引速率;Search Rate
:查詢速率;Unassigned Shards
:未分配的分片數;點擊 Index Name 能夠進入查看對於索引的詳細基礎監控:
Index Memory (KB)
:索引內存使用,分爲 Lucene、Term、Points;Index Size (MB)
:索引大小;Search Rate (/s)
:查詢速率;Indexing Rate (/s)
:索引速率;Segment Count
:段數;Document Count
:文檔數;Shard Legend
:分片狀態圖譜,分爲 Primary
, Replica
,Relocating
,Initializing
,Unassigned Primary
,Unassigned Replica
多個狀態。點擊 Advanced
能夠看到高級監控頁面,請讀者本身去感覺下。
節點監控,首先看到的是概述指標:
CPU Usage
: CPU 使用率;Load Average
:CPU 平均負載;JVM Memory
:JVM 使用狀況;Disk Free Space
:磁盤空閒空間;Shards
:分片數;點擊某個節點咱們能夠看到詳細基礎監控:
JVM Heap (GB)
:JVM 使用狀況;Index Memory (KB)
:索引佔用內存;CPU Utilization (%)
:CPU 使用率;System Load
:系統負載;Latency (ms)
:延遲,分爲索引和查詢;Segment Count
:段數量;Shard Legend
:分片狀態圖譜, Primary
, Replica
,Relocating
,Initializing
多個狀態。該功能的入口在 Management
-> Users
/Roles
。Users
能夠方便的管理用戶而且對其賦予角色,角色和權限掛鉤。Roles
能夠方便的管理角色,對其進行賦權。Role
是 Permission
的集合,Permission
是 Privilege
的集合,下面來講說權限:
其中,集羣權限和索引權限的詳細細分權限以下:
權限類型 | 權限描述 |
---|---|
all |
全部羣集管理操做,如快照,節點關閉/從新啓動,設置更新,從新路由或管理用戶和角色。 |
monitor |
全部集羣只讀操做,如集羣健康狀態,熱線程,節點信息,節點和集羣統計信息,快照/恢復狀態,掛起集羣任務。 |
manage |
構建在監視器上,並添加可更改集羣中值的集羣操做。這包括快照,已檢查的設置和從新路由。此權限不包括管理安全性的能力。 |
manage_security |
全部與安全性相關的操做,如對用戶和角色的CRUD操做以及緩存清除。 |
manage_index_templates |
對索引模板的全部操做。 |
manage_pipeline |
對管道的全部操做。 |
transport_client |
傳輸客戶端鏈接所需的全部權限。 |
權限類型 | 權限描述 |
---|---|
all | 全部索引操做權限。 |
monitor |
監控(恢復,細分信息,索引統計信息和狀態)所需的全部操做。 |
manage |
全部監視器權限和索引管理( aliases, analyze, cache clear, close, delete, exists, flush, mapping, open, force merge, refresh, settings, search shards, templates, validate |
view_index_metadata |
只讀訪問索引元數據(aliases, aliases exists, get index, exists, field mappings, mappings, search shards, type exists, validate, warmers, settings)。此權限主要供Kibana用戶使用。 |
read |
只讀訪問操做(count, explain, get, mget, get indexed scripts, more like this, multi percolate/search/termvector, percolate, scroll, clear_scroll, search, suggest, tv)。還授予對更新映射操做的訪問權限。 |
index |
索引和更新文檔的權限。還授予對更新映射操做的訪問權限。 |
create |
索引文檔的權限。還授予對更新映射操做的訪問權限。 |
delete |
刪除文檔的權限。 |
write |
對文檔執行全部寫操做的權限,包括對文檔進行索引,更新和刪除以及執行批量操做的權限。還授予對更新映射操做的訪問權限。 |
delete_index |
刪除索引的權限。 |
create_index |
建立索引的權限。建立索引請求可能包含在建立後添加到索引的別名。在這種狀況下,請求還要求在索引和別名名稱上具備manage特權。 |
具體的 Privilege 能夠參看:https://www.elastic.co/guide/en/x-pack/current/security-privileges.html。
本文主要介紹了安全解決方案 X-Pack 的概況、免費和收費版本的區別、部署步驟以及基本免費功能的使用。基於此,咱們的結論是,對於企業級安全解決方案來講,免費版本的 X-Pack 的確力不從心,須要購買或者結合第三方免費插件進行安全方案升級。
Q: 打開 Kibana 遇到 Login is disabled because your license has expired. Please extend your license or disable Security in Elasticsearch.
A: 說明體驗的 x-pack 功能證書過時,須要 disable 以後才能夠恢復使用,在 elasticsearch.yml 中添加:
xpack.security.enabled: false