配置远程机器
1、 打开对应tomcat脚本
[root@l-noahcef39gzl1.auto.beta.cn0 /home/q/www]# cat /home/q/www/pangolin_pay.qunar.com/startenv.sh
/"*******************下面是命令执行结果*************************"/
#!/bin/sh
export TOMCAT_USER="tomcat"
export JAVA_OPTS="-Ddubbo.reference.check=false -Xms1024m -Xmx2048m -XX:NewSize=256m -XX:PermSize=256m -server -XX:+DisableExplicitGC -Dqunar.logs=$CATALINA_BASE/logs -Dqunar.cache=$CATALINA_BASE/cache -verbose:g
c -XX:+PrintGCDateStamps -XX:+PrintGCDetails -Xloggc:$CATALINA_BASE/logs/gc.log -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=31990"
chown -R tomcat:tomcat $CATALINA_BASE/logs
chown -R tomcat:tomcat $CATALINA_BASE/cache
chown -R tomcat:tomcat $CATALINA_BASE/conf
chown -R tomcat:tomcat $CATALINA_BASE/work
chown -R tomcat:tomcat $CATALINA_BASE/temp
2、 如上,如果存在address,则获取到了端口号,之间链接即可。
3、 如上,如果不存在address,则在“export JAVA_OPTS”中,插入
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=31990
4、 restart
[root@l-noahcef39gzl1.auto.beta.cn0 /home/q/www]# sh /home/***/restart_tomcat.sh ***.com/
/"*******************下面是命令执行结果**********************"/
/home/***/start_tomcat.sh ***.com start succeed
配置Idea
(1)在idea中, “edit Configurations” => “+” => “Remote” => Host:”改为debug目标机器的ip地址” => Port:”startenv.sh中的端口号”
(2)配置好idea后,本地需要打开与服务器所运行程序一致的程序,然后即可在本地代码中打断点,调试服务器上正在运行的程序。
特别注意
1、 debug之后,记得删除-Xdebug这一串,否则有安全风险
2、 现在一般不这么直接debug,很容易被安全组发邮件。使用socat作为媒介。
socat debug
// 增加配置
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=127.0.0.1:31990
// socat开启转发
socat TCP4-LISTEN:50001,fork,range=10.86.144.71/32 TCP4:127.0.0.1:31990
1、 打开debug,支持127.0.0.1:31990的访问
2、 socat监听50001端口的TCP4访问,范围是10.86.144.71(就是本机的ip),转发到TCP4:127.0.0.1:31990
3、 fork是说每次新的链接,复制新的监听