你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

连接到应用实例进行故障排除

注意

Azure Spring Apps 是 Azure Spring Cloud 服务的新名称。 虽然该服务有新名称,但一些地方仍会使用旧名称,我们仍在更新屏幕截图、视频和图形等资产。

本文适用于:✔️ 基本版/标准版 ✔️ 企业版

本文介绍如何访问应用程序实例中的 shell 环境以进行高级故障排除。

尽管 Azure Spring Apps 提供了多种托管式故障排除方法,但你可能希望使用 shell 环境进行高级故障排除。 例如,你可能想要完成以下故障排除任务:

  • 直接使用 Java 开发工具包 (JDK) 工具。
  • 对虚拟网络和非虚拟网络实例的网络连接应用后端服务和 API 调用延迟进行诊断。
  • 诊断存储容量、性能和 CPU/内存问题。

先决条件

  • 带有 Azure Spring Apps 扩展的 Azure CLI。 使用以下命令删除以前的版本,并安装最新的扩展。 如果以前安装了 spring-cloud 扩展,请卸载它以避免配置和版本不匹配。

    az extension remove --name spring
    az extension add --name spring
    az extension remove --name spring-cloud
    
  • Azure Spring Apps 中部署的应用程序。

  • 如果已部署自定义容器,则需要一个 shell 程序。 默认为 /bin/sh

分配 Azure 角色

在连接到应用实例之前,必须具有 Azure Spring Apps 连接角色。 连接到应用实例需要数据操作权限 Microsoft.AppPlatform/Spring/apps/deployments/connect/action

可以使用 Azure 门户或 Azure CLI 分配 Azure 角色。

按照以下步骤使用 Azure 门户分配 Azure 角色。

  1. 打开 Azure 门户

  2. 打开现有 Azure Spring Apps 服务实例。

  3. 从左侧菜单中选择“访问控制 (IAM)”。

  4. 在命令栏中,依次选择“添加”、“添加角色分配”。

    Screenshot of the Access Control(IAM) page showing the Add role assignment command.

  5. 在列表中搜索“Azure Spring Apps 连接角色”,然后选择“下一步”。

    Screenshot of the Add role assignment page showing the Azure Spring Apps Connect Role.

  6. 选择“选择成员”,然后搜索你的用户名。

  7. 选择“查看 + 分配”。

连接到应用实例

可以使用 Azure 门户或 Azure CLI 连接到应用实例。

使用以下步骤通过 Azure 门户连接到应用实例。

  1. 打开 Azure 门户

  2. 打开现有 Azure Spring Apps 服务实例。

  3. 从左侧菜单中选择“应用”,然后选择一个应用。

  4. 从左侧菜单中选择“控制台”。

  5. 选择一个应用程序实例。

    Screenshot of the Azure portal Console page showing an app instance.

  6. 选择或输入要在容器中运行的 shell。

    Screenshot of the Azure portal Console page showing a Custom Shell entry.

  7. 选择“连接” 。

    Screenshot of the Azure portal Console page showing the Connect command.

对应用实例进行故障排除

连接到应用实例后,可以检查堆内存的状态。

使用以下命令查找 Java 进程 ID(通常为 1):

jps

输出应如以下示例所示:

Screenshot showing the output of the jps command.

然后使用以下命令运行 JDK 工具来检查结果:

jstat -gc 1

输出应如以下示例所示:

Screenshot showing the output of the jstat command.

断开与应用实例的连接

完成故障排除后,使用 exit 命令断开与应用实例的连接,或按 Ctrl+d

故障排除工具

以下列表介绍了可用于故障排除的一些预安装工具:

  • lsof - 列出打开的文件。
  • top - 显示系统摘要信息和当前利用率。
  • ps - 获取正在运行的进程的快照。
  • netstat - 输出网络连接和接口统计信息。
  • nslookup - 以交互方式查询 Internet 名称服务器。
  • ping - 测试是否可以访问网络主机。
  • nc - 使用 TCP 或 UDP 从/向网络连接进行读取和写入。
  • wget - 用于下载文件以及与 REST API 交互。
  • df - 显示可用的磁盘空间量。

还可以使用 JDK 捆绑的工具,例如 jpsjcmdjstat

以下列表显示了可用的工具,具体取决于你的服务计划和应用部署类型:

  • 源代码、JAR 和生成工具部署:
    • 基本、标准以及标准消耗和专用计划:
      • 常用工具 - 是
      • JDK 工具 - 是,仅适用于 Java 工作负载。
    • 企业计划:
      • 常用工具 - 取决于你在生成器中选择的 OS 堆栈。 是的,适用于完整的 OS 堆栈。 否,对于基本 OS 堆栈。
      • JDK 工具 - 是,仅适用于 Java 工作负载。
  • 自定义映像部署:取决于映像中已安装的工具集。

注意

JDK 工具未包含在“源代码”部署类型的路径中。 在运行任何 JDK 命令之前运行 export PATH="$PATH:/layers/tanzu-buildpacks_microsoft-openjdk/jdk/bin"

限制

在应用程序实例中使用 shell 环境时存在以下限制:

  • 由于应用是以非 root 用户身份运行的,因此你无法执行某些需要 root 权限的操作。 例如,无法使用系统包管理器 apt / yum 安装新工具。

  • 由于禁止某些 Linux 功能,因此需要特殊权限的工具(例如 tcpdump)无法正常运行。

后续步骤