使用 Azure CLI 針對 VPN 虛擬網路閘道和連線進行疑難排解
在本文中,您將了解如何使用網路監看員 VPN 疑難排解功能來診斷 VPN 虛擬網路閘道及其連線並進行疑難排解,以解決虛擬網路與內部部署網路之間的連線問題。 VPN 疑難排解要求是執行時間很長的要求,可能需要幾分鐘的時間才會傳回結果。 疑難排解記錄會儲存在指定儲存體帳戶的容器中。
必要條件
具有有效訂用帳戶的 Azure 帳戶。 免費建立帳戶。
已在虛擬網路閘道的區域中啟用網路監看員。 如需詳細資訊,請參閱啟用或停用 Azure 網路監看員。
虛擬網路閘道。 如需詳細資訊,請參閱支援的閘道類型。
Azure Cloud Shell 或 Azure CLI。
本文中的步驟會在 Azure Cloud Shell 中以互動方式執行 Azure CLI 命令。 若要在 Cloud Shell 中執行命令,請選取程式碼區塊右上角的 [開啟 Cloud Shell]。 選取 [複製] 以複製程式碼,並將它貼到 Cloud Shell 中以執行。 您也可以從 Azure 入口網站內執行 Cloud Shell。
您也可以在本機安裝 Azure CLI 以執行命令。 如果您在本機執行 Azure CLI,請使用 az login 命令登入 Azure。
使用現有儲存體帳戶進行疑難排解
在本節中,您會了解如何使用現有儲存體帳戶對 VPN 虛擬網路閘道或 VPN 連線進行疑難排解。
使用 az storage account show 來擷取儲存體帳戶的資源識別碼。 然後使用 az network watcher troubleshooting start 開始對 VPN 閘道進行疑難排解。
# Place the storage account ID into a variable.
storageId=$(az storage account show --name 'mystorageaccount' --resource-group 'myResourceGroup' --query 'id' --output tsv)
# Start VPN troubleshoot session.
az network watcher troubleshooting start --resource-group 'myResourceGroup' --resource 'myGateway' --resource-type 'vnetGateway' --storage-account $storageId --storage-path 'https://mystorageaccount.blob.core.windows.net/{containerName}'
疑難排解要求完成之後,系統會傳回良好或狀況不良,並有動作文字會提供如何解決問題的一般指導。 如果問題有可行動作,則會提供附有更多指導的連結。
此外,在您於上一個命令中指定的儲存體帳戶容器中也會儲存詳細記錄。 如需詳細資訊,請參閱記錄檔。 您可以使用儲存體總管或任何其他偏好方式來存取和下載記錄。 如需詳細資訊,請參閱開始使用儲存體總管。
使用新的儲存體帳戶進行疑難排解
在本節中,您會了解如何使用新的儲存體帳戶對 VPN 虛擬網路閘道或 VPN 連線進行疑難排解。
使用 az storage account create 和 az storage container create 分別建立新的儲存體帳戶和容器。 然後,使用 az network watcher troubleshooting start 開始對 VPN 閘道進行疑難排解。
# Create a new storage account.
az storage account create --name 'mystorageaccount' --resource-group 'myResourceGroup' --location 'eastus' --sku 'Standard_LRS'
# Get the storage account keys.
az storage account keys list --resource-group 'myResourceGroup' --account-name 'mystorageaccount'
# Create a container.
az storage container create --account-name 'mystorageaccount' --account-key {storageAccountKey} --name 'vpn'
# Start VPN troubleshoot session.
az network watcher troubleshooting start --resource-group 'myResourceGroup' --resource 'myGateway' --resource-type 'vnetGateway' --storage-account 'mystorageaccount' --storage-path 'https://mystorageaccount.blob.core.windows.net/vpn'
疑難排解要求完成之後,系統會傳回良好或狀況不良,並有動作文字會提供如何解決問題的一般指導。 如果問題有可行動作,則會提供附有更多指導的連結。
此外,在您於上一個命令中指定的儲存體帳戶容器中也會儲存詳細記錄。 如需詳細資訊,請參閱記錄檔。 您可以使用儲存體總管或任何其他偏好方式來存取和下載記錄。 如需詳細資訊,請參閱開始使用儲存體總管。