共用方式為


教學課程:將執行 Windows 的 Service Fabric 叢集部署至 Azure 虛擬網路

本教學課程是一個系列的第一部分。 您將瞭解如何使用 PowerShell 和範本,將執行 Windows 的 Azure Service Fabric 叢集部署至 Azure 虛擬網路網路安全性群組 。 完成後,您將在雲端中執行叢集,您可以在其中部署應用程式。 若要建立使用 Azure CLI 的 Linux 叢集,請參閱 在 Azure 上建立安全的 Linux 叢集

本教學課程說明生產案例。 如果您想要建立較小的叢集以進行測試,請參閱 建立測試叢集

在本教學課程中,您將瞭解如何:

  • 使用 PowerShell 在 Azure 中建立 VNET
  • 建立金鑰保存庫並上傳憑證
  • 設定 Microsoft Entra 驗證
  • 設定診斷資料收集
  • 設定 EventStore 服務
  • 設定 Azure 監視器記錄
  • 在 Azure PowerShell 中建立安全的 Service Fabric 叢集
  • 使用 X.509 憑證保護叢集
  • 使用 PowerShell 連線到叢集
  • 移除叢集

在本教學課程系列中,您將瞭解如何:

備註

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

先決條件

開始進行本教學課程之前:

下列程式會建立七節點 Service Fabric 叢集。 使用 Azure 定價計算機 來計算在 Azure 中執行 Service Fabric 叢集所產生的成本。

下載並探索模板

下載下列 Azure Resource Manager 範本檔案:

此範本會將七個虛擬機器和三個節點類型的安全叢集部署到虛擬網路和網路安全性群組中。 其他範例範本可在 GitHub 上找到。 azuredeploy.json 會部署許多資源,包括下列資源。

Service Fabric 叢集

Microsoft.ServiceFabric/clusters 資源中,Windows 叢集會設定下列特性:

  • 三種節點類型。
  • 主要節點類型中有五個節點(可在範本參數中配置),其他兩種節點類型各有一個節點。
  • 作業系統:Windows Server 2016 Datacenter with Containers (可在範本參數中設定)。
  • 憑證受保護(可在範本引數中設定)。
  • 已啟用反向代理
  • DNS 服務 已啟用。
  • 青銅的耐久性層級 (可在範本引數中設定)。
  • 銀牌的可靠性等級(可在範本參數中設定)。
  • 用戶端連線端點:19000 (可在範本參數中設定)。
  • HTTP 閘道端點:19080 (可在範本參數中設定)。

Azure Load Balancer

Microsoft.Network/loadBalancers 資源中,已設定負載平衡器。 探針和規則會針對下列連接埠進行設定:

  • 用戶端連線端點:19000
  • HTTP 閘道端點:19080
  • 應用埠:80
  • 申請連接埠:443
  • Service Fabric 反向代理:19081

如果需要其他應用程式埠,您必須調整 Microsoft.Network/loadBalancers 資源和 Microsoft.Network/networkSecurityGroups 資源,以允許流量進入。

虛擬網路、子網路和網路安全性群組

虛擬網路、子網路和網路安全性群組的名稱會在範本參數中宣告。 虛擬網路和子網路的位址空間也會在範本參數中宣告,並在 Microsoft.Network/virtualNetworks 資源中設定:

  • 虛擬網路位址空間:172.16.0.0/20
  • Service Fabric 子網路位址空間:172.16.2.0/23

下列輸入流量規則會在 Microsoft.Network/networkSecurityGroups 資源中啟用。 您可以變更範本變數來變更埠值。

  • ClientConnectionEndpoint (TCP):19000
  • HttpGatewayEndpoint (HTTP/TCP):19080
  • SMB:445
  • 節點間通訊:1025、1026、1027
  • 暫時連接埠範圍:49152 到 65534 (至少需要 256 個連接埠)。
  • 應用用埠:80 和 443
  • 應用端口範圍:49152 至 65534(用於服務到服務通信。其他連接埠不會在負載平衡器上開啟)。
  • 封鎖所有其他連接埠

如果需要其他應用程式埠,您必須調整 Microsoft.Network/loadBalancers 資源和 Microsoft.Network/networkSecurityGroups 資源,以允許流量進入。

Windows 防護程序

默認情況下, Windows Defender 防病毒程序 已安裝並在 Windows Server 2016 上運行。 使用者介面預設會安裝在某些 SKU 上,但不是必要的。 針對範本中宣告的每個節點類型/VM 擴展集, Azure VM 反惡意代碼延伸模組 可用來排除 Service Fabric 目錄和進程:

{
"name": "[concat('VMIaaSAntimalware','_vmNodeType0Name')]",
"properties": {
        "publisher": "Microsoft.Azure.Security",
        "type": "IaaSAntimalware",
        "typeHandlerVersion": "1.5",
        "settings": {
        "AntimalwareEnabled": "true",
        "Exclusions": {
                "Paths": "D:\\SvcFab;D:\\SvcFab\\Log;C:\\Program Files\\Microsoft Service Fabric",
                "Processes": "Fabric.exe;FabricHost.exe;FabricInstallerService.exe;FabricSetup.exe;FabricDeployer.exe;ImageBuilder.exe;FabricGateway.exe;FabricDCA.exe;FabricFAS.exe;FabricUOS.exe;FabricRM.exe;FileStoreService.exe"
        },
        "RealtimeProtectionEnabled": "true",
        "ScheduledScanSettings": {
                "isEnabled": "true",
                "scanType": "Quick",
                "day": "7",
                "time": "120"
        }
        },
        "protectedSettings": null
}
}

設定範本參數

azuredeploy.parameters.json 參數檔案會宣告許多用來部署叢集和相關資源的值。 以下是要針對部署修改的參數:

Parameter 範例值 注意事項
管理者用戶名 虛擬機管理員 叢集 VM 的管理員使用者名稱。 VM 的使用者名稱需求
管理員密碼 密碼#1234 叢集 VM 的管理員密碼。 VM 的密碼需求
叢集名稱 (clusterName) mysf叢集123 叢集的名稱。 只能包含字母和數字。 長度可以介於 3 到 23 個字元之間。
位置 southcentralus 叢集的位置。
certificateThumbprint

如果建立自我簽署憑證或提供憑證檔案,則值應該是空的。

若要使用先前上傳至金鑰保存庫的現有憑證,請填寫憑證 SHA1 指紋值。 例如,“AA11BB22CC33DD44EE55FF66AA77BB88CC99DD00”。

certificateUrlValue

如果建立自我簽署憑證或提供憑證檔案,則值應該是空的。

若要使用先前上傳至金鑰保存庫的現有憑證,請填寫憑證 URL。 例如,“https://mykeyvault.vault.azure.net:443/secrets/mycertificate/02bea722c9ef4009a76c5052bcbf8346"。

sourceVault值

如果建立自我簽署憑證或提供憑證檔案,則值應該是空的。

若要使用先前上傳至金鑰保存庫的現有憑證,請填寫來源保存庫值。 例如,「/subscriptions/333cc2c84-12fa-5778-bd71-c71c07bf873f/resourceGroups/MyTestRG/providers/Microsoft.KeyVault/vaults/MYKEYVAULT」。

設定 Microsoft Entra 用戶端驗證

對於部署在 Azure 上裝載的公用網路中的 Service Fabric 叢集,用戶端對節點相互驗證的建議如下:

  • 使用 Microsoft Entra ID 作為用戶端身分識別。
  • 使用憑證進行伺服器身分識別和 HTTP 通訊的 TLS 加密。

建立叢集之前,必須先設定 Microsoft Entra ID 來驗證 Service Fabric 叢集的用戶端。 Microsoft Entra ID 可讓組織 (稱為租用戶) 管理使用者對應用程式的存取權。

Service Fabric 叢集提供其管理功能的各種進入點 (包括 Web 型 Service Fabric ExplorerVisual Studio)。 因此,您會建立兩個 Microsoft Entra 應用程式來控制叢集的存取:一個 Web 應用程式和一個原生應用程式。 建立應用程式之後,您將使用者指派為唯讀和管理員角色。

備註

您必須先完成下列步驟,才能建立叢集。 由於指令碼需要叢集名稱和端點,因此應該規劃值,而不是您已建立的值。

在本文中,我們假設您已經建立了一個租戶。 如果您還沒有這樣做,請先閱讀 如何取得 Microsoft Entra 租戶

為了簡化使用 Service Fabric 叢集設定 Microsoft Entra ID 所涉及的步驟,我們已建立一組 Windows PowerShell 腳本。 將腳本下載到您的電腦。

建立 Microsoft Entra 應用程式,並將使用者指派給角色

建立兩個 Microsoft Entra 應用程式來控制叢集的存取:一個 Web 應用程式和一個原生應用程式。 建立應用程式來代表叢集之後,請將使用者指派給 Service Fabric 支援的角色:唯讀和系統管理員。

執行 SetupApplications.ps1,並提供租戶識別碼、叢集名稱和 Web 應用程式回覆 URL 作為參數。 指定使用者的使用者名稱和密碼。 例如:

$Configobj = .\SetupApplications.ps1 -TenantId '<MyTenantID>' -ClusterName 'mysfcluster123' -WebApplicationReplyUrl 'https://mysfcluster123.eastus.cloudapp.azure.com:19080/Explorer/index.html' -AddResourceAccess
.\SetupUser.ps1 -ConfigObj $Configobj -UserName 'TestUser' -Password 'P@ssword!123'
.\SetupUser.ps1 -ConfigObj $Configobj -UserName 'TestAdmin' -Password 'P@ssword!123' -IsAdmin

備註

針對國家/地區雲端 (例如 Azure 政府、21Vianet、Azure 德國營運的 Microsoft Azure) ,請指定參數 -Location

您可以在 Azure 入口網站中找到您的 TenantId 或目錄識別碼。 選取 [Microsoft Entra ID>屬性] ,然後複製 目錄識別碼 值。

ClusterName 可用來為腳本所建立的 Microsoft Entra 應用程式加上前置詞。 它不需要完全符合實際的叢集名稱。 這會讓您更輕鬆地將 Microsoft Entra 工件對應至使用中的 Service Fabric 叢集。

WebApplicationReplyUrl 是 Microsoft Entra ID 在使用者完成登入之後傳回給使用者的預設端點。 將此端點設定為叢集的 Service Fabric 總管端點,預設為:

https://<cluster_domain>:19080/Explorer

系統會提示您登入具有 Microsoft Entra 租使用者系統管理許可權的帳戶。 登入之後,指令碼會建立 Web 和原生應用程式來代表您的 Service Fabric 叢集。 在 Azure 入口網站 的租戶的應用程式中,您應該會看到兩個新項目:

  • ClusterName_Cluster
  • ClusterName _Client

指令碼會在您建立叢集時列印 Resource Manager 範本所需的 JSON,因此最好讓 PowerShell 視窗保持開啟狀態。

"azureActiveDirectory": {
  "tenantId":"<guid>",
  "clusterApplication":"<guid>",
  "clientApplication":"<guid>"
},

新增 Microsoft Entra 設定以使用 Microsoft Entra ID 進行用戶端存取

azuredeploy.json中,在 Microsoft.ServiceFabric/clusters 區段中設定Microsoft Entra ID。 新增租用戶 ID、叢集應用程式 ID 和用戶端應用程式 ID 的參數。

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
  "contentVersion": "1.0.0.0",
  "parameters": {
    ...

    "aadTenantId": {
      "type": "string",
      "defaultValue": "0e3d2646-78b3-4711-b8be-74a381d9890c"
    },
    "aadClusterApplicationId": {
      "type": "string",
      "defaultValue": "cb147d34-b0b9-4e77-81d6-420fef0c4180"
    },
    "aadClientApplicationId": {
      "type": "string",
      "defaultValue": "7a8f3b37-cc40-45cc-9b8f-57b8919ea461"
    }
  },

...

{
  "apiVersion": "2018-02-01",
  "type": "Microsoft.ServiceFabric/clusters",
  "name": "[parameters('clusterName')]",
  ...
  "properties": {
    ...
    "azureActiveDirectory": {
      "tenantId": "[parameters('aadTenantId')]",
      "clusterApplication": "[parameters('aadClusterApplicationId')]",
      "clientApplication": "[parameters('aadClientApplicationId')]"
    },
    ...
  }
}

azuredeploy.parameters.json 參數檔案中新增參數值。 例如:

"aadTenantId": {
"value": "0e3d2646-78b3-4711-b8be-74a381d9890c"
},
"aadClusterApplicationId": {
"value": "cb147d34-b0b9-4e77-81d6-420fef0c4180"
},
"aadClientApplicationId": {
"value": "7a8f3b37-cc40-45cc-9b8f-57b8919ea461"
}

在叢集上配置診斷數據收集

當您執行 Service Fabric 叢集時,最好從中央位置的所有節點收集記錄。 將日誌放在中央位置可協助您分析和疑難排解叢集中的問題,或該叢集中執行的應用程式和服務中的問題。

上傳和收集記錄的其中一種方式是使用 Azure 診斷 (WAD) 延伸模組,它會將記錄上傳至 Azure 儲存體,也可以選擇將記錄傳送至 Azure Application Insights 或事件中樞。 您也可以使用外部進程從儲存體讀取事件,並將其放在分析平台產品中,例如 Azure 監視器記錄或其他記錄剖析解決方案。

如果您遵循本教學課程,則診斷收集已在範本中設定。

如果您有未部署診斷的現有叢集,您可以透過叢集範本新增或更新它。 修改用來建立現有叢集的 Resource Manager 範本,或從入口網站下載範本。 執行下列工作來修改 template.json 檔案:

將新的儲存資源新增至範本中的資源區段:

"resources": [
...
{
  "apiVersion": "2015-05-01-preview",
  "type": "Microsoft.Storage/storageAccounts",
  "name": "[parameters('applicationDiagnosticsStorageAccountName')]",
  "location": "[parameters('computeLocation')]",
  "sku": {
    "accountType": "[parameters('applicationDiagnosticsStorageAccountType')]"
  },
  "tags": {
    "resourceType": "Service Fabric",
    "clusterName": "[parameters('clusterName')]"
  }
},
...
]

接下來,將儲存體帳戶名稱和類型的參數新增至範本的參數區段。 以您偏好的儲存體帳戶名稱來取代預留位置文字 storage account name goes here。

"parameters": {
...
"applicationDiagnosticsStorageAccountType": {
    "type": "string",
    "allowedValues": [
    "Standard_LRS",
    "Standard_GRS"
    ],
    "defaultValue": "Standard_LRS",
    "metadata": {
    "description": "Replication option for the application diagnostics storage account"
    }
},
"applicationDiagnosticsStorageAccountName": {
    "type": "string",
    "defaultValue": "**STORAGE ACCOUNT NAME GOES HERE**",
    "metadata": {
    "description": "Name for the storage account that contains application diagnostics data from the cluster"
    }
},
...
}

接下來,將 IaaSDiagnostics 延伸模組新增至叢集中每個 Microsoft.Compute/virtualMachineScaleSets 資源之 VirtualMachineProfile 屬性的延伸模組陣列。 如果您使用 範例範本,那麼會有三個虛擬機器規模設定集(每個叢集節點類型各有一個)。

"apiVersion": "2018-10-01",
"type": "Microsoft.Compute/virtualMachineScaleSets",
"name": "[variables('vmNodeType1Name')]",
"properties": {
    ...
    "virtualMachineProfile": {
        "extensionProfile": {
            "extensions": [
                {
                    "name": "[concat(parameters('vmNodeType0Name'),'_Microsoft.Insights.VMDiagnosticsSettings')]",
                    "properties": {
                        "type": "IaaSDiagnostics",
                        "autoUpgradeMinorVersion": true,
                        "protectedSettings": {
                        "storageAccountName": "[parameters('applicationDiagnosticsStorageAccountName')]",
                        "storageAccountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('applicationDiagnosticsStorageAccountName')),'2015-05-01-preview').key1]",
                        "storageAccountEndPoint": "https://core.windows.net/"
                        },
                        "publisher": "Microsoft.Azure.Diagnostics",
                        "settings": {
                        "WadCfg": {
                            "DiagnosticMonitorConfiguration": {
                            "overallQuotaInMB": "50000",
                            "EtwProviders": {
                                "EtwEventSourceProviderConfiguration": [
                                {
                                    "provider": "Microsoft-ServiceFabric-Actors",
                                    "scheduledTransferKeywordFilter": "1",
                                    "scheduledTransferPeriod": "PT5M",
                                    "DefaultEvents": {
                                    "eventDestination": "ServiceFabricReliableActorEventTable"
                                    }
                                },
                                {
                                    "provider": "Microsoft-ServiceFabric-Services",
                                    "scheduledTransferPeriod": "PT5M",
                                    "DefaultEvents": {
                                    "eventDestination": "ServiceFabricReliableServiceEventTable"
                                    }
                                }
                                ],
                                "EtwManifestProviderConfiguration": [
                                {
                                    "provider": "cbd93bc2-71e5-4566-b3a7-595d8eeca6e8",
                                    "scheduledTransferLogLevelFilter": "Information",
                                    "scheduledTransferKeywordFilter": "4611686018427387904",
                                    "scheduledTransferPeriod": "PT5M",
                                    "DefaultEvents": {
                                    "eventDestination": "ServiceFabricSystemEventTable"
                                    }
                                }
                                ]
                            }
                            }
                        },
                        "StorageAccount": "[parameters('applicationDiagnosticsStorageAccountName')]"
                        },
                        "typeHandlerVersion": "1.5"
                    }
                }
            ...
            ]
        }
    }
}

設定 EventStore 服務

EventStore 服務是 Service Fabric 中的監視選項。 EventStore 提供一種方法來了解叢集或工作負載在指定時間點的狀態。 EventStore 是可設定狀態的 Service Fabric 服務,可維護叢集中的事件。 事件會透過 Service Fabric Explorer、REST 和 APIs 公開。 EventStore 會直接查詢叢集,以取得叢集中任何實體的診斷資料,並應該用來協助:

  • 診斷開發或測試中的問題,或您可能採用監控流程的情境
  • 確認您在叢集上採取的管理操作正在被正確處理
  • 取得 Service Fabric 與特定實體互動的快照

若要在叢集上啟用 EventStore 服務,請將下列專案新增至 Microsoft.ServiceFabric/clusters 資源的 fabricSettings 屬性:

"apiVersion": "2018-02-01",
"type": "Microsoft.ServiceFabric/clusters",
"name": "[parameters('clusterName')]",
"properties": {
    ...
    "fabricSettings": [
        ...
        {
            "name": "EventStoreService",
            "parameters": [
                {
                "name": "TargetReplicaSetSize",
                "value": "3"
                },
                {
                "name": "MinReplicaSetSize",
                "value": "1"
                }
            ]
        }
    ]
}

設定叢集的 Azure 監視器記錄

Azure 監視器記錄是監視叢集層級事件的建議。 若要設定 Azure 監視器記錄來監視叢集,您必須 啟用診斷才能檢視叢集層級事件

工作區需要連線到來自叢集的診斷資料。 此記錄資料會儲存在 applicationDiagnosticsStorageAccountName 儲存體帳戶、WADServiceFabric*EventTable、WADWindowsEventLogsTable 和 WADETWEventTable 資料表中。

新增 Azure Log Analytics 工作區,並將解決方案新增至工作區:

"resources": [
    ...
    {
        "apiVersion": "2015-11-01-preview",
        "location": "[parameters('omsRegion')]",
        "name": "[parameters('omsWorkspacename')]",
        "type": "Microsoft.OperationalInsights/workspaces",
        "properties": {
            "sku": {
                "name": "Free"
            }
        },
        "resources": [
            {
                "apiVersion": "2015-11-01-preview",
                "name": "[concat(variables('applicationDiagnosticsStorageAccountName'),parameters('omsWorkspacename'))]",
                "type": "storageinsightconfigs",
                "dependsOn": [
                    "[concat('Microsoft.OperationalInsights/workspaces/', parameters('omsWorkspacename'))]",
                    "[concat('Microsoft.Storage/storageAccounts/', variables('applicationDiagnosticsStorageAccountName'))]"
                ],
                "properties": {
                    "containers": [],
                    "tables": [
                        "WADServiceFabric*EventTable",
                        "WADWindowsEventLogsTable",
                        "WADETWEventTable"
                    ],
                    "storageAccount": {
                        "id": "[resourceId('Microsoft.Storage/storageaccounts/', variables('applicationDiagnosticsStorageAccountName'))]",
                        "key": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('applicationDiagnosticsStorageAccountName')),'2015-06-15').key1]"
                    }
                }
            },
            {
                "apiVersion": "2015-11-01-preview",
                "type": "datasources",
                "name": "sampleWindowsPerfCounter",
                "dependsOn": [
                    "[concat('Microsoft.OperationalInsights/workspaces/', parameters('omsWorkspacename'))]"
                ],
                "kind": "WindowsPerformanceCounter",
                "properties": {
                    "objectName": "Memory",
                    "instanceName": "*",
                    "intervalSeconds": 10,
                    "counterName": "Available MBytes"
                }
            },
            {
                "apiVersion": "2015-11-01-preview",
                "type": "datasources",
                "name": "sampleWindowsPerfCounter2",
                "dependsOn": [
                    "[concat('Microsoft.OperationalInsights/workspaces/', parameters('omsWorkspacename'))]"
                ],
                "kind": "WindowsPerformanceCounter",
                "properties": {
                    "objectName": "Service Fabric Service",
                    "instanceName": "*",
                    "intervalSeconds": 10,
                    "counterName": "Average milliseconds per request"
                }
            }
        ]
    },
    {
        "apiVersion": "2015-11-01-preview",
        "location": "[parameters('omsRegion')]",
        "name": "[variables('solution')]",
        "type": "Microsoft.OperationsManagement/solutions",
        "dependsOn": [
            "[concat('Microsoft.OperationalInsights/workspaces/', parameters('omsWorkspacename'))]"
        ],
        "properties": {
            "workspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces/', parameters('omsWorkspacename'))]"
        },
        "plan": {
            "name": "[variables('solution')]",
            "publisher": "Microsoft",
            "product": "[Concat('OMSGallery/', variables('solutionName'))]",
            "promotionCode": ""
        }
    }
]

接下來,新增參數

"parameters": {
    ...
    "omsWorkspacename": {
        "type": "string",
        "defaultValue": "mysfomsworkspace",
        "metadata": {
            "description": "Name of your OMS Log Analytics Workspace"
        }
    },
    "omsRegion": {
        "type": "string",
        "defaultValue": "West Europe",
        "allowedValues": [
            "West Europe",
            "East US",
            "Southeast Asia"
        ],
        "metadata": {
            "description": "Specify the Azure Region for your OMS workspace"
        }
    }
}

接下來,新增變數:

"variables": {
    ...
    "solution": "[Concat('ServiceFabric', '(', parameters('omsWorkspacename'), ')')]",
    "solutionName": "ServiceFabric"
}

將 Log Analytics 代理程式擴充模組新增至叢集中的每個虛擬機器規模設定集,並將代理程式連線到 Log Analytics 工作區。 這可讓您收集有關容器、應用程式和效能監控的診斷資料。 藉由將它新增為虛擬機器擴展集資源的延伸模組,Azure Resource Manager 可確保它安裝在每個節點上,即使在調整叢集時也是如此。

"apiVersion": "2018-10-01",
"type": "Microsoft.Compute/virtualMachineScaleSets",
"name": "[variables('vmNodeType1Name')]",
"properties": {
    ...
    "virtualMachineProfile": {
        "extensionProfile": {
            "extensions": [
                {
                    "name": "[concat(variables('vmNodeType0Name'),'OMS')]",
                    "properties": {
                        "publisher": "Microsoft.EnterpriseCloud.Monitoring",
                        "type": "MicrosoftMonitoringAgent",
                        "typeHandlerVersion": "1.0",
                        "autoUpgradeMinorVersion": true,
                        "settings": {
                            "workspaceId": "[reference(resourceId('Microsoft.OperationalInsights/workspaces/', parameters('omsWorkspacename')), '2015-11-01-preview').customerId]"
                        },
                        "protectedSettings": {
                            "workspaceKey": "[listKeys(resourceId('Microsoft.OperationalInsights/workspaces/', parameters('omsWorkspacename')),'2015-11-01-preview').primarySharedKey]"
                        }
                    }
                }
            ...
            ]
        }
    }
}

部署虛擬網路和叢集

接下來,設定網路拓撲並部署 Service Fabric 叢集。 azuredeploy.json Resource Manager 範本會建立 Service Fabric 的虛擬網路、子網路和網路安全性群組。 範本也會部署已啟用憑證安全性的叢集。 對於生產叢集,請使用憑證頒發機構的憑證作為叢集憑證。 自我簽署憑證可用來保護測試叢集。

本文中的範本會部署使用憑證指紋來識別叢集憑證的叢集。 沒有兩個憑證可以具有相同的指紋,這使得憑證管理更加困難。 將已部署的叢集從憑證指紋切換至憑證通用名稱,可簡化憑證管理。 若要瞭解如何更新叢集以使用憑證通用名稱進行憑證管理,請參閱 將叢集變更為憑證通用名稱管理

使用現有的憑證建立叢集

下列指令碼會使用 New-AzServiceFabricCluster Cmdlet 和範本,在 Azure 中部署新的叢集。 Cmdlet 會在 Azure 中建立新的金鑰保存庫,並上傳您的憑證。

# Variables.
$groupname = "sfclustertutorialgroup"
$clusterloc="southcentralus"  # Must match the location parameter in the template
$templatepath="C:\temp\cluster"

$certpwd="q6D7nN%6ck@6" | ConvertTo-SecureString -AsPlainText -Force
$clustername = "mysfcluster123"  # Must match the clustername parameter in the template
$vaultname = "clusterkeyvault123"
$vaultgroupname="clusterkeyvaultgroup123"
$subname="$clustername.$clusterloc.cloudapp.azure.com"

# Sign in to your Azure account and select your subscription
Connect-AzAccount
Get-AzSubscription
Set-AzContext -SubscriptionId <guid>

# Create a new resource group for your deployment, and give it a name and a location.
New-AzResourceGroup -Name $groupname -Location $clusterloc

# Create the Service Fabric cluster.
New-AzServiceFabricCluster  -ResourceGroupName $groupname -TemplateFile "$templatepath\azuredeploy.json" `
-ParameterFile "$templatepath\azuredeploy.parameters.json" -CertificatePassword $certpwd `
-KeyVaultName $vaultname -KeyVaultResourceGroupName $vaultgroupname -CertificateFile $certpath

使用新的自我簽署憑證建立叢集

下列指令碼會使用 New-AzServiceFabricCluster Cmdlet 和範本,在 Azure 中部署新的叢集。 Cmdlet 會在 Azure 中建立新的金鑰保存庫、將新的自我簽署憑證新增至金鑰保存庫,並在本機下載憑證檔案。

# Variables.
$groupname = "sfclustertutorialgroup"
$clusterloc="southcentralus"  # Must match the location parameter in the template
$templatepath="C:\temp\cluster"

$certpwd="q6D7nN%6ck@6" | ConvertTo-SecureString -AsPlainText -Force
$certfolder="c:\mycertificates\"
$clustername = "mysfcluster123"
$vaultname = "clusterkeyvault123"
$vaultgroupname="clusterkeyvaultgroup123"
$subname="$clustername.$clusterloc.cloudapp.azure.com"

# Sign in to your Azure account and select your subscription
Connect-AzAccount
Get-AzSubscription
Set-AzContext -SubscriptionId <guid>

# Create a new resource group for your deployment, and give it a name and a location.
New-AzResourceGroup -Name $groupname -Location $clusterloc

# Create the Service Fabric cluster.
New-AzServiceFabricCluster  -ResourceGroupName $groupname -TemplateFile "$templatepath\azuredeploy.json" `
-ParameterFile "$templatepath\azuredeploy.parameters.json" -CertificatePassword $certpwd `
-CertificateOutputFolder $certfolder -KeyVaultName $vaultname -KeyVaultResourceGroupName $vaultgroupname -CertificateSubjectName $subname

連線到安全叢集

使用隨 Service Fabric SDK 一起安裝的 Service Fabric PowerShell 模組連線到叢集。 首先,將憑證安裝到您電腦上目前使用者的個人(我的)存放區中。 執行下列 PowerShell 命令:

$certpwd="q6D7nN%6ck@6" | ConvertTo-SecureString -AsPlainText -Force
Import-PfxCertificate -Exportable -CertStoreLocation Cert:\CurrentUser\My `
        -FilePath C:\mycertificates\mysfcluster20170531104310.pfx `
        -Password $certpwd

您現在已準備好連線到安全叢集。

Service Fabric PowerShell 模組提供許多 Cmdlet 來管理 Service Fabric 叢集、應用程式和服務。 使用 Connect-ServiceFabricCluster Cmdlet 連線到安全叢集。 憑證 SHA1 指紋和連線端點詳細數據可在上一個步驟的輸出中找到。

如果您先前已設定 Microsoft Entra 用戶端驗證,請執行下列命令:

Connect-ServiceFabricCluster -ConnectionEndpoint mysfcluster123.southcentralus.cloudapp.azure.com:19000 `
        -KeepAliveIntervalInSec 10 `
        -AzureActiveDirectory `
        -ServerCertThumbprint BB22CC33DD44EE55FF66AA77BB88CC99DD00EE11

如果您未設定 Microsoft Entra 用戶端驗證,請執行下列命令:

Connect-ServiceFabricCluster -ConnectionEndpoint mysfcluster123.southcentralus.cloudapp.azure.com:19000 `
          -KeepAliveIntervalInSec 10 `
          -X509Credential -ServerCertThumbprint BB22CC33DD44EE55FF66AA77BB88CC99DD00EE11 `
          -FindType FindByThumbprint -FindValue BB22CC33DD44EE55FF66AA77BB88CC99DD00EE11 `
          -StoreLocation CurrentUser -StoreName My

使用 Get-ServiceFabricClusterHealth Cmdlet 檢查您是否已連線,且叢集狀況良好。

Get-ServiceFabricClusterHealth

清理資源

本教學課程系列中的其他文章會使用您建立的叢集。 如果您未立即繼續閱讀下一篇文章,您可能想要 刪除叢集 以避免產生費用。

後續步驟

繼續閱讀下列教學課程,以瞭解如何擴展叢集。

  • 使用 PowerShell 在 Azure 中建立 VNET
  • 建立金鑰保存庫並上傳憑證
  • 設定 Microsoft Entra 驗證
  • 設定診斷資料收集
  • 設定 EventStore 服務
  • 設定 Azure 監視器記錄
  • 在 Azure PowerShell 中建立安全的 Service Fabric 叢集
  • 使用 X.509 憑證保護叢集
  • 使用 PowerShell 連線到叢集
  • 移除叢集

接下來,繼續進行下列教學課程,以瞭解如何監控叢集。