建立 Service Fabric 叢集

此範例指令碼會建立一個使用 X.509 憑證保護的五節點 Service Fabric 叢集。 此命令會建立自我簽署的憑證,並將它上傳到新的金鑰保存庫。 憑證也會複製到本機目錄。 設定 -OS 參數選擇在叢集節點執行的 Windows 或 Linux 版本。 視需要自訂參數。

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 請參閱安裝 Azure PowerShell 以開始使用。 若要了解如何移轉至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 移轉至 Az

您可以視需要使用 Azure PowerShell 指南 (英文) 中的指示來安裝 Azure PowerShell,然後執行 Connect-AzAccount 來建立與 Azure 的連線。

範例指令碼

#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="SouthCentralUS"
$clustername = "mysfcluster"
$groupname="mysfclustergroup"       
$vmsku = "Standard_D2_v2"
$vaultname = "mykeyvault"
$subname="$clustername.$clusterloc.cloudapp.azure.com"

# 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

清除部署

在執行過指令碼範例之後,您可以使用下列命令來移除資源群組、叢集和所有相關資源。

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

指令碼說明

此指令碼會使用下列命令。 下表中的每個命令都會連結至命令特定的文件。

Command 注意
New-AzServiceFabricCluster 建立新的 Service Fabric 叢集。

下一步

如需有關 Azure PowerShell 模組的詳細資訊,請參閱 Azure PowerShell 文件

您可以在 Azure PowerShell 範例中找到適用於 Azure Service Fabric 的其他 Azure PowerShell 範例。