您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

教程:将 Service Fabric 应用程序部署到 Azure 中的群集Tutorial: Deploy a Service Fabric application to a cluster in Azure

本教程是一个系列中的第二部分。This tutorial is part two of a series. 它介绍如何将 Azure Service Fabric 应用程序部署到 Azure 中的新群集。It shows you how to deploy an Azure Service Fabric application to a new cluster in Azure.

本教程介绍如何执行下列操作:In this tutorial, you learn how to:

  • 创建群集。Create a cluster.
  • 使用 Visual Studio 将应用程序部署到远程群集。Deploy an application to a remote cluster using Visual Studio.

此教程系列介绍了如何:In this tutorial series, you learn how to:

先决条件Prerequisites

在开始学习本教程之前:Before you begin this tutorial:

下载投票示例应用程序Download the voting sample application

如果未生成本教程系列的第一部分中的投票示例应用程序,可以下载它。If you didn't build the voting sample application in part one of this tutorial series, you can download it. 在命令窗口中,运行以下代码,将示例应用程序存储库克隆到本地计算机。In a command window, run the following code to clone the sample application repository to your local machine.

git clone https://github.com/Azure-Samples/service-fabric-dotnet-quickstart 

在 Visual Studio 中打开应用程序,以管理员身份运行,然后生成应用程序。Open the application in Visual Studio, running as administrator, and build the application.

创建群集Create a cluster

应用程序就绪以后,即可创建 Service Fabric 群集,然后将应用程序部署到群集。Now that the application is ready, you create a Service Fabric cluster and then deploy the application to the cluster. Service Fabric 群集是一组通过网络连接在一起的虚拟机或物理计算机,微服务会在其中部署和管理。A Service Fabric cluster is a network-connected set of virtual or physical machines into which your microservices are deployed and managed.

在本教程中,请在 Visual Studio IDE 中创建一个新的三节点型测试群集,然后将应用程序发布到该群集。In this tutorial, you create a new three node test cluster in the Visual Studio IDE and then publish the application to that cluster. 请参阅有关创建和管理群集的教程,了解如何创建生产群集。See the Create and manage a cluster tutorial for information on creating a production cluster. 也可通过 Azure 门户PowerShelAzure CLI 脚本或 Azure 资源管理器模板将应用程序部署到此前已创建的现有群集。You can also deploy the application to an existing cluster that you previously created through the Azure portal, by using PowerShell or Azure CLI scripts, or from an Azure Resource Manager template.

备注

Voting 应用程序和许多其他的应用程序使用 Service Fabric 反向代理在服务之间通信。The Voting application, and many other applications, use the Service Fabric reverse proxy to communicate between services. 通过 Visual Studio 创建的群集默认启用反向代理。Clusters created from Visual Studio have the reverse proxy enabled by default. 如果部署到现有的群集,则必须在群集中启用反向代理,否则 Voting 应用程序无法正常运行。If you're deploying to an existing cluster, you must enable the reverse proxy in the cluster for the Voting application to work.

找到 VotingWeb 服务终结点Find the VotingWeb service endpoint

如果已按照此教程系列的第一部分中的步骤操作,则 Voting 应用程序的前端 Web 服务会在特定端口 (8080) 上进行侦听。The front-end web service of the Voting application is listening on a specific port (8080 if you in followed the steps in part one of this tutorial series. 当应用程序部署到 Azure 中的群集时,该群集和应用程序都在 Azure 负载均衡器之后运行。When the application deploys to a cluster in Azure, both the cluster and the application run behind an Azure load balancer. 必须使用规则在 Azure 负载均衡器中打开应用程序端口。The application port must be opened in the Azure load balancer by using a rule. 此规则通过负载均衡器将入站流量发送到 Web 服务。The rule sends inbound traffic through the load balancer to the web service. 端口可以在 VotingWeb/PackageRoot/ServiceManifest.xml 文件的 Endpoint 元素中找到。The port is found in the VotingWeb/PackageRoot/ServiceManifest.xml file in the Endpoint element.

<Endpoint Protocol="http" Name="ServiceEndpoint" Type="Input" Port="8080" />

记下服务终结点,后续步骤中需要使用它。Take note of the service endpoint, which is needed in a later step. 如果要部署到现有群集,请使用 PowerShell 脚本在 Azure 负载均衡器中创建负载均衡规则和探测,或者在 Azure 门户中通过此群集的负载均衡器打开此端口。If you're deploying to an existing cluster, open this port by creating a load-balancing rule and probe in the Azure load balancer using a PowerShell script or via the load balancer for this cluster in the Azure portal.

在 Azure 中创建测试群集Create a test cluster in Azure

在“解决方案资源管理器”中,右键单击“Voting”并选择“发布” 。In Solution Explorer, right-click on Voting and select Publish.

在“连接终结点”中,选择“创建新群集” 。In Connection Endpoint, select Create New Cluster. 如果要部署到现有群集,请从列表中选择群集终结点。If you're deploying to an existing cluster, select the cluster endpoint from the list. 此时会打开“创建 Service Fabric 群集”对话框。The Create Service Fabric Cluster dialog opens.

在“群集”选项卡中, 输入群集名称(例如“mytestcluster”),选择订阅,选择群集的区域(例如“美国中南部”),输入群集节点的数目(对于测试群集,建议使用三节点),然后输入资源组(例如“mytestclustergroup”)。In the Cluster tab, enter the Cluster name (for example, "mytestcluster"), select your subscription, select a region for the cluster (such as South Central US), enter the number of cluster nodes (we recommend three nodes for a test cluster), and enter a resource group (such as "mytestclustergroup"). 单击“下一步”。 Click Next.

创建群集

在“证书”选项卡中,输入群集证书的密码和输出路径。 In the Certificate tab, enter the password and output path for the cluster certificate. 自签名证书创建为 PFX 文件并保存到指定的输出路径。A self-signed certificate is created as a PFX file and saved to the specified output path. 使用证书是为了确保节点到节点和客户端到节点的安全。The certificate is used for both node-to-node and client-to-node security. 请勿将自签名证书用于生产群集。Don't use a self-signed certificate for production clusters. 此证书由 Visual Studio 用于对群集进行身份验证,以及用于部署应用程序。This certificate is used by Visual Studio to authenticate with the cluster and deploy applications. 选择“导入证书”,以便 将 PFX 安装在计算机的 CurrentUser\My certificate 存储中。Select Import certificate to install the PFX in the CurrentUser\My certificate store of your computer. 单击“下一步”。 Click Next.

创建群集

在“VM 详细信息”选项卡中,输入群集管理员帐户的“用户名”和“密码”。 In the VM Detail tab, enter the User name and Password for the cluster admin account. 选择群集节点的“虚拟机映像”,以及每个群集节点的“虚拟机大小”。 Select the Virtual machine image for the cluster nodes and the Virtual machine size for each cluster node. 单击“高级” 选项卡。Click the Advanced tab.

创建群集

在“端口”中, 输入上一步的 VotingWeb 服务终结点(例如 8080)。In Ports, enter the VotingWeb service endpoint from the previous step (for example, 8080). 创建群集以后,这些应用程序端口会在 Azure 负载均衡器中打开,这样就可以将流量转发到群集。When the cluster is created, these application ports are opened in the Azure load balancer to forward traffic to the cluster. 单击“创建”即可创建群集,这需要几分钟的时间。 Click Create to create the cluster, which takes several minutes.

创建群集

将应用程序发布到群集Publish the application to the cluster

新群集就绪以后,即可直接通过 Visual Studio 部署 Voting 应用程序。When the new cluster is ready, you can deploy the Voting application directly from Visual Studio.

在“解决方案资源管理器”中,右键单击“Voting”并选择“发布” 。In Solution Explorer, right-click on Voting and select Publish. 此时会显示“发布”对话框。 The Publish dialog box appears.

在“连接终结点”中,选择在上一步创建的群集的终结点 。In Connection Endpoint, select the endpoint for the cluster you created in the previous step. 例如,“mytestcluster.southcentral.cloudapp.azure.com:19000”。For example, "mytestcluster.southcentral.cloudapp.azure.com:19000". 如果选择“高级连接参数”,则会自动填充证书信息。 If you select Advanced Connection Parameters, the certificate information should be auto-filled.
发布 Service Fabric 应用程序Publish a Service Fabric application

选择“发布” 。Select Publish.

应用程序部署完以后,请打开浏览器并输入群集地址,后跟 :8080Once the application is deployed, open a browser and enter the cluster address followed by :8080. 或者输入另一端口(如果已配置一个)。Or enter another port if one is configured. 例如 http://mytestcluster.southcentral.cloudapp.azure.com:8080An example is http://mytestcluster.southcentral.cloudapp.azure.com:8080. 会看到应用程序在 Azure 群集中运行。You see the application running in the cluster in Azure. 在投票网页中,尝试添加和删除投票选项,并针对这些选项中的一个或多个进行投票。In the voting web page, try adding and deleting voting options and voting for one or more of these options.

Service Fabric 投票示例

后续步骤Next steps

本教程的此部分介绍了如何:In this part of the tutorial, you learned how to:

  • 创建群集。Create a cluster.
  • 使用 Visual Studio 将应用程序部署到远程群集。Deploy an application to a remote cluster using Visual Studio.

转到下一教程:Advance to the next tutorial: