如何远程调试在Azure App Service上运行的Java应用程序

g52tjvyc  于 2023-05-15  发布在  Java
关注(0)|答案(3)|浏览(124)

当浏览到Settings > Configuration > General Settings时,微软非常清楚,它目前不支持远程调试(Linux应用程序服务计划,Java 11 SE)。

然而,我想知道是否还有方法可以以更手动的方式完成这一点。例如,我可以使用以下自定义启动命令打开调试端口。
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar /home/site/wwwroot/app.jar
请注意下面的日志,它指出它正在侦听5005/TCP。然而,正如预期的那样,这个监听端口没有被微软的基础设施转发。
此外,SSH只能通过浏览器使用,因此没有简单的方法通过像ssh user@mywebsite.azurewebsites.net -L 5005:localhost:5005这样转发来暴露该端口。
有没有其他的想法可以用Java实现远程调试会话?

2021-07-29T14:52:59.769816383Z: [INFO]    _____
2021-07-29T14:52:59.769851884Z: [INFO]    /  _  \ __________ _________   ____
2021-07-29T14:52:59.769857984Z: [INFO]   /  /_\  \___   /  |  \_  __ \_/ __ \
2021-07-29T14:52:59.769873185Z: [INFO]  /    |    \/    /|  |  /|  | \/\  ___/
2021-07-29T14:52:59.769878285Z: [INFO]  \____|__  /_____ \____/ |__|    \___  >
2021-07-29T14:52:59.924543150Z: [INFO]          \/      \/                  \/
2021-07-29T14:52:59.924549150Z: [INFO]  A P P   S E R V I C E   O N   L I N U X
[...]
2021-07-29T14:53:05.404068415Z: [INFO]  STARTUP_FILE=
2021-07-29T14:53:05.419701706Z: [INFO]  STARTUP_COMMAND=java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar /home/site/wwwroot/app.jar
2021-07-29T14:53:05.419807209Z: [INFO]  No STARTUP_FILE available.
2021-07-29T14:53:05.419822210Z: [INFO]  Running STARTUP_COMMAND: java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar /home/site/wwwroot/app.jar
2021-07-29T14:53:05.468409936Z: [ERROR]  Picked up JAVA_TOOL_OPTIONS: -Xmx1346M -Djava.net.preferIPv4Stack=true
2021-07-29T14:53:05.769742003Z: [INFO]  Listening for transport dt_socket at address: 5005
2021-07-29T14:53:15.032989100Z: [INFO]
2021-07-29T14:53:15.033937730Z: [INFO]    .   ____          _            __ _ _
2021-07-29T14:53:15.034646252Z: [INFO]   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
2021-07-29T14:53:15.035378475Z: [INFO]  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2021-07-29T14:53:15.035688785Z: [INFO]   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
2021-07-29T14:53:15.082402455Z: [INFO]    '  |____| .__|_| |_|_| |_\__, | / / / /
2021-07-29T14:53:15.082444656Z: [INFO]   =========|_|==============|___/=/_/_/_/
2021-07-29T14:53:15.082450956Z: [INFO]   :: Spring Boot ::                (v2.5.3)
2021-07-29T14:53:15.082455556Z: [INFO]
2021-07-29T14:53:15.874610379Z: [INFO]  2021-07-29 14:53:15.853  INFO 122 --- [           main] c.s.r.RemoteDebuggingDemo1Application    : Starting RemoteDebuggingDemo1Application using Java 11.0.7 on 16f2213f1d06 with PID 122 (/home/site/wwwroot/app.jar started by root in /)
2021-07-29T14:53:15.889931561Z: [INFO]  2021-07-29 14:53:15.889  INFO 122 --- [           main] c.s.r.RemoteDebuggingDemo1Application    : No active profile set, falling back to default profiles: default
2021-07-29T14:53:26.797375136Z: [INFO]  2021-07-29 14:53:26.796  INFO 122 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 80 (http)
2021-07-29T14:53:26.919083170Z: [INFO]  2021-07-29 14:53:26.918  INFO 122 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-07-29T14:53:26.921537347Z: [INFO]  2021-07-29 14:53:26.919  INFO 122 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.50]
2021-07-29T14:53:27.704270105Z: [INFO]  2021-07-29 14:53:27.703  INFO 122 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
[...]
cygmwpex

cygmwpex1#

实际上,通过SSH隧道,可以在Azue Linux AppService上远程调试Java应用程序。这在高级应用服务计划上进行了测试。不知何故,我从来没有发现一个文件表明,所以我们来看看:
1.将应用程序设置JAVA_OPTS添加到应用程序
agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:8000
1.使用azure cli创建远程连接,在您的计算机上创建SSH端口1234:
az webapp create-remote-connection -g RG -n MY_APP -p 1234
1.在appservice中创建一个从本地SSH端口到远程调试端口的ssh隧道
ssh -L 1235:127.0.0.1:8000 root@127.0.0.1 -p 1234
1.然后,您可以将所选的调试器附加到本地主机上的端口1235:(可能是eclipse,vscode,intellij)
jdb -attach 1235
隧道从您的计算机-> remote-connection通过az-cli -> SSH进入appservice -> remotedebug端口

lymgl2op

lymgl2op2#

远程调试选项:

  • runtime as java 11 + OS as linux --> No remote debugging available
  • runtime as java 8 + OS as linux --> No remote debugging available

如果将运行时用作Python + OS用作Linux,则可以选择启用远程调试。
基于复制,我们已经创建了一个运行时间为Java 7,8,11的Web应用程序,操作系统为Windows,无论应用程序服务计划是基本/标准/高级,您都可以选择启用远程调试。

kiz8lqtg

kiz8lqtg3#

无法在Azure Web应用程序上调试基于Java应用程序。你可以用.NET应用程序和VS代码来做。
使用SSL隧道提出的想法是一个有趣的想法。然而,它不起作用。我刚试过了。隧道可以设置,但显然Azure不荣誉远程端口,并会直接将您放入shell。因此您只能通过隧道连接到Java应用程序中进行SSH

相关问题