简体   繁体   English

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

[英]How to remote debug a java application running on Azure App Service

When browsing to Settings > Configuration > General Settings Microsoft is pretty clear in that it currently doesn't support remote debugging (Linux App Service Plan, Java 11 SE).当浏览到Settings > Configuration > General Settings时,Microsoft 非常清楚它目前不支持远程调试(Linux 应用服务计划,Java 11 SE)。

在此处输入图像描述

However, I was wondering if there still is way to accomplish this, in a more manual fashion.但是,我想知道是否还有办法以更手动的方式完成此操作。 Eg I am able to open up a debugging port with the following custom startup command.例如,我可以使用以下自定义启动命令打开调试端口。

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar /home/site/wwwroot/app.jar

Notice the log below, that states it is listening on 5005/TCP.请注意下面的日志,表明它正在侦听 5005/TCP。 As expected, however, this listening port is not getting forwarded by Microsoft's infrastructure.但是,正如预期的那样,Microsoft 的基础结构不会转发此侦听端口。

Also, SSH is only available via browser, so there is no easy way to expose that port by forwarding it like so ssh user@mywebsite.azurewebsites.net -L 5005:localhost:5005 .此外,SSH 只能通过浏览器使用,因此没有像ssh user@mywebsite.azurewebsites.net -L 5005:localhost:5005这样转发它来公开该端口的简单方法。

Any other idea how a remote debugging session might be achieved with Java?任何其他想法如何使用 Java 实现远程调试 session?

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
[...]

It is actually possible to remote debug a Java application on Azue Linux AppService, by tunneling through SSH. This was tested on premium App Service Plans.实际上,可以通过 SSH 隧道在 Azue Linux AppService 上远程调试 Java 应用程序。这已在高级应用程序服务计划上进行了测试。 Somehow I never found a documentation suggesting that, so here we go:不知何故,我从来没有找到建议的文档,所以我们在这里 go:

  1. You add an application setting JAVA_OPTS to your app您将应用程序设置JAVA_OPTS添加到您的应用程序

agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:8000

  1. Create a remote-connection with azure cli, that creates a SSH port 1234 on your computer:使用 azure cli 创建一个远程连接,在您的计算机上创建一个 SSH 端口 1234:

    az webapp create-remote-connection -g RG -n MY_APP -p 1234

  2. Create a ssh Tunnel from this local SSH port to the remote debugging port in the appservice在appservice中创建一个从这个本地SSH端口到远程调试端口的ssh Tunnel

    ssh -L 1235:127.0.0.1:8000 root@127.0.0.1 -p 1234

  3. You then can attach a debugger of your choice to the port 1235 on your local host: (Maybe eclipse, vscode, intellij)然后,您可以将您选择的调试器附加到本地主机上的端口 1235:(可能是 eclipse、vscode、intellij)

    jdb -attach 1235

The tunnel goes from your computer -> remote-connection via az-cli -> SSH into appservice -> remotedebug port in appservice隧道从您的计算机 -> 通过 az-cli 进行远程连接 -> SSH 进入应用服务 -> 应用服务中的 remotedebug 端口

Remote debugging options:远程调试选项:

  • runtime as java 11 + OS as linux --> No remote debugging available运行时为 java 11 + 操作系统为 linux --> 没有可用的远程调试
  • runtime as java 8 + OS as linux --> No remote debugging available运行时为 java 8 + 操作系统为 linux --> 没有可用的远程调试

if you use runtime as Python + OS as linux you have an option to enable remote debugging.如果您使用运行时作为 Python + OS 作为 linux,您可以选择启用远程调试。

Based on the repro we have created a web app with run time as Java 7,8,11 with operating system as windows irrespective of the app service plan either basic/standard/premium you have an option to enable the remote debugging.基于 repro,我们创建了一个运行时为 Java 7、8、11 的 Web 应用程序,操作系统为 Windows,无论应用程序服务计划是基本/标准/高级,您都可以选择启用远程调试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Java SDK 从我的远程 Azure 应用程序配置中检索服务总线队列的队列名称? - How can I retrieve the queue name for a service bus queue from my remote Azure App Configuration using the Java SDK? 如何在运行应用程序作为 windows 服务时登录到 azure 帐户? - How to login to azure account while running the application as windows service? 如何将服务结构应用程序部署到远程服务器? - How to deploy service fabric application to remote server? 我如何知道我的 Azure 应用服务正在运行的 IIS 和 Windows 是什么版本 - How do I tell what version of IIS and Windows my Azure App Service is running on 如何从运行在 Azure 的“应用服务”PaaS 上的 IIS 获取 HTTP500 的回溯? - How do I get a traceback of a HTTP500 from IIS running on Azure's "App Service" PaaS? azure 应用服务中的谷歌应用凭证(as.net core web api) - Google application credentials in azure app service (aspnet core web api) 在 Azure 上使用 PM2 运行 nextjs 时出错 在 Linux 上应用服务 - Error running nextjs with PM2 on Azure App Service on Linux Azure 应用程序服务为 Spring 引导返回 404 Java 8 based war - Azure app service returning 404 for Spring boot Java 8 based war 如何使用私有 Azure Container Registry 创建一个 Azure APP Service? - How to create a Azure APP Service with a private Azure Container Registry? 如何从 Azure 管道中的 Azure 应用服务获取价值 - How to get value from Azure App Service from Azure pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM