1. 新建一个springboot项目
@RestController
@SpringBootApplication
public class AppApplication {
public static void main(String[] args) {
ConfigurableApplicationContext ctx = SpringApplication.run(AppApplication.class);
}
@RequestMapping("/hello")
public String hello(){
return "hello";
}
}
2. maven打成jar包并传入CentOS7服务器
app.jar
3. 修改jdk中jmxremote.password
cd jdk1.8.0_231\jre\lib\management
cp jmxremote.password.template jmxremote.password
vi jmxremote.password
monitorRole QED
controlRole R&D
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201101190358871.png#pic_center)
chmod +w jmxremote.password
chmod 0400 jmxremote.password
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201101190427106.png#pic_center)
4. 启动程序
export JAVA_OPTS='-Djava.rmi.server.hostname=192.168.1.101 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8888 -Dcom.sun.management.jmxremote.rmi.port=8888 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=false'
-Dcom.sun.management.jmxremote.port=8888 //连接端口
-Dcom.sun.management.jmxremote.rmi.port=8888
-Dcom.sun.management.jmxremote.authenticate=true //需要密码登陆
-Dcom.sun.management.jmxremote.ssl=false //不需要安全证书
-Djava.rmi.server.hostname=192.168.1.101 //这个ip是自己服务器的ip
5. 启动程序
java $JAVA_OPTS -jar app.jar
6. 用jconsole远程连接进程
本地计算机(这里是window10系统)jdk的bin目录下(jdk1.8.0_231\bin), 有个jconsole.exe文件,双击打开
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201101190510401.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2praWhpX2xpbg==,size_16,color_FFFFFF,t_70#pic_center)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201101190559456.png#pic_center)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201101190615792.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2praWhpX2xpbg==,size_16,color_FFFFFF,t_70#pic_center)
- 如果还是连接失败, 则考虑是不是服务器的防火墙8888端口没有放开