创建 Service Fabric 群集Create a Service Fabric cluster

此示例脚本将创建一个由五个节点组成的 Service Fabric 群集(使用 X.509 证书保护的群集)。This sample script creates a five-node Service Fabric cluster secured with an X.509 certificate. 该命令将创建一个自签名证书,并将其上传到新的 Key Vault。The command creates a self-signed certificate and uploads it to a new key vault. 该证书也会复制到本地目录。The certificate is also copied to a local directory. 设置 -OS 参数可选择群集节点上运行的 Windows 或 Linux 的版本。Set the -OS parameter to choose the version of Windows or Linux that runs on the cluster nodes. 根据需要自定义参数。Customize the parameters as needed.

备注

本文进行了更新,以便使用新的 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

#Provide the subscription Id
$subscriptionId = 'yourSubscriptionId'

# Certificate variables.
$certpwd="Password#1234" | ConvertTo-SecureString -AsPlainText -Force
$certfolder="c:\mycertificates\"

# Variables for VM admin.
$adminuser="vmadmin"
$adminpwd="Password#1234" | ConvertTo-SecureString -AsPlainText -Force 

# Variables for common values
$clusterloc="chinaeast"
$clustername = "mysfcluster"
$groupname="mysfclustergroup"       
$vmsku = "Standard_D2_v2"
$vaultname = "mykeyvault"
$subname="$clustername.$clusterloc.cloudapp.chinacloudapi.cn"

# Set the number of cluster nodes. Possible values: 1, 3-99
$clustersize=5 

# Set the context to the subscription Id where the cluster will be created
Select-AzSubscription -SubscriptionId $subscriptionId

# Create the Service Fabric cluster.
New-AzServiceFabricCluster -Name $clustername -ResourceGroupName $groupname -Location $clusterloc `
-ClusterSize $clustersize -VmUserName $adminuser -VmPassword $adminpwd -CertificateSubjectName $subname `
-CertificatePassword $certpwd -CertificateOutputFolder $certfolder `
-OS WindowsServer2016DatacenterwithContainers -VmSku $vmsku -KeyVaultName $vaultname

清理部署Clean up deployment

运行脚本示例后,可以使用以下命令删除资源组、群集以及所有相关资源。After the script sample has been run, the following command can be used to remove the resource group, cluster, and all related resources.

$groupname="mysfclustergroup"
Remove-AzResourceGroup -Name $groupname -Force

脚本说明Script explanation

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

CommandCommand 说明Notes
New-AzServiceFabricClusterNew-AzServiceFabricCluster 新建 Service Fabric 群集。Creates a new Service Fabric 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.