以local模式使用Xshell+Xmanager远程监控jvisualvm
使用jvisualvm的remote方式监控服务器端jvisualvm时,不是很方便,因此通过local方式,应该是正路。
一、服务器端(Linux,最小安装模式,没有图形界面)
1.安装xauth
如果在Xshell中配置了X11转发后,出现如下提示:
WARNING! The remote SSH server rejected X11 forwarding request.
则需要查看/etc/ssh/sshd_config中以下选项是否为yes,
X11Forwarding yes
如果设置没问题,连接时仍报上述提示,则需要安装xauth(使用微软Azure时,最小化安装Linux,默认没有xauth)
yum install xorg-x11-xauth
2.安装xhost
如果执行xhost +命令,提示xhost命令找不到,则还需要安装xhost,否则略过此步:
[teld@T-SHA1-FLK-01 ~]$ xhost +
-bash: xhost: command not found
查看谁提供了xhost:
[teld@T-SHA1-FLK-01 ~]$ yum provides xhost
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
xorg-x11-server-utils-7.7-20.el7.x86_64 : X.Org X11 X server utilities
Repo : base
Matched from:
Provides : xhost = 1.0.7
从列表中选择安装:
[teld@T-SHA1-FLK-01 ~]$ yum install xorg-x11-server-utils-7.7-20.el7.x86_64 [teld@T-SHA1-FLK-01 ~]$ xhost + access control disabled, clients can connect from any host
3.检查$DISPLAY是否有值
[teld@T-SHA1-FLK-01 ~]$ echo $DISPLAY localhost:10.0
二、客户端(Windows)
1.安装Xshell
2.安装Xmanager
Xmanager会把X DISPLAY选项自动查找为Xshell
3.配置Xshell
三、使用步骤
1.Xshell连接远程服务器
2.在Xshell中启动xhost +,以便在客户端开启xserver
[teld@T-SHA1-FLK-01 ~]$ xhost + access control disabled, clients can connect from any host
如果客户端的xmanager没开的话,这时会发现客户端的xmanager会被拉起来了
3.在Xshell中启动jvisualvm
[teld@T-SHA1-FLK-01 ~]$ jvisualvm
这时会发现jvisualvm在xmanager里出现了:
四、遇到的坑
如果执行jvisualvm时,未能弹出性能监控画面,可以查看VisualVM的日志:
切换到指定日志下,查看日志内容,发现是:
java.lang.UnsatisfiedLinkError: /usr/java/jdk1.8.0_131/jre/lib/amd64/libawt_xawt.so:
libXtst.so.6: cannot open shared object file: No such file or directory at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824) at java.lang.Runtime.load0(Runtime.java:809) at java.lang.System.load(System.java:1086) at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1845) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:77) at java.security.AccessController.doPrivileged(Native Method) at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103) at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82) at org.netbeans.core.startup.Main.start(Main.java:214) at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:84) at java.lang.Thread.run(Thread.java:748)
根据提示,发现需要安装libXtst
[teld@T-SHA1-FLK-02 ~]$ yum install libXtst
问题解决。
网上也有建议需要安装三个:
#yum install libXp
#yum install libXt
#yum install libXtst
实际运行时,发现只安装libXtst即可