使用 Terraform 方案來部署 VMware Ubuntu 虛擬機,並將其連線至 Azure Arc

本文提供使用提供的 Terraform 計劃來部署 Ubuntu 伺服器、VMware vSphere 虛擬機,並將其連線為已啟用 Azure Arc 的伺服器資源的指導。

必要條件

  1. 複製 Azure Arc Jumpstart 存放庫。

    git clone https://github.com/microsoft/azure_arc.git
    
  2. 將 Azure CLI 安裝或更新為 2.7 版和更新版本。 使用下列命令來檢查您目前的已安裝版本。

    az --version
    
  3. 安裝 Terraform >= 0.12

  4. 具有 從 vSphere Web 用戶端範本部署 虛擬機之許可權的 VMware vCenter Server 使用者。

  5. 建立 Azure 服務主體。

    若要將 VMware vSphere 虛擬機連線至 Azure Arc,則需要指派參與者角色的 Azure 服務主體。 若要建立它,請登入您的 Azure 帳戶,然後執行下列命令。 您也可以在 Azure Cloud Shell執行此命令。

    az login
    az account set -s <Your Subscription ID>
    az ad sp create-for-rbac -n "<Unique SP Name>" --role contributor --scopes "/subscriptions/<Your Subscription ID>"
    

    例如:

    az ad sp create-for-rbac -n "http://AzureArcServers" --role contributor --scopes "/subscriptions/00000000-0000-0000-0000-000000000000"
    

    輸出應該看起來像這樣:

    {
      "appId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "displayName": "http://AzureArcServers",
      "password": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      "tenant": "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    }
    

    注意

    強烈建議您將服務主體的範圍設定為特定的 Azure 訂用帳戶和資源群組

準備Ubuntu伺服器 VMware vSphere VM 樣本

使用本指南部署Ubuntu伺服器 VM 並將其連線到 Azure Arc 之前,需要 VMware vSphere 範本。 本文 說明如何使用 VMware vSphere 6.5 和更新版本輕鬆地建立這類範本。

注意

如果您已經有Ubuntu伺服器 VM 樣本,您仍應使用本指南作為參考。

部署

在執行 Terraform 方案之前,您必須設定計劃將使用的環境變數。 這些變數是以您剛才建立的 Azure 服務主體、您的 Azure 訂用帳戶和租使用者,以及 VMware vSphere 認證為基礎。

  1. 使用 命令擷取您的 Azure 訂用帳戶標識碼和租用戶 az account list 標識碼。

  2. Terraform 方案會在 Microsoft Azure 和 VMware vSphere 中建立資源。 接著,它會在虛擬機上執行腳本,以安裝 Azure Arc 代理程式和所有必要的成品。 此腳本需要 VMware vSphere 和 Azure 環境的特定資訊。 使用適當的值編輯 scripts/vars.sh 和更新每個變數。

    • TF_VAR_subscription_id = 您的 Azure 訂用帳戶識別碼
    • TF_VAR_client_id = 您的 Azure 服務主體名稱
    • TF_VAR_client_secret= 您的 Azure 服務主體密碼
    • TF_VAR_tenant_id = 您的 Azure 租使用者識別碼
    • TF_VAR_resourceGroup = Azure 資源組名
    • TF_VAR_location = Azure 區域
    • TF_VAR_vsphere_user = vCenter 管理員用戶名稱
    • TF_VAR_vsphere_password = vCenter 管理員密碼
    • TF_VAR_vsphere_server = vCenter Server FQDN/IP
    • TF_VAR_admin_user =OS 系統管理員用戶名稱
    • TF_VAR_admin_password = OS 系統管理員密碼
  3. 從 CLI,瀏覽至 azure_arc_servers_jumpstart/vmware/ubuntu/terraform 複製存放庫的目錄。

  4. 使用source命令執行 scripts/vars.sh 來匯出您編輯的環境變數,如下所示。 Terraform 需要設定這些項目,計劃才能正確執行。 請注意,此腳本也會在 Terraform 部署中從遠端在虛擬機上自動執行。

    source ./scripts/vars.sh

  5. 除了您剛導出的 TF_VAR 環境變數之外,請編輯 中的 terraform.tfvars Terraform 變數,以符合您的 VMware vSphere 環境。

    A screenshot of the TF_VAR environment variables

  6. terraform init執行命令,以下載 Terraform AzureRM、本機和 vSphere 提供者。

    A screenshot of the terraform init command.

  7. terraform apply --auto-approve執行 命令,並等候計劃完成。

  8. 完成 Terraform 部署之後,新的 Ubuntu 伺服器 VM 將會啟動並執行,並投影為新建立 Azure 資源群組中已啟用 Azure Arc 的伺服器資源。

    A screenshot of terraform apply completed.

    A screenshot of a new VMware vSphere Ubuntu server virtual machine.

    A screenshot of an Azure Arc-enabled server in an Azure resource group.

    Another screenshot of an Azure Arc-enabled server in an Azure resource group.

刪除部署

  • 最簡單的方式是透過 Azure 入口網站 刪除 Azure Arc 資源,只要選取資源並加以刪除。 此外,請刪除 VMware vSphere VM。

    A screenshot of an Azure Arc-enabled server being deleted.

    如果您手動刪除實體,則也應該刪除 install_arc_agent.shTerraform 方案所建立的 。

  • 如果您想要卸除整個環境,請使用 terraform destroy --auto-approve 命令,如下所示。

    A screenshot of the terraform destroy command.