使用服务主体进行自动化

服务主体是在租户中创建的 Microsoft Entra 应用程序资源,用于执行无人参与的资源和服务级别操作。 服务主体是特殊类型的用户标识,具有应用程序 ID 和密码或证书。 服务主体仅具有执行由所分配的角色和权限定义的任务所需的权限。

在 Analysis Services 中,服务主体可以与 Azure 自动化、PowerShell 无人参与模式、自定义客户端应用程序和 Web 应用配合使用,以便自动完成常见的任务。 例如,预配服务器、部署模型、数据刷新、垂直缩放、暂停/恢复等操作均可使用服务主体自动完成。 权限通过角色成员身份分配给服务主体,十分类似于常规的 Microsoft Entra UPN 帐户。

Analysis Services 不支持 由托管标识使用服务主体执行的操作。 要了解详细信息,请参阅 Azure 资源的托管标识支持 Microsoft Entra 身份验证的 Azure 服务

创建服务主体

可以通过 Azure 门户或 PowerShell 创建服务主体。 若要了解更多信息,请参阅以下文章:

创建服务主体 - Azure 门户
创建服务主体 - PowerShell

在 Azure 自动化中存储凭据和证书资产

服务主体凭据和证书可以安全地存储在 Azure 自动化中进行 Runbook 操作。 若要了解更多信息,请参阅以下文章:

Azure 自动化中的凭据资产
Azure 自动化中的证书资产

将服务主体添加到服务器管理员角色

在使用服务主体进行 Analysis Services 服务器管理操作之前,必须将其添加到服务器管理员角色。 必须直接将服务主体添加到服务器管理员角色。 不支持先将服务主体添加到安全组,然后再将该安全组添加到服务器管理员角色。 有关详细信息,请参阅将服务主体添加到服务器管理员角色

连接字符串中的服务主体

服务主体 appID 和密码或证书可以在连接字符串中使用,与 UPN 很类似。

PowerShell

注意

建议使用 Azure Az PowerShell 模块与 Azure 交互。 请参阅安装 Azure PowerShell 以开始使用。 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 Az

使用 Az.AnalysisServices 模块

将服务主体与 Az.AnalysisServices 模块配合使用来执行资源管理操作时,请使用 Connect-AzAccount -Environment AzureChinaCloud cmdlet。

以下示例使用 appID 和密码执行控制平面操作,以便与只读副本同步并进行纵向/横向扩展:

Param (
        [Parameter(Mandatory=$true)] [String] $AppId,
        [Parameter(Mandatory=$true)] [String] $PlainPWord,
        [Parameter(Mandatory=$true)] [String] $TenantId
       )
$PWord = ConvertTo-SecureString -String $PlainPWord -AsPlainText -Force
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $AppId, $PWord

# Connect using Az module
Connect-AzAccount -Environment AzureChinaCloud -Credential $Credential -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx"

# Synchronize a database for query scale out
Sync-AzAnalysisServicesInstance -Instance "asazure://chinanorth.asazure.chinacloudapi.cn/testsvr" -Database "testdb"

# Scale up the server to an S1, set 2 read-only replicas, and remove the primary from the query pool. The new replicas will hydrate from the synchronized data.
Set-AzAnalysisServicesServer -Name "testsvr" -ResourceGroupName "testRG" -Sku "S1" -ReadonlyReplicaCount 2 -DefaultConnectionMode Readonly

使用 SQLServer 模块

以下示例使用 appID 和密码执行模型数据库刷新操作:

Param (
        [Parameter(Mandatory=$true)] [String] $AppId,
        [Parameter(Mandatory=$true)] [String] $PlainPWord,
        [Parameter(Mandatory=$true)] [String] $TenantId
       )
$PWord = ConvertTo-SecureString -String $PlainPWord -AsPlainText -Force

$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $AppId, $PWord

Invoke-ProcessTable -Server "asazure://chinanorth.asazure.chinacloudapi.cn/myserver" -TableName "MyTable" -Database "MyDb" -RefreshType "Full" -ServicePrincipal -ApplicationId $AppId -TenantId $TenantId -Credential $Credential

AMO 和 ADOMD

通过客户端应用程序和 Web 应用进行连接时,由 NuGet 提供的 AMO 和 ADOMD 客户端库 15.0.2 及更高版本的可安装包支持在连接字符串中使用服务主体,可以使用 app:AppID 语法以及密码或 cert:thumbprint

以下示例使用 appIDpassword 执行模型数据库刷新操作:

string appId = "xxx";
string authKey = "yyy";
string connString = $"Provider=MSOLAP;Data Source=asazure://chinanorth.asazure.chinacloudapi.cn/<servername>;User ID=app:{appId};Password={authKey};";
Server server = new Server();
server.Connect(connString);
Database db = server.Databases.FindByName("adventureworks");
Table tbl = db.Model.Tables.Find("DimDate");
tbl.RequestRefresh(RefreshType.Full);
db.Model.SaveChanges();

后续步骤

使用 Azure PowerShell 进行登录
使用逻辑应用进行刷新

将服务主体添加到服务器管理员角色
使用服务主体自动完成 Power BI Premium 工作区和数据集任务