> java远程调优可采用两种方式进行连接,`jmx`与`jstatd`,此文演示如何配置`jmx`进行连接调优。
## 配置指南
|配置|功能|值|备注|
|---|---|---|---|
|-Dcom.sun.management.jmxremote.authenticate|connection authenticate|true / false||
|-Dcom.sun.management.jmxremote.port|jmx connection remote port|1~65535||
|-Dcom.sun.management.jmxremote.local.only|remote can connection|true / false||
|-Dcom.sun.management.jmxremote.ssl|enable ssl connection|true / false||
|-Djava.rmi.server.hostname|multi eth choose|ip / domain||
|-Dcom.sun.management.jmxremote.access.file|remote access roles|file path||
|-Dcom.sun.management.jmxremote.password.file|remote authenticate file when auth config enable|file path||
## Demo1
不启用认证
```
java \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.port=5555 \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.rmi.server.hostname=test.domain.dounine.com \
-jar test-jar-1.0.jar
```
## Demo2
启用用户认证
```
java \
-Dcom.sun.management.jmxremote.authenticate=true \
-Dcom.sun.management.jmxremote.port=5555 \
-Dcom.sun.management.jmxremote.access.file=./jmxremote.access \
-Dcom.sun.management.jmxremote.password.file=./jmxremote.password \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.rmi.server.hostname=test.domain.dounine.com \
-jar test-jar-1.0.jar
```
编辑`./jmxremote.access`权限文件
```
dounine readwrite
```
编辑`./jmxremote.password`密码文件
```
dounine 你的密码
```
增加访问权限
```
chmod 400 ./jmxremote.access
chmod 400 ./jmxremote.password
```
启动`jvisualvm`或者`jconsole`
```
jvisualvm
# 或者
jconsole
```
## jvisualvm
添加远程主机地扯
![](http://upload-images.jianshu.io/upload_images/9028759-fe64a8144023405a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
添加`jmx`端口
![](http://upload-images.jianshu.io/upload_images/9028759-9f4db411d414b74b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
授权配置
![](http://upload-images.jianshu.io/upload_images/9028759-1fe88e88e8a8291c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
已连接视图
![](http://upload-images.jianshu.io/upload_images/9028759-96785e80eb4bf1ea.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
---
![](https://upload-images.jianshu.io/upload_images/9028759-5619fe0d9edd7a1b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)