天天看點

ZooKeeper監控工具(六)

之前說了那麼多配置資訊,具體做的怎麼樣,還需要真正的擷取ZooKeeper的運作時資訊才行。這裡介紹ZooKeeper的監控。

ZooKeeper監控工具(六)

與文無關

有如下方式:

  • 使用内置的四字指令來擷取健康狀态資訊
  • 使用JMX檢視運作狀态
  • 使用Exhibitor
  • 使用Sass

四字指令

最簡單的監控方式就是使用ZooKeeper的四字指令,你可以直接通過telnet或者nc指令檢視狀态。

ZooKeeper監控工具(六)
ZooKeeper監控工具(六)
ZooKeeper監控工具(六)

常用的四字指令如下:

  • conf: 列印ZooKeeper的配置資訊
  • cons: 列出所有的用戶端會話連結
  • crst: 重置所有的用戶端連接配接
  • dump: 列印叢集的所有會話資訊,包括ID,以及臨時節點等資訊。用在Leader節點上才有效果。
  • envi: 列出所有的環境參數
  • ruok: "諧音為Are you ok"。檢查目前伺服器是否正在運作。
  • stat: 擷取ZooKeeper伺服器運作時的狀态資訊,包括版本,運作時角色,叢集節點個數等資訊。
  • srst: 重置伺服器統計資訊
  • srvr: 和stat輸出資訊一樣,隻不過少了用戶端連接配接資訊。
  • wchs: 輸出目前伺服器上管理的Watcher概要資訊
  • wchc: 輸出目前伺服器上管理的Watcher的詳細資訊,以session為機關進行歸組
  • wchp: 和wchc非常相似,但是以節點路徑進行歸組
  • mntr: 輸出比stat更為詳細的伺服器統計資訊

JMX

JMX是用來遠端監控Java應用的架構,這個也可以用來監控其他的Java應用。JMX使用起來也很簡單。

在運作Java的jar的時候:

//不需要使用者密碼的
-Dcom.sun.management.jmxremote.port=5000  
-Dcom.sun.management.jmxremote.authenticate=true 
-Dcom.sun.management.jmxremote.ssl=false 

// 使用需要使用者密碼登入的
-Dcom.sun.management.jmxremote.port=5000  
-Dcom.sun.management.jmxremote.authenticate=true 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.access.file=jmxremote.access
-Dcom.sun.management.jmxremote.password.file=jmxremote.password   

 cat jmxremote.access
monitorRole   readonly
controlRole   readwrite
 cat jmxremote.password
monitorRole mypassword
controlRole mypassword
           

接下來,我們可以使用jConsole或者VisualVM進行監控。

預設情況下,ZooKeeper允許本地進行監控。

ZooKeeper監控工具(六)

jconsole圖

如果想要遠端監控,可以修改zkServer.sh檔案中的shell腳本

ZooKeeper監控工具(六)

JMX參數圖

修改方式為我們剛才看到的加上

-Dcom.sun.management.jmxremote.access.file=jmxremote.access
-Dcom.sun.management.jmxremote.password.file=jmxremote.password   
           

Exhibitor

Exhibitor是一個ZooKeeper的管理工具,由Netfix公司開發,在ZooKeeper監控,備份恢複,清潔,在可視化上提供了不小的幫助。

  1. 首先我們下載下傳exhibitor的pom檔案
mkdir build
cd build 
wget -c https://raw.github.com/Netflix/exhibitor/master/exhibitor-standalone/src/main/resources/buildscripts/standalone/maven/pom.xml
           
  1. 打包編譯jar包
//這個打包的時間真心長
mvn clean package
// 測試是否正确打包,這個exhibitor根據你自己打包出來的檔案名進行測試
java -jar target/exhibitor-1.6.0.jar --help       

           
  1. 運作
java -jar exhibitor-1.6.0.jar -c file
           
  1. 在浏覽器中輸入exhibitor的位址

    http://伺服器位址:8080/exhibitor/v1/ui/index.html

  2. 配置Exhibitor
    ZooKeeper監控工具(六)
    Exhibitor面闆
  1. 更多Exhitor的詳細資訊,參考github的wiki
https://github.com/soabase/exhibitor/wiki

雲服務商

當然也有一些雲服務商提供ZooKeeper的監控服務,一般都是收費的。

國外的有:server density. 網站:

https://www.serverdensity.com/

最後

在看ZooKeeper監控的時候,發現ZooKeeper的監控工具都很老了,大部分都是幾年前的了,ZooKeeper這是要被淘汰了嗎...,好用的軟體應該都有很好用的工具才對。不過既然當初它那麼流行,還是有值得研究的地方...

參考

  • 《從Paxos到ZooKeeper-分布式一緻性原理與實踐》
  • 《Apache ZooKeeper Essetial》
  • Exhibitor Wiki