2006年01月7日
Resin 3.x與JMX的使用測試
由於Resin 3已經支援JMX(Java Management Extensions)了,但以前並沒有關注過這項議題,今天趁空粗略的測試了一次。
JMX是定義成統一的監控與管理JVM的標準,JDK 5.0也已內建(參考:Monitoring and Management for the JavaTM Platform) ,用來監控JMX的兩種模式是:
- 讓Resin進入JMX本地端管理狀態:
- httpd.exe -Dcom.sun.management.jmxremote
- 讓Resin進入JMX遠端管理狀態:
- httpd.exe -Dcom.sun.management.jmxremote.port=9004
本地端管理是最簡單的,讓Resin啟動後,用JDK 5.0\bin\jconsole.exe就可以來管理Resin Server,一進入jconsole就可以看到已經啟動好的Resin Server,按Connect即可進入管理畫面。
jconsole管理畫面有Summary、Memory、Threads、Classes、MBeans與VM等六個頁籤,透過這六個功能畫面能清楚看到Resin Server的內部狀況,在MBeans並能透過提供的Method來停止或啟動Resin Server或其中的某個Web應用系統。
以下便是在jconsole裡可以用start、stop等操作來控制Resin Server裡的某一個Web應用系統,當然整個Resin Server也可透過此種方式控制。
遠端的JXM管理則手續複雜得多,我們可以先把認證和SSL的功能關閉,以快速測試:
- httpd -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
在jconsole的登入對話窗切換到Remote並輸入主機名稱或IP與Port再按Connect即可連接成功。
接著忽略SSL的設定,只利用密碼檔的認證來管理。JMX使用的密碼檔必須只有Owner能存取,因此必須放置在NTFS上,無法放在FAT32上(參考:JConsole: remoting, notifications and log control)。
- 複製密碼檔:
- 修改密碼檔,加入要登入的使用者帳號與密碼
- 修改權限,讓使用者只剩下啟動Resin Server的使用者,同時用進階將權限只有一名使用者(把從「...父項繼承權...」的勾選拿掉)
- 在同目錄內的jmxremote.access加入新加帳號與其存取權限(readonly或readwrite)
| cd \JDK1.5\jre\lib\management copy jmxremote.password.template jmxremote.password |
若密碼檔權限未設定完整,則啟動Resin時會出現錯誤訊息:
Error: Password file read access must be restricted: C:\JDK1.5\jre\lib\managemet\jmxremote.password
除了使用jconsole外,也可以用Open-Source的MC4J Management Console來管理。MC4J console的結果類似jconsole,只是呈現的方式不同而已,由其網站得知此程式是建立在NetBeans之上的應用,因此其操作介面與 NetBeans相當雷同。
- 先下載MX4J(MC4J是建立在MX4J的 Client),再把MX4J\lib裡的所有jar檔複製到Resin的Lib目錄。
- 啟動Resin Server
- 啟動MC4J Management Console
- 如下列畫面建立連線並登入MC4J

MC4J的功能與jconsole類似,操作介面與NetBeans雷同。
在MBeans上按右鈕也可以開啟Dashboard視窗(Basic MBean view)。
##
