一、问题概述

参考前一篇:

jvisualvm连接远程应用终于成功,附踩大坑记录!!(一:jstatd方式)

这篇主要讲讲jmx方式。

二、启动前设置jmx参数

我这边拿tomcat举例,其余java应用只会比它更简单,读者可以自行尝试下。

在tomcat的bin目录下,创建setenv.sh(文件名不能错,这个是tomcat提供的一个定制参数的钩子,名字不同就找不到了)

内容如下:

#!/bin/sh
JAVA_OPTS="$JAVA_OPTS -Xmx1024m -Djava.rmi.server.hostname=192.168.19.114 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9998 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

其中,

-Djava.rmi.server.hostname=192.168.19.114 ---------------- 192.168.19.114为tomcat所在机器的ip地址。
-Dcom.sun.management.jmxremote ----------------- 开启jmx,jdk1.5之前还要手动开启,现在已经默认开启了,所以可以省略

-Dcom.sun.management.jmxremote.port=9998 -------------------jmx的端口
-Dcom.sun.management.jmxremote.authenticate=false ---------------- 不开启验证

-Dcom.sun.management.jmxremote.ssl=false ----------------------不开启ssl通信

配置好了之后,正常启动应用即可。接下来验证是否可以连接。

除了上面几个参数,oralce官方(jdk1.8版本)还公布了其他的相关参数,如下:

Table 2-1 Out-of-the-Box Monitoring and Management Properties
Property Description Values

com.sun.management.jmxremote

Enables the JMX remote agent and local monitoring via a JMX connector published on a private interface used by JConsole and any other local JMX clients that use the Attach API. JConsole can use this connector if it is started by the same user as the user that started the agent. No password or access files are checked for requests coming via this connector.

true / false. Default is true.

com.sun.management.jmxremote. port

Enables the JMX remote agent and creates a remote JMX connector to listen through the specified port. By default, the SSL, password, and access file properties are used for this connector. It also enables local monitoring as described for the com.sun.management.jmxremote property.

Port number. No default.

com.sun.management.jmxremote. registry.ssl

Binds the RMI connector stub to an RMI registry protected by SSL.

true / false. Default is false.

com.sun.management.jmxremote. ssl

Enables secure monitoring via SSL. If false, then SSL is not used.

true / false. Default is true.

com.sun.management.jmxremote. ssl.enabled.protocols

A comma-delimited list of SSL/TLS protocol versions to enable. Used in conjunction with com.sun.management.jmxremote.ssl.

Default SSL/TLS protocol version.

com.sun.management.jmxremote. ssl.enabled.cipher.suites

A comma-delimited list of SSL/TLS cipher suites to enable. Used in conjunction with com.sun.management.jmxremote.ssl.

Default SSL/TLS cipher suites.

com.sun.management.jmxremote. ssl.need.client.auth

If this property is true and the property com.sun.management.jmxremote.ssl is also true, then client authentication will be performed.

It is recommended that you set this property to true.

true / false. Default is false.

com.sun.management.jmxremote. authenticate

If this property is false then JMX does not use passwords or access files: all users are allowed all access.

true / false. Default is true.

com.sun.management.jmxremote. password.file

Specifies location for password file. If com.sun.management.jmxremote.authenticate is false, then this property and the password and access files are ignored. Otherwise, the password file must exist and be in the valid format. If the password file is empty or nonexistent, then no access is allowed.

JRE_HOME/lib/management/ jmxremote.password

com.sun.management.jmxremote. access.file

Specifies location for the access file. If com.sun.management.jmxremote.authenticate is false, then this property and the password and access files are ignored. Otherwise, the access file must exist and be in the valid format. If the access file is empty or nonexistent, then no access is allowed.

JRE_HOME/lib/management/ jmxremote.access

com.sun.management.jmxremote.login.config

Specifies the name of a Java Authentication and Authorization Service (JAAS) login configuration entry to use when the JMX agent authenticates users. When using this property to override the default login configuration, the named configuration entry must be in a file that is loaded by JAAS. In addition, the login modules specified in the configuration should use the name and password callbacks to acquire the user's credentials. For more information, see the API documentation forjavax.security.auth.callback.NameCallback and javax.security.auth.callback.PasswordCallback.

Default login configuration is a file-based password authentication.

链接如下:

https://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html#gdeum

三、设置setenv.sh的可执行权限

[root@localhost bin]# chmod +x setenv.sh
[root@localhost bin]# pwd
/home/apache-tomcat-8.5./bin
[root@localhost bin]# ll setenv.sh
-rwxr-xr-x root root Mar : setenv.sh
[root@localhost bin]# pwd
/home/apache-tomcat-8.5./bin
// 添加可执行权限
[root@localhost bin]# chmod +x setenv.sh

然后启动startup.sh来启动tomcat。

等待tomcat启动后,查看9998端口是否开启:

netstat -nltp

三、本机visualvm进行连接

参考前一篇,在本机的visualvm上,依然是失败的。

四、换台机器试试

五、jconsole连接

更新于2020-3-13,

今天被同事问到这个,于是用jconsole也试了下,发现可以连接:

六、结论

依然是,遇到bug不要怕,换个客户端,不行就换台机器试试

jvisualvm连接远程应用终于成功,附踩大坑记录!!(二:jmx方式)的更多相关文章

  1. jvisualvm连接远程应用终于成功,附踩大坑记录!!(一:jstatd方式)

    一.问题概述 连接远程java应用除了jstatd方式,还有jmx方式.不必拘泥于一种,一种不行可以果断尝试另一种,兴许就行了. 姊妹篇在这: jvisualvm连接远程应用终于成功,附踩大坑记录!! ...

  2. VUE使用微信JDK(附踩坑记录)

    VUE使用微信分享SDK(附踩坑记录) 微信分享官方文档 安装JS-SDK npm i -S weixin-jsapi 引入包 ES5 写法 const wx = require('weixin-js ...

  3. 我用EasyExcel优化了公司的导出(附踩坑记录)

    背景介绍 最近要改一个导出的功能,在原有的基础上,在导出一份明细数据,要求导出内容加在原有 excel 的第二个 sheet 上.考虑到数据量还比较大,干脆引入阿里的 EasyExcel 来做. 下面 ...

  4. Spring Cloud Feign踩坑记录(二)

    注意,以下的Feign遇到的坑,在高版本中有些已经修复. 某些项目由于历史包袱原因,无法进行全面升级,才需要修补这些坑. 1.启动报错:not annotated with HTTP method t ...

  5. React-Native踩坑记录二

    1.Image组件的borderRadius画圆有平台兼容性问题,在IOS下会失效 解决方法有几种 (1)在外面包裹一层View,对View组件使用borderRadius就可以了,这是我的做法 (2 ...

  6. TF-GNN踩坑记录(二)

    引言 最近在尝试构建GraphTensor时,尝试把默认的特征名hidden_state改成其他时,出现了奇怪的报错. 报错 WARNING:tensorflow:Gradients do not e ...

  7. 用JvisualVM监视远程tomcat

    在tomcat的catcalina.sh 中java_opts 环境变量中添加以下参数: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmx ...

  8. jvisualvm_使用jmx连接远程linux应用

    [前提] JVisualVM是由Sun提供的性能分析工具,在Jdk6.0以后的版本中是自带的,如果是用Jdk1.5或以前版本的就得要单独安装了. [1]远程机器需要开启jmx 在使用jvisualvm ...

  9. jvisualvm_使用jstatd连接远程linux应用

    [1]确定linux系统正确安装了ssh # sudo ps -e | grep ssh ①注意使用root,使用$会报如下错误: [appadmin@webcsuat2 ~]$ sudo ps -e ...

随机推荐

  1. hdu 5086 Revenge of Segment Tree(BestCoder Round #16)

    Revenge of Segment Tree                                                          Time Limit: 4000/20 ...

  2. [转]Linux服务器上11种网络连接状态 和 TCP三次握手/四次挥手详解

    一.Linux服务器上11种网络连接状态: 图:TCP的状态机 通常情况下:一个正常的TCP连接,都会有三个阶段:1.TCP三次握手;2.数据传送;3.TCP四次挥手. 注:以下说明最好能结合”图:T ...

  3. LR进行接口测试

    其实无论用那种测试方法,接口测试的原理是通过测试程序模拟客户端向服务器发送请求报文,服务器接收请求报文后对相应的报文做出处理然后再把应答报文发送给客户端,客户端接收应答报文这一个过程. 方法一.用Lo ...

  4. phpcms首页如加上用户登录的信息?

    请看效果图 我用的是cookie的方法,请先打开discuz的文件 \source\function\function_member.php 找到函数function setloginstatus() ...

  5. [原]pomelo开发环境搭建

    pomelo基于nodejs服务器开源框架,比较牛逼的! 1.安装nodejs(官网下载地址) 安装python等 具体见官网说明 2.安装pomelo(见官方步骤)或者 http://blog.cs ...

  6. Git初级使用教程

    什么是 Git? Git 是一款免费的.开源的.分布式的版本控制系统.旨在快速高效地处理无论规模大小的任何软件工程. 每一个 Git克隆 都是一个完整的文件库,含有全部历史记录和修订追踪能力,不依赖于 ...

  7. Eclipse------使用Maven install出错:编码GBK的不可映射字符

    使用Maven install时报错:编码GBK的不可映射字符 原因:Maven默认使用GBK进行编码 解决方法: 在pom.xml文件中添加如下代码即可 <project> <pr ...

  8. Git------如何使用Git Bash Here提交代码

    转载:码云帮助文档地址 http://git.mydoc.io/?t=154712 1.打开“Git Bash Here” 2.输入: ssh-keygen -t rsa -C "xxxxx ...

  9. My Apple Developer Library Catalog

    Objective-C & Memory Management:Programming with Objective-CConcepts in Objective-C ProgrammingM ...

  10. 【GIS】Cesium GLTF

    cd D:\GISSoft\3DsMax2017\COLLADA2GLTF-v2.1.4-windows-Release-x64 COLLADA2GLTF-bin.exe -f tree05.DAE ...