通过windows系统中的VisualVM工具,监控Linux系统的测试环境或uat环境或生成环境,来监控JVM内存。
VisualVm提供在Java虚拟机(Java Virutal Machine,JVM)上运行的java应用程序。
只有按照了jdk,就可以在bin目录下,找到启动程序。
以下是具体步骤:
一、再windows系统中,启动VisualVM
-
在windows系统中java安装目录中
jdk/bin/
目录下的jvisualvm.exe
启动程序。双击启动。 -
下载插件
依次点击:工具-> 插件
二、再Linux系统中,配置远程授权
要监控Linux服务器,需要在该服务器上运行jstatd
守护进程。
2.1 配置
jstatd
命令也是在jdk/bin/
目录下。
执行这个命令之前,需要进行安全策略授权。在jdk/bin
目录下,创建名称为jstatd.all.policy
的文件,内容如下:
grant codebase "file:${java.home}/../lib/tools.jar" { permission java.security.AllPermission; };
2.2 启动
配置完后,在jdk/bin
目录下执行jstatd
命令,命令为:
# jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=ip (hostname 为你的 IP) # & 是后台运行 ./jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=172.16.120.12 &
如果启动报错,错误信息如下:
/usr/local/jdk1.8.0_321/bin/jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=172.16.120.12 Could not create remote object access denied ("java.util.PropertyPermission" "java.rmi.server.ignoreSubClasses" "write") java.security.AccessControlException: access denied ("java.util.PropertyPermission" "java.rmi.server.ignoreSubClasses" "write") at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472) at java.security.AccessController.checkPermission(AccessController.java:886) at java.lang.SecurityManager.checkPermission(SecurityManager.java:549) at java.lang.System.setProperty(System.java:792) at sun.tools.jstatd.Jstatd.main(Jstatd.java:139)
解决办法:修改/usr/local/jdk1.8.0_321/jre/lib/security/java.policy
文件,并在最后增加如下内容:
//添加下面内容 permission java.security.AllPermission;
添加完,整体文件如下:
// Standard extensions get all permissions by default grant codeBase "file:${{java.ext.dirs}}/*" { permission java.security.AllPermission; }; // default permissions granted to all domains grant { // Allows any thread to stop itself using the java.lang.Thread.stop() // method that takes no argument. // Note that this permission is granted by default only to remain // backwards compatible. // It is strongly recommended that you either remove this permission // from this policy file or further restrict it to code sources // that you specify, because Thread.stop() is potentially unsafe. // See the API specification of java.lang.Thread.stop() for more // information. permission java.lang.RuntimePermission "stopThread"; // allows anyone to listen on dynamic ports permission java.net.SocketPermission "localhost:0", "listen"; // "standard" properies that can be read by anyone permission java.util.PropertyPermission "java.version", "read"; permission java.util.PropertyPermission "java.vendor", "read"; permission java.util.PropertyPermission "java.vendor.url", "read"; permission java.util.PropertyPermission "java.class.version", "read"; permission java.util.PropertyPermission "os.name", "read"; permission java.util.PropertyPermission "os.version", "read"; permission java.util.PropertyPermission "os.arch", "read"; permission java.util.PropertyPermission "file.separator", "read"; permission java.util.PropertyPermission "path.separator", "read"; permission java.util.PropertyPermission "line.separator", "read"; permission java.util.PropertyPermission "java.specification.version", "read"; permission java.util.PropertyPermission "java.specification.vendor", "read"; permission java.util.PropertyPermission "java.specification.name", "read"; permission java.util.PropertyPermission "java.vm.specification.version", "read"; permission java.util.PropertyPermission "java.vm.specification.vendor", "read"; permission java.util.PropertyPermission "java.vm.specification.name", "read"; permission java.util.PropertyPermission "java.vm.version", "read"; permission java.util.PropertyPermission "java.vm.vendor", "read"; permission java.util.PropertyPermission "java.vm.name", "read"; //添加下面内容 permission java.security.AllPermission; };
再次运行jstatd
命令就不会报错了,命令如下:
./jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=172.16.120.12 &
三、远程连接
在windows系统中java安装目录中jdk/bin/
目录下的jvisualvm.exe
启动程序。双击启动。
点击确认,就连接成功了。文章来源:https://www.toymoban.com/news/detail-789343.html
文章来源地址https://www.toymoban.com/news/detail-789343.html
到了这里,关于JVM调优工具-VisualVM 远程连接服务器的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!