教程:将运行 Windows 的 Service Fabric 群集部署到 Azure 虚拟网络

本教程是一个系列中的第一部分。 其中介绍了如何通过使用 PowerShell 和模板,将运行 Windows 的 Service Fabric 群集部署到 Azure 虚拟网络网络安全组。 完成本教程后,云中会运行一个可在其中部署应用程序的群集。 要创建使用 Azure CLI 的 Linux 群集,请参阅在 Azure 上创建安全的 Linux 群集

本教程介绍一个生产方案。 要创建小型群集以供测试,请参阅创建测试群集

在本教程中,你将了解如何执行以下操作:

  • 使用 PowerShell 在 Azure 中创建 VNET
  • 创建 Key Vault 并上传证书
  • 设置 Microsoft Entra 身份验证
  • 配置诊断集合
  • 设置 EventStore 服务
  • 设置 Azure Monitor 日志
  • 在 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 资源管理器模板文件:

注意

必须修改从 GitHub 存储库“Azure-Samples”下载或参考的模板,以适应由世纪互联运营的 Microsoft Azure 环境。 例如,替换某些终结点(将“blob.core.windows.net”替换为“blob.core.chinacloudapi.cn”,将“cloudapp.azure.com”替换为“cloudapp.chinacloudapi.cn”);必要时更改某些不受支持的位置、VM 映像、VM 大小、SKU 以及资源提供程序的 API 版本。

在本文中,在成功下载相应的文件后,我们应当替换以下配置来满足由世纪互联运营的 Microsoft Azure 环境:

此模板将包含七个虚拟机和三个节点类型的安全群集部署到虚拟网络和网络安全组中。 其他示例模板可以在 GitHub 上找到。 azuredeploy.json 部署若干资源,包括以下资源。

Service Fabric 群集

Microsoft.ServiceFabric/clusters 资源中,配置了具有以下特征的 Windows 群集:

  • 三个节点类型。
  • 主节点类型包含五个节点(可在模板参数中配置),其他两个节点类型各包含一个节点。
  • OS:包含容器的 Windows Server 2016 Datacenter(可在模板参数中配置)。
  • 证书保护(可在模板参数中配置)。
  • 已启用反向代理
  • 已启用 DNS 服务
  • 铜级持久性级别(可在模板参数中配置)。
  • 银级可靠性级别(可在模板参数中配置)。
  • 客户端连接终结点:19000(可在模板参数中配置)。
  • HTTP 网关终结点:19080(可在模板参数中配置)。

Azure 负载均衡器

在 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
  • Internodecommunication:1025、1026、1027
  • 临时端口范围:49152 到 65534(至少需要 256 个端口)。
  • 应用程序使用的端口:80 和 443
  • 应用程序端口范围:49152 到 65534(用于测试服务间的通信。其他端口不会在负载均衡器上打开)。
  • 阻止其他所有端口

如需其他应用程序端口,则需要调整 Microsoft.Network/loadBalancers 资源和 Microsoft.Network/networkSecurityGroups 资源,以允许传入流量 。

Windows Defender

默认情况下,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 参数文件声明用于部署群集和关联资源的多个值。 下面是要为部署修改的参数:

参数 示例值 说明
adminUserName vmadmin 群集 VM 的管理员用户名。 VM 的用户名要求
adminPassword Password#1234 群集 VM 的管理员密码。 VM 的密码要求
clusterName mysfcluster123 群集的名称。 仅可包含字母和数字。 长度可介于 3 到 23 个字符之间。
location chinaeast 群集的位置。
certificateThumbprint

如果创建自签名证书或提供证书文件,则值应为空。

若要使用之前上传到密钥保管库的现有证书,请填写证书 SHA1 指纹值。 例如“6190390162C988701DB5676EB81083EA608DCCF3”。

certificateUrlValue

如果创建自签名证书或提供证书文件,则值应为空。

若要使用之前上传到 Key Vault 的现有证书,请填写证书 URL。 例如,"https://mykeyvault.vault.azure.cn:443/secrets/mycertificate/02bea722c9ef4009a76c5052bcbf8346"。

sourceVaultValue

如果创建自签名证书或提供证书文件,则值应为空。

若要使用之前上传到 Key Vault 的现有证书,请填写源保管库值。 例如“/subscriptions/333cc2c84-12fa-5778-bd71-c71c07bf873f/resourceGroups/MyTestRG/providers/Microsoft.KeyVault/vaults/MYKEYVAULT”。

设置 Microsoft Entra 客户端身份验证

如果将 Service Fabric 群集部署在某个公共网络中,而该网络托管在 Azure 上,则对于客户端到节点型相互身份验证,建议如下:

  • 将 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 租户

为了简化涉及到配置 Microsoft Entra ID 与 Service Fabric 群集的步骤,我们创建了一组 Windows PowerShell 脚本。 将脚本下载到计算机。

创建 Microsoft Entra 应用程序并为用户分配角色

创建两个 Microsoft Entra 应用程序来控制对群集的访问权限:一个 Web 应用程序和一个本机应用程序。 创建用于表示群集的应用程序后,请将用户分配到 Service Fabric 支持的角色:只读和管理员。

运行 SetupApplications.ps1 并提供租户 ID、群集名称和 Web 应用程序回复 URL 作为参数。 请指定用户的用户名和密码。 例如:

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

注意

对于由世纪互联运营的 Microsoft Azure,请指定 -Location 参数。

可在 Azure 门户中找到 TenantId 或目录 ID。 选择“Microsoft Entra ID”>“属性”并复制“目录 ID”的值。

ClusterName 用作脚本创建的 Microsoft Entra 应用程序的前缀。 无需完全匹配实际的群集名称。 只是为了操作更加简便,可将 Microsoft Entra 项目映射到正在使用的 Service Fabric 群集。

WebApplicationReplyUrl 是 Microsoft Entra ID 在完成登录过程之后返回给用户的默认终结点。 将此终结点设置为群集的 Service Fabric Explorer 的终结点,默认值为:

https://<cluster_domain>:19080/Explorer

系统会提示登录到具有 Microsoft Entra 租户管理权限的帐户。 完成此操作后,脚本会创建 Web 和本机应用程序来代表 Service Fabric 群集。 在 Azure 门户中的租户的应用程序中,应会看到两个新条目:

  • ClusterName_Cluster
  • ClusterName_Client

创建群集时该脚本显示资源管理器模板所需的 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 存储、也能选择发送日志到 Azure Application Insights 或事件中心的 Azure 诊断 (WAD) 扩展。 也可以使用外部进程读取存储中的事件,并将其放在分析平台产品(例如 Azure Monitor 日志或其他日志分析解决方案)中。

如果是按照本教程执行的操作,则已在模板中配置了诊断集合。

如果存在尚未部署诊断的现有群集,可以通过群集模板来添加或更新该扩展。 修改用于创建现有群集的资源管理器模板,或者从门户下载该模板。 执行以下任务来修改 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": {
                        "storageAccountEndPoint": "https://core.chinacloudapi.cn/",
                        "storageAccountName": "[parameters('applicationDiagnosticsStorageAccountName')]",
                        "storageAccountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('applicationDiagnosticsStorageAccountName')),'2015-05-01-preview').key1]",
                        "storageAccountEndPoint": "https://core.chinacloudapi.cn/"
                        },
                        "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 和 API 公开。 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 Monitor 日志

要监视群集级别的事件,建议使用 Azure Monitor 日志。 要设置 Azure Monitor 日志来监视群集,需要启用诊断功能以查看群集级别事件

需要将工作区连接到来自群集的诊断数据。 此日志数据存储在 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": "China North",
        "allowedValues": [
            "China North",
            "China East",
            "China East"
        ],
        "metadata": {
            "description": "Specify the Azure Region for your OMS workspace"
        }
    }
}

下一步,添加变量:

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

将 Log Analytics 代理扩展添加到群集中的每个虚拟机规模集,并将代理连接到 Log Analytics 工作区。 这可收集关于容器、应用程序和性能监视的诊断数据。 通过将其作为扩展添加到虚拟机规模集资源,Azure 资源管理器可确保它安装在每个节点上,即使在缩放群集时也是如此。

"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 资源管理器模板针对 Service Fabric 创建虚拟网络、子网和网络安全组。 该模板还会部署一个已启用证书安全性的群集。 对于生产群集,请使用证书颁发机构提供的证书作为群集证书。 可以使用自签名证书来保护测试群集。

本文中的模板部署一个群集,该群集使用证书指纹来标识群集证书。 两个证书不能有相同的指纹,否则会增加证书管理的难度。 将已部署的群集从证书指纹切换为证书公用名称可简化证书管理。 若要了解如何更新群集,以便使用证书公用名称进行证书管理,请阅读将群集更改为使用证书公用名称进行管理

通过使用现有证书创建群集

以下脚本使用 New-AzServiceFabricCluster cmdlet 和模板在 Azure 中部署新群集。 该 cmdlet 在 Azure 中创建新的密钥保管库,并上传证书。

# Variables.
$groupname = "sfclustertutorialgroup"
$clusterloc="chinaeast"  # 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.chinacloudapi.cn"

# Sign in to your Azure account and select your subscription
Connect-AzAccount -Environment AzureChinaCloud
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 中创建新的 Key Vault、向 Key Vault 添加新的自签名证书,并将证书文件下载到本地。

# Variables.
$groupname = "sfclustertutorialgroup"
$clusterloc="chinaeast"  # 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.chinacloudapi.cn"

# Sign in to your Azure account and select your subscription
Connect-AzAccount -Environment AzureChinaCloud
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.chinaeast.cloudapp.chinacloudapi.cn:19000 `
        -KeepAliveIntervalInSec 10 `
        -AzureActiveDirectory `
        -ServerCertThumbprint C4C1E541AD512B8065280292A8BA6079C3F26F10

如果没有设置过 Microsoft Entra 客户端身份验证,请运行以下命令:

Connect-ServiceFabricCluster -ConnectionEndpoint mysfcluster123.chinaeast.cloudapp.chinacloudapi.cn:19000 `
          -KeepAliveIntervalInSec 10 `
          -X509Credential -ServerCertThumbprint C4C1E541AD512B8065280292A8BA6079C3F26F10 `
          -FindType FindByThumbprint -FindValue C4C1E541AD512B8065280292A8BA6079C3F26F10 `
          -StoreLocation CurrentUser -StoreName My

通过使用 Get-ServiceFabricClusterHealth cmdlet 检查是否已连接并且群集是否正常运行。

Get-ServiceFabricClusterHealth

清理资源

本教程系列中的其他文章将会使用本文中创建的群集。 如果不立即转到下一篇文章,可能需要删除该群集,以避免产生费用。

后续步骤

请转到以下教程了解如何缩放群集。

  • 使用 PowerShell 在 Azure 中创建 VNET
  • 创建 Key Vault 并上传证书
  • 设置 Microsoft Entra 身份验证
  • 配置诊断集合
  • 设置 EventStore 服务
  • 设置 Azure Monitor 日志
  • 在 Azure PowerShell 中创建安全的 Service Fabric 群集
  • 使用 X.509 证书保护群集
  • 使用 PowerShell 连接到群集
  • 删除群集

下一步,请转到以下教程了解如何监视群集。