一、问题概述

参考前一篇:

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. 正则grep

    什么是正则: 正则就是一串有规律的字符串. 正则三剑客: grep/egrep (egrep是grep的扩展),sed, awk grep grep过滤指定关键词 [root@localhost gr ...

  2. Write operations are not allowed in read-only mode 只读模式下(FlushMode.NEVER/MANUAL)写操作不允

    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...

  3. [转]Linux内核源码详解--iostat

    Linux内核源码详解——命令篇之iostat 转自:http://www.cnblogs.com/york-hust/p/4846497.html 本文主要分析了Linux的iostat命令的源码, ...

  4. windows下卸载oracle11g

    oracle11g卸载   oracle11g卸载 卸载oracle: 1.开始--控制面板--性能和维护--管理工具--服务    停止所有的oracle服务. 2.开始--程序--oracle-- ...

  5. 《HTTP权威指南》学习笔记——URL和资源

    URL与资源 URL是互联网资源的标准化名称 1.浏览互联网资源 URL是浏览器寻找信息时所需的资源位置 URI是一类更通用的资源标识符,URL是它的子集. URI的两个子集:URL和URN URL提 ...

  6. Lua 中 number 转换各种进制,以及string串转number

    原文地址:http://blog.csdn.net/david_dai_1108/article/details/71699449 --region : NumConvert.lua --Date : ...

  7. Mac上csv导入mysql提示错误[Error Code] 1290 - The MySQL server is running with the --secure-file-priv option解决办法

    1.进入mysql查看secure_file_prive的值 $mysql -u root -p mysql>SHOW VARIABLES LIKE "secure_file_priv ...

  8. JSP判断闰年

    闰年条件: 能被4整除但不能被100整除 能被400整除 <%@ page language="java" import="java.util.*" co ...

  9. phpcms v9模板制作常用代码集合(转)

    phpcms v9模板制作常用代码集合(个人收藏) 1.截取调用标题长度 {str_cut($r[title],36,'')} 2.格式化时间 调用格式化时间 2011-05-06 11:22:33 ...

  10. [scala] scala 集合(⑧)

    1.List 基础操作 2.Set 基础操作 3. TreeSet 排序Set 4. 拉链操作 5. 流 import scala.collection.immutable.TreeSet impor ...