将应用程序证书添加到 Service Fabric 群集Add an application certificate to a Service Fabric cluster

此示例脚本在指定的 Azure Key Vault 中创建一个自签名证书,并将它安装到 Service Fabric 群集的所有节点上。This sample script creates a self-signed certificate in the specified Azure key vault and installs it to all nodes of the Service Fabric cluster. 该证书还会下载到本地文件夹。The certificate also downloads to a local folder. 已下载证书的名称与 Key Vault 中证书的名称相同。The name of the downloaded certificate is the same as the name of the certificate in the key vault. 根据需要自定义参数。Customize the parameters as needed.

Note

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

必要时,请使用 Azure PowerShell 指南中的说明安装 Azure PowerShell,并运行 Connect-AzAccount -Environment AzureChinaCloud 创建与 Azure 的连接。If needed, install the Azure PowerShell using the instruction found in the Azure PowerShell guide and then run Connect-AzAccount -Environment AzureChinaCloud to create a connection with Azure.

示例脚本Sample script


# Variables for common values.
$clusterloc="chinaeast"
$groupname="mysfclustergroup"
$clustername = "mysfcluster"
$vaultname = "mykeyvault"
$subname="$clustername.$clusterloc.cloudapp.chinacloudapi.cn"
$subscriptionID = 'subscription ID'

# Login and select your subscription
Connect-AzAccount -Environment AzureChinaCloud
Get-AzSubscription -SubscriptionId $subscriptionID | Select-AzSubscription

# Certificate variables.
$appcertpwd = ConvertTo-SecureString -String 'Password#1234' -AsPlainText -Force
$appcertfolder="c:\myappcertificates\"

# Create a new self-signed certificate and add it to all the VMs in the cluster.
Add-AzServiceFabricApplicationCertificate -ResourceGroupName $groupname -Name $clustername `
    -KeyVaultName $vaultname -KeyVaultResouceGroupName $groupname -CertificateSubjectName $subname `
    -CertificateOutputFolder $appcertfolder -CertificatePassword $appcertpwd

脚本说明Script explanation

此脚本使用以下命令:表中的每条命令均链接到特定于命令的文档。This script uses the following commands: Each command in the table links to command specific documentation.

命令Command 注释Notes
Add-AzServiceFabricApplicationCertificateAdd-AzServiceFabricApplicationCertificate 将新的应用程序证书添加到构成群集的虚拟机规模集。Add a new application certificate to the virtual machine scale set that make up the cluster.

后续步骤Next steps

有关 Azure PowerShell 模块的详细信息,请参阅 Azure PowerShell 文档For more information on the Azure PowerShell module, see Azure PowerShell documentation.

可以在 Azure PowerShell 示例中找到 Azure Service Fabric 的其他 Azure Powershell 示例。Additional Azure Powershell samples for Azure Service Fabric can be found in the Azure PowerShell samples.