部署控制平面

SAP 部署自動化架構的控制平面部署包含:

  • 部署器
  • SAP 程式庫

Diagram that shows the control plane.

準備部署認證

SAP 部署自動化架構會使用服務主體進行部署。 若要為控制平面部署建立服務主體,請使用具有建立服務主體存取權限的帳戶:

az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/<subscriptionID>" --name="<environment>-Deployment-Account"
  

重要

服務主體的名稱必須是唯一的。

記錄命令的輸出值:

  • appId
  • password
  • tenant

選擇性地將下列權限指派給服務主體:

az role assignment create --assignee <appId> --role "User Access Administrator" --scope /subscriptions/<subscriptionID>

如果您想要僅提供範圍限定為資源群組的使用者存取管理員角色,請使用下列命令:


az role assignment create --assignee <appId> --role "User Access Administrator" --scope /subscriptions/<subscriptionID>/resourceGroups/<resourceGroupName>

部署控制平面

部署控制平面所需的所有成品都位於 GitHub 存放庫中。

使用下列命令複製存放庫來準備進行控制平面部署:

mkdir -p ~/Azure_SAP_Automated_Deployment; cd $_

git clone https://github.com/Azure/sap-automation.git sap-automation

git clone https://github.com/Azure/sap-automation-samples.git samples

範例部署器設定檔 MGMT-WEEU-DEP00-INFRASTRUCTURE.tfvars 位於 ~/Azure_SAP_Automated_Deployment/samples/Terraform/WORKSPACES/DEPLOYER/MGMT-WEEU-DEP00-INFRASTRUCTURE 資料夾中。

範例 SAP 程式庫設定檔 MGMT-WEEU-SAP_LIBRARY.tfvars 位於 ~/Azure_SAP_Automated_Deployment/samples/Terraform/WORKSPACES/LIBRARY/MGMT-WEEU-SAP_LIBRARY 資料夾中。

您可以複製設定檔範例,以開始測試部署自動化架構。

DEPLOYER 的最小 Terraform 檔案看起來可能如下列範例:

# The environment value is a mandatory field, it is used for partitioning the environments.
environment = "MGMT"
# The location/region value is a mandatory field, it is used to control where the resources are deployed
location = "westeurope"

# management_network_address_space is the address space for management virtual network
management_network_address_space = "10.10.20.0/25"
# management_subnet_address_prefix is the address prefix for the management subnet
management_subnet_address_prefix = "10.10.20.64/28"

# management_firewall_subnet_address_prefix is the address prefix for the firewall subnet
management_firewall_subnet_address_prefix = "10.10.20.0/26"
firewall_deployment = false

# management_bastion_subnet_address_prefix is the address prefix for the bastion subnet
management_bastion_subnet_address_prefix = "10.10.20.128/26"
bastion_deployment = true

# deployer_enable_public_ip controls if the deployer Virtual machines will have Public IPs
deployer_enable_public_ip = false

# deployer_count defines how many deployer VMs will be deployed
deployer_count = 1

# use_service_endpoint defines that the management subnets have service endpoints enabled
use_service_endpoint = true

# use_private_endpoint defines that the storage accounts and key vaults have private endpoints enabled
use_private_endpoint = false

# enable_firewall_for_keyvaults_and_storage defines that the storage accounts and key vaults have firewall enabled
enable_firewall_for_keyvaults_and_storage = false

# public_network_access_enabled controls if storage account and key vaults have public network access enabled
public_network_access_enabled = true

請記下 Terraform 變數檔案的位置,以便未來在部署期間進行編輯。

LIBRARY 的最小 Terraform 檔案看起來可能如下列範例:

# The environment value is a mandatory field, it is used for partitioning the environments, for example, PROD and NP.
environment = "MGMT"
# The location/region value is a mandatory field, it is used to control where the resources are deployed
location = "westeurope"

#Defines the DNS suffix for the resources
dns_label = "azure.contoso.net"

# use_private_endpoint defines that the storage accounts and key vaults have private endpoints enabled
use_private_endpoint = false

請記下 Terraform 變數檔案的位置,以便未來在部署期間進行編輯。

執行下列命令來建立部署器和 SAP 連結庫。 命令會將服務主體詳細資料新增至部署金鑰保存庫。

設定服務主體的環境變數:


export ARM_SUBSCRIPTION_ID="<subscriptionId>"
export       ARM_CLIENT_ID="<appId>"
export   ARM_CLIENT_SECRET="<password>"
export       ARM_TENANT_ID="<tenantId>"

執行下列命令以部署控制平面:


export            env_code="MGMT"
export         region_code="WEEU"
export           vnet_code="DEP00"

export DEPLOYMENT_REPO_PATH="${HOME}/Azure_SAP_Automated_Deployment/sap-automation"
export CONFIG_REPO_PATH="${HOME}/Azure_SAP_Automated_Deployment/WORKSPACES"
export SAP_AUTOMATION_REPO_PATH="${HOME}/Azure_SAP_Automated_Deployment/sap-automation"

az logout
az login --service-principal -u "${ARM_CLIENT_ID}" -p="${ARM_CLIENT_SECRET}" --tenant "${ARM_TENANT_ID}"

cd ~/Azure_SAP_Automated_Deployment/WORKSPACES


deployer_parameter_file="${CONFIG_REPO_PATH}/DEPLOYER/${env_code}-${region_code}-${vnet_code}-INFRASTRUCTURE/${env_code}-${region_code}-${vnet_code}-INFRASTRUCTURE.tfvars"
library_parameter_file="${CONFIG_REPO_PATH}/LIBRARY/${env_code}-${region_code}-SAP_LIBRARY/${env_code}-${region_code}-SAP_LIBRARY.tfvars"

${SAP_AUTOMATION_REPO_PATH}/deploy/scripts/deploy_controlplane.sh  \
    --deployer_parameter_file "${deployer_parameter_file}"         \
    --library_parameter_file "${library_parameter_file}"            \
    --subscription "${ARM_SUBSCRIPTION_ID}"                        \
    --spn_id "${ARM_CLIENT_ID}"                                    \
    --spn_secret "${ARM_CLIENT_SECRET}"                            \
    --tenant_id "${ARM_TENANT_ID}"

使用 Azure Bastion 手動將虛擬機器設定為 SDAF 部署器

若要連線到部署器:

  1. 登入 Azure 入口網站

  2. 移至包含部署器虛擬機器 (VM) 的資源群組。

  3. 使用 Azure Bastion 連線到 VM。

  4. 預設的使用者名稱為 azureadm

  5. 選取 [來自 Azure Key Vault 的 SSH 私密金鑰]

  6. 選取包含控制平面的訂用帳戶。

  7. 選取部署器金鑰保存庫。

  8. 從祕密清單中,選擇以 -sshkey 結尾的祕密。

  9. 連線至 VM。

執行下列指令碼以設定部署器:


mkdir -p ~/Azure_SAP_Automated_Deployment; cd $_

wget https://raw.githubusercontent.com/Azure/sap-automation/main/deploy/scripts/configure_deployer.sh -O configure_deployer.sh	
chmod +x ./configure_deployer.sh
./configure_deployer.sh

# Source the new variables

. /etc/profile.d/deploy_server.sh

指令碼會安裝 Terraform 和 Ansible,並設定部署器。

手動將虛擬機器設定為 SDAF 部署器

從可連線到 Azure 虛擬網路的電腦連線到部署器 VM。

若要連線到部署器:

  1. 登入 Azure 入口網站

  2. 選取或搜尋 [金鑰保存庫]

  3. 在 [金鑰保存庫] 頁面上,尋找部署器金鑰保存庫。 名稱開頭為 MGMT[REGION]DEP00user。 視需要依 [資源群組] 或 [位置] 進行篩選。

  4. 在左側窗格的 [設定] 區段上,選取 [祕密]

  5. 尋找並選取包括 sshkey 的祕密。 外觀如下:MGMT-[REGION]-DEP00-sshkey

  6. 在祕密的頁面上,選取目前的版本。 然後,複製 [祕密值]

  7. 開啟純文字編輯器。 複製 [祕密值]。

  8. 將檔案儲存至您存放 SSH 金鑰的位置。 例如 C:\Users\<your-username>\.ssh

  9. 儲存檔案。 如果系統提示您選擇 [存檔類型],請在 [SSH] 無法選取時,選取 [所有檔案]。 例如,使用 deployer.ssh

  10. 透過任何 SSH 用戶端 (例如 Visual Studio Code) 連線至部署器 VM。 使用部署器的私人 IP 位址,以及您所下載的 SSH 金鑰。 如需如何使用 Visual Studio Code 連線到部署器的指示,請參閱使用 Visual Studio Code 連線到部署器。 如果您使用 PuTTY,請先使用 PuTTYGen 轉換 SSH 金鑰檔案。

注意

預設的使用者名稱為 azureadm

使用下列指令碼來設定部署器:

mkdir -p ~/Azure_SAP_Automated_Deployment; cd $_

wget https://raw.githubusercontent.com/Azure/sap-automation/main/deploy/scripts/configure_deployer.sh -O configure_deployer.sh	
chmod +x ./configure_deployer.sh
./configure_deployer.sh

# Source the new variables

. /etc/profile.d/deploy_server.sh

指令碼會安裝 Terraform 和 Ansible,並設定部署器。

保護控制平面

控制平面是 SAP 自動化架構中最重要的部分。 保護控制平面至關重要。 下列步驟可協助您保護控制平面。 如果您已使用外部虛擬機器或使用 Cloud Shell 建立控制平面,則應該實作儲存體帳戶和金鑰保存庫的私人端點來保護控制平面。

您可以使用 sync_deployer.sh 指令碼將控制平面設定檔複製到部署器 VM。 登入部署器 VM 並執行下列命令:


cd ~/Azure_SAP_Automated_Deployment/WORKSPACES

../sap-automation/deploy/scripts/sync_deployer.sh --storageaccountname mgtneweeutfstate### --state_subscription xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

確定 DEPLOYERLIBRARY 設定檔中的 use_private_endpoint 變數已設定為 true。 也請確定 DEPLOYER 設定檔中的 public_network_access_enabled 已設定為 false


# use_private_endpoint defines that the storage accounts and key vaults have private endpoints enabled
use_private_endpoint = true

# public_network_access_enabled controls if storage account and key vaults have public network access enabled
public_network_access_enabled = false

重新執行控制平面部署,以啟用儲存體帳戶和金鑰保存庫的私人端點。



export            env_code="MGMT"
export         region_code="WEEU"
export           vnet_code="DEP00"
export  storageaccountname=<storageaccountname>

export DEPLOYMENT_REPO_PATH="${HOME}/Azure_SAP_Automated_Deployment/sap-automation"
export CONFIG_REPO_PATH="${HOME}/Azure_SAP_Automated_Deployment/WORKSPACES"
export SAP_AUTOMATION_REPO_PATH="${HOME}/Azure_SAP_Automated_Deployment/sap-automation"

az logout
az login --service-principal -u "${ARM_CLIENT_ID}" -p="${ARM_CLIENT_SECRET}" --tenant "${ARM_TENANT_ID}"

cd ~/Azure_SAP_Automated_Deployment/WORKSPACES

deployer_parameter_file="${CONFIG_REPO_PATH}/DEPLOYER/${env_code}-${region_code}-${vnet_code}-INFRASTRUCTURE/${env_code}-${region_code}-${vnet_code}-INFRASTRUCTURE.tfvars"
library_parameter_file="${CONFIG_REPO_PATH}/LIBRARY/${env_code}-${region_code}-SAP_LIBRARY/${env_code}-${region_code}-SAP_LIBRARY.tfvars"

${SAP_AUTOMATION_REPO_PATH}/deploy/scripts/deploy_controlplane.sh  \
    --deployer_parameter_file "${deployer_parameter_file}"         \
    --library_parameter_file "${library_parameter_file}"            \
    --subscription "${ARM_SUBSCRIPTION_ID}"                        \
    --spn_id "${ARM_CLIENT_ID}"                                    \
    --spn_secret "${ARM_CLIENT_SECRET}"                            \
    --tenant_id "${ARM_TENANT_ID}"                                 \
    --storageaccountname "${storageaccountname}"                   \
    --recover

準備 Web 應用程式

此步驟是選擇性的。 如果您要以瀏覽器為基礎的 UX 來協助設定 SAP 工作負載區域和系統,請在部署控制平面之前執行下列命令。

echo '[{"resourceAppId":"00000003-0000-0000-c000-000000000000","resourceAccess":[{"id":"e1fe6dd8-ba31-4d61-89e7-88639da4683d","type":"Scope"}]}]' >> manifest.json

region_code=WEEU

export TF_VAR_app_registration_app_id=$(az ad app create \
    --display-name ${region_code}-webapp-registration \
    --enable-id-token-issuance true \
    --sign-in-audience AzureADMyOrg \
    --required-resource-access @manifest.json \
    --query "appId" | tr -d '"')

export TF_VAR_webapp_client_secret=$(az ad app credential reset \
    --id $TF_VAR_app_registration_app_id --append               \
    --query "password" | tr -d '"')

export TF_VAR_use_webapp=true
rm manifest.json

後續步驟