监视和管理远程会话

已完成

在此单元中,你将了解如何通过启用诊断日志和监视远程会话来管理远程会话。

配置诊断设置以生成审核日志

Azure Bastion 可以记录远程用户会话信息。 可以查看日志,以查看谁在何时、何处连接到哪些工作负载、以及其他相关日志记录信息。

若要生成这些日志,必须在 Azure Bastion 上配置诊断设置。 日志流式传输到存储帐户可能需要几个小时。 以下部分说明如何配置 Azure Bastion 诊断设置,以便稍后在你自己的订阅中尝试此设置。

为 Azure Bastion 启用诊断

在 Azure Bastion 资源的“监视”下添加诊断设置。 你需要一个将日志流式传输到的存储帐户。 如果你还没有存储帐户,请先创建一个,然后在你自己的订阅中尝试执行这些步骤。

  1. Azure 门户中,搜索或选择“Bastion”。

  2. 选择 Azure Bastion 资源。

  3. 在“监视”下,选择“诊断设置” 。

  4. 选择“添加诊断设置”。

    Screenshot that shows the Add diagnostic settings link within the Diagnostics settings page.

  5. 为“诊断设置名称”输入名称。

  6. 在“日志”下,选中“Bastion 审核日志”框

  7. 在“目标详细信息”下,选择“发送到 Log Analytics”和“存档到存储帐户”。

  8. 位置、订阅和存储帐户会自动填充。 请确保存储帐户与 Azure Bastion 资源位于同一区域。

    Screenshot that shows the Diagnostics setting page filled out.

  9. 选择“保存”。

  10. 保存完成后,关闭页面。

查看诊断日志

诊断日志需要几个小时才能显示在你的存储帐户中。 可以在存储帐户的“容器”下找到它们。

Screenshot of a storage account with a container called insights-logs-bastionauditlogs.

向下钻取资源层次结构文件夹,以转到 Azure Bastion 主机文件。

Screenshot of the insights logs for Azure Bastion that shows the folder location level is at the Azure Bastion host resource.

继续向下钻取“年 (y=)”、“月 (m=)”、“日 (d=)”、“小时 (h=)”和“分钟 (m=)”文件夹,以查找特定时间段的诊断日志数据。

Screenshot of the insights logs for Azure Bastion that shows the J S O N file for a specific time period.

下载 .json 文件以查看会话详细信息。 打开该文件时,它将如以下示例所示。 在此示例中,可以看到操作类型、用户名和客户端 IP 地址等信息。

{ 
"time":"2020-10-22T23:26:00.697Z",
"resourceId":"/SUBSCRIPTIONS/<subscripionID>/RESOURCEGROUPS/MYBASTION/PROVIDERS/MICROSOFT.NETWORK/BASTIONHOSTS/MYBASTION-BASTION",
"operationName":"Microsoft.Network/BastionHost/connect",
"category":"BastionAuditLogs",
"level":"Informational",
"location":"westus2",
"properties":{ 
   "userName":"<username>",
   "userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36",
   "clientIpAddress":"131.107.159.86",
   "clientPort":24039,
   "protocol":"ssh",
   "targetResourceId":"/SUBSCRIPTIONS/<subscripionID>/RESOURCEGROUPS/MYBASTION/PROVIDERS/MICROSOFT.COMPUTE/VIRTUALMACHINES/LINUX-KEY",
   "subscriptionId":"<subscripionID>",
   "message":"Successfully Connected.",
   "resourceType":"VM",
   "targetVMIPAddress":"172.16.1.5",
   "tunnelId":"<tunnelID>"
},
"FluentdIngestTimestamp":"2020-10-22T23:26:00.0000000Z",
"Region":"westus2",
"CustomerSubscriptionId":"<subscripionID>"
}

管理当前远程会话

通过 Azure Bastion 会话监视可以查看哪些用户连接到了哪些虚拟机。 它显示用户从其连接的 IP、连接的时间以及连接时间。 你可以选择正在进行的会话,并强制断开会话连接以断开用户与会话的连接。

Screenshot of the Azure Bastion sessions page with the delete option selected for one of the two sessions.

你将在下一个单元中演练如何管理远程会话。