近日?qǐng)F(tuán)隊(duì)有一個(gè)集群項(xiàng)目部分機(jī)器發(fā)生了宕機(jī),于是想通過(guò)jvisualvm遠(yuǎn)程連接到集群機(jī)器,可是部分機(jī)器能正常建立jmx連接,查看遠(yuǎn)程jvm統(tǒng)計(jì)信息。部分機(jī)器在連接過(guò)程中彈出錯(cuò)誤窗口,顯示無(wú)法使用service:jmx:rmi:///jndi/rmi://controller:8777/jmxrmi連接到controller:8777,
遠(yuǎn)程集群所有機(jī)器的jmx相關(guān)配置為
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8777
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.rmi.port=8777
jvisualvm連接過(guò)程中,在遠(yuǎn)程機(jī)器上查看tcp連接情況:
$ jps
27506 controller-launcher.jar
17784 RegistryImpl
27708 Main
28925 Jps
$ netstat -tlpna | grep 8777
tcp 0 0 0.0.0.0:8777 0.0.0.0:* LISTEN 27708/java
進(jìn)程在監(jiān)聽(tīng)8777端口,但是沒(méi)有建立tcp連接。
在jvisualvm所在機(jī)器上ping遠(yuǎn)程機(jī)器能ping通,說(shuō)明網(wǎng)絡(luò)沒(méi)問(wèn)題。
由于遠(yuǎn)程機(jī)器的jmx配置沒(méi)有配置 -Djava.rmi.server.hostname,它的官方解釋為:
java.rmi.server.hostname
The value of this property represents the host name string that should be associated with remote stubs for locally created remote objects, in order to allow clients to invoke methods on the remote object. The default value of this property is the IP address of the local host, in "dotted-quad" format.
By default, the remote stubs for locally created remote objects that are sent to client contains the IP address of the local host in dotted-quad format. For remote stubs to be associated with a specific interface address, the java.rmi.server.hostname system property must be set to IP address of that interface.
說(shuō)明jmx server默認(rèn)是在local host的ip地址上提供RMI服務(wù)
在遠(yuǎn)程機(jī)器上查看主機(jī)名對(duì)應(yīng)的ip地址:
$ host controller
controller has address 10.242.93.40
$ hostname -i
10.85.35.39
原來(lái)主機(jī)名的dns注冊(cè)地址與本地解析的地址不一致,查詢/etc/hosts配置文件內(nèi)容:
$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.85.35.39 controller
原來(lái)不知哪位同事修改了/etc/hosts文件,并為主機(jī)名設(shè)置了一個(gè)與公司在dns上登記的不一樣的ip地址。
刪除掉/etc/hosts文件中配置內(nèi)容:10.85.35.39 controller,重新啟動(dòng)controller,jvisualvm就可以正常連接遠(yuǎn)程機(jī)器,監(jiān)視jvm運(yùn)行數(shù)據(jù)了。
這里如果不改/etc/hosts中的配置,通過(guò)-Djava.rmi.server.hostname=10.242.93.40 jmx選項(xiàng)明確指定jmx server遠(yuǎn)程調(diào)用服務(wù)關(guān)聯(lián)的ip地址為10.242.93.40,jvisualvm也可以連接上遠(yuǎn)程機(jī)器