如需如何安裝目前版本的 Azure CLI,請參閱安裝 Azure CLI 一文。
使用 az sql server create 命令建立伺服器,並設定使用者指派的受控識別和客戶受控的 TDE。
az sql server create \
--name $serverName \
--resource-group $resourceGroupName \
--location $location \
--admin-user $adminlogin \
--admin-password $password \
--assign-identity \
--identity-type $identitytype \
--user-assigned-identity-id $identityid \
--primary-user-assigned-identity-id $primaryidentityid \
--key-id $keyid
使用 az sql db create 命令建立資料庫。
az sql db create \
--resource-group $resourceGroupName \
--server $serverName \
--name mySampleDatabase \
--sample-name AdventureWorksLT \
--edition GeneralPurpose \
--compute-model Serverless \
--family Gen5 \
--capacity 2
使用 PowerShell 建立伺服器,並設定使用者指派的受控識別和客戶受控的 TDE。
如需 Az PowerShell 模組安裝指示,請參閱安裝 Azure PowerShell。 如需特定的 Cmdlet,請參閱 AzureRM.Sql。
使用 New-AzSqlServer Cmdlet。
取代範例中的下列值:
<ResourceGroupName>
:Azure SQL 邏輯伺服器的資源群組名稱
<Location>
:伺服器的位置,例如 West US
或 Central US
<ServerName>
:使用唯一的 Azure SQL 邏輯伺服器名稱
<ServerAdminName>
:SQL 管理員登入
<ServerAdminPassword>
:SQL 管理員密碼
<IdentityType>
:要指派給伺服器的身分識別類型。 可能的值是 SystemAssigned
、UserAssigned
, SystemAssigned,UserAssigned
和 None
<UserAssignedIdentityId>
:要指派給伺服器的使用者指派受控識別清單 (可以是一或多個)
<PrimaryUserAssignedIdentityId>
:使用者指派的受控識別,應該作為此伺服器的主要或預設值
<CustomerManagedKeyId>
:「金鑰識別碼」,而且可以從金鑰保存庫中的金鑰擷取
若要取得使用者指派的受控識別資源識別碼,請在 Azure 入口網站中搜尋受控識別。 尋找您的受控識別,並移至 [屬性]。 UMI「資源識別碼」的範例看起來像 /subscriptions/<subscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managedIdentity>
# create a server with user-assigned managed identity and customer-managed TDE
$params = @{
ResourceGroupName = "<ResourceGroupName>"
Location = "<Location>"
ServerName = "<ServerName>"
ServerVersion = "12.0"
SqlAdministratorCredentials = (Get-Credential)
SqlAdministratorLogin = "<ServerAdminName>"
SqlAdministratorPassword = "<ServerAdminPassword>"
AssignIdentity = $true
IdentityType = "<IdentityType>"
UserAssignedIdentityId = "<UserAssignedIdentityId>"
PrimaryUserAssignedIdentityId = "<PrimaryUserAssignedIdentityId>"
KeyId = "<CustomerManagedKeyId>"
}
New-AzSqlServer @params
以下是使用使用者指派的受控識別和客戶自控 TDE 在 Azure 中建立邏輯伺服器的 ARM 範例。 此範本也會為伺服器新增 Microsoft Entra 管理員集,並啟用 僅限 Microsoft Entra 的驗證,但可以從範本範例中移除。
如需詳細資訊和 ARM 範本,請參閱適用於 Azure SQL 資料庫 和 SQL 受管理執行個體 的 Azure Resource Manager 範本。
使用 Azure 入口網站中的自訂部署,然後在編輯器中建置您自己的範本。 接下來,將設定貼進範例之後,加以儲存。
若要取得使用者指派的受控識別資源識別碼,請在 Azure 入口網站中搜尋受控識別。 尋找您的受控識別,並移至 [屬性]。 UMI「資源識別碼」的範例看起來像 /subscriptions/<subscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managedIdentity>
。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.1",
"parameters": {
"server": {
"type": "String"
},
"location": {
"type": "String"
},
"aad_admin_name": {
"type": "String",
"metadata": {
"description": "The name of the Azure AD admin for the SQL server."
}
},
"aad_admin_objectid": {
"type": "String",
"metadata": {
"description": "The Object ID of the Azure AD admin."
}
},
"aad_admin_tenantid": {
"type": "String",
"defaultValue": "[subscription().tenantId]",
"metadata": {
"description": "The Tenant ID of the Azure Active Directory"
}
},
"aad_admin_type": {
"defaultValue": "User",
"allowedValues": [
"User",
"Group",
"Application"
],
"type": "String"
},
"aad_only_auth": {
"defaultValue": true,
"type": "Bool"
},
"user_identity_resource_id": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "The Resource ID of the user-assigned managed identity."
}
},
"keyvault_url": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "The key vault URI."
}
},
"AdminLogin": {
"minLength": 1,
"type": "String"
},
"AdminLoginPassword": {
"type": "SecureString"
}
},
"resources": [
{
"type": "Microsoft.Sql/servers",
"apiVersion": "2020-11-01-preview",
"name": "[parameters('server')]",
"location": "[parameters('location')]",
"identity": {
"type": "UserAssigned",
"UserAssignedIdentities": {
"[parameters('user_identity_resource_id')]": {}
}
},
"properties": {
"administratorLogin": "[parameters('AdminLogin')]",
"administratorLoginPassword": "[parameters('AdminLoginPassword')]",
"PrimaryUserAssignedIdentityId": "[parameters('user_identity_resource_id')]",
"KeyId": "[parameters('keyvault_url')]",
"administrators": {
"login": "[parameters('aad_admin_name')]",
"sid": "[parameters('aad_admin_objectid')]",
"tenantId": "[parameters('aad_admin_tenantid')]",
"principalType": "[parameters('aad_admin_type')]",
"azureADOnlyAuthentication": "[parameters('aad_only_auth')]"
}
}
}
]
}