开启JMX远程监控

参考:

1. 启动参数

java -server -Xms256M -Xmx256M -Xss256K   -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=256M  -Dfile.encoding=UTF-8 -Dsun.jun.encoding=UTF-8  -Djava.security.egd=file:/dev/./urandom  -Dio.netty.leakDetectionLevel=advanced  -Dcom.sun.management.jmxremote=true  -Dcom.sun.management.jmxremote.rmi.port=1919  -Dcom.sun.management.jmxremote.port=1919  -Dcom.sun.management.jmxremote.ssl=false  -Dcom.sun.management.jmxremote.authenticate=true  -Dcom.sun.management.jmxremote.local.only=false  -Dcom.sun.management.jmxremote.access.file=/etc/jmx/jmxremote.access  -Dcom.sun.management.jmxremote.password.file=/etc/jmx/jmxremote.password  -Djava.rmi.server.hostname=服务器公网ip  -jar foo.jar

2. authenticate文件配置

jmxremote.access 

guest readonly admin readwrite

jmxremote.password   

guest guestpwd admin adminpwd

注意: 文件(jmxremote.access, jmxremote.password)内容不能有注释

文件授权

chmod 600 jmxremote.access 
chmod 600 jmxremote.password 
chown root:root jmxremote.access 
chown root:root jmxremote.password
注意不能随便改, chmod 777都不行 否则启动会报错
Error: Password file read access must be restricted: /etc/jmx/jmxremote.password sun.management.AgentConfigurationError  at sun.management.jmxremote.ConnectorBootstrap.checkPasswordFile(ConnectorBootstrap.java:577) at sun.management.jmxremote.ConnectorBootstrap.startRemoteConnectorServer(ConnectorBootstrap.java:426) at sun.management.Agent.startAgent(Agent.java:262) at sun.management.Agent.startAgent(Agent.java:452)

jvisualvm连接

开启JMX远程监控_第1张图片

你可能感兴趣的:(java,linux)