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

将现有可执行文件部署到 Service FabricDeploy an existing executable to Service Fabric

可以在 Azure Service Fabric 中运行任何类型的代码(如 Node.js、Java 或 C++)作为服务。You can run any type of code, such as Node.js, Java, or C++ in Azure Service Fabric as a service. Service Fabric 将这些类型的服务称为来宾可执行文件。Service Fabric refers to these types of services as guest executables.

来宾可执行文件由 Service Fabric 如同无状态服务一样进行处理。Guest executables are treated by Service Fabric like stateless services. 因此,它们会基于可用性和其他指标放在群集中的节点上。As a result, they are placed on nodes in a cluster, based on availability and other metrics. 本文介绍了如何使用 Visual Studio 或命令行实用工具打包来宾可执行文件,并将其部署到 Service Fabric 群集中。This article describes how to package and deploy a guest executable to a Service Fabric cluster, by using Visual Studio or a command-line utility.

在 Service Fabric 中运行来宾可执行文件的好处Benefits of running a guest executable in Service Fabric

在 Service Fabric 群集中运行来宾可执行文件有诸多优势:There are several advantages to running a guest executable in a Service Fabric cluster:

  • 高可用性。High availability. 在 Service Fabric 中运行的应用程序都是高度可用的。Applications that run in Service Fabric are made highly available. Service Fabric 会确保应用程序的实例正在运行。Service Fabric ensures that instances of an application are running.
  • 运行状况监视。Health monitoring. Service Fabric 运行状况监视功能可检测应用程序是否正在运行,并在出现故障时提供诊断信息。Service Fabric health monitoring detects if an application is running, and provides diagnostic information if there is a failure.
  • 应用程序生命周期管理。Application lifecycle management. 除了提供无需停机的升级,Service Fabric 还可以在升级过程中报告坏健康事件时自动回滚到先前的版本。Besides providing upgrades with no downtime, Service Fabric provides automatic rollback to the previous version if there is a bad health event reported during an upgrade.
  • 密度。Density. 可以在群集中运行多个应用程序,这样便无需使每个应用程序在自己的硬件上运行。You can run multiple applications in a cluster, which eliminates the need for each application to run on its own hardware.
  • 可发现性使用 REST, 你可以调用 Service Fabric 命名服务以在群集中查找其他服务。Discoverability: Using REST you can call the Service Fabric Naming service to find other services in the cluster.

示例Samples

应用程序和服务清单文件概述Overview of application and service manifest files

在部署来宾可执行文件期间,最好先了解 Service Fabric 打包和部署模型(如应用程序模型中所述)。As part of deploying a guest executable, it is useful to understand the Service Fabric packaging and deployment model as described in application model. Service Fabric 打包模型依赖两个 XML 文件:应用程序清单和服务清单。The Service Fabric packaging model relies on two XML files: the application and service manifests. ApplicationManifest.xml 和 ServiceManifest.xml 文件的架构定义随 Service Fabric SDK 一起安装到 C:\Program Files\Microsoft SDKs\Service Fabric\schemas\ServiceFabricServiceModel.xsdThe schema definition for the ApplicationManifest.xml and ServiceManifest.xml files is installed with the Service Fabric SDK into C:\Program Files\Microsoft SDKs\Service Fabric\schemas\ServiceFabricServiceModel.xsd.

  • 应用程序清单:应用程序清单用于描述应用程序。Application manifest The application manifest is used to describe the application. 其中会列出应用程序所包含的服务,以及用于定义应如何部署一个或多个服务的其他参数(如实例数)。It lists the services that compose it, and other parameters that are used to define how one or more services should be deployed, such as the number of instances.

    在 Service Fabric 中,应用程序就是一个部署和升级单元。In Service Fabric, an application is a unit of deployment and upgrade. 可将应用程序作为一个单位进行升级,其中潜在的失败和潜在回滚受到管理。An application can be upgraded as a single unit where potential failures and potential rollbacks are managed. Service Fabric 可保证要么升级成功,要么即使升级失败,也不会让应用程序处于未知或不稳定状态。Service Fabric guarantees that the upgrade process is either successful, or, if the upgrade fails, does not leave the application in an unknown or unstable state.

  • 服务清单 服务清单描述服务的组件。Service manifest The service manifest describes the components of a service. 其中包括数据(如服务的名称和类型)及其代码和配置。It includes data, such as the name and type of service, and its code and configuration. 服务清单还包含一些可以用于在部署之后配置服务的其他参数。The service manifest also includes some additional parameters that can be used to configure the service once it is deployed.

应用程序包文件结构Application package file structure

应用程序应遵循预定义的目录结构,才能将应用程序部署到 Service Fabric。To deploy an application to Service Fabric, the application should follow a predefined directory structure. 下面的示例展示了此结构。The following is an example of that structure.

|-- ApplicationPackageRoot
    |-- GuestService1Pkg
        |-- Code
            |-- existingapp.exe
        |-- Config
            |-- Settings.xml
        |-- Data
        |-- ServiceManifest.xml
    |-- ApplicationManifest.xml

ApplicationPackageRoot 包含定义应用程序的 ApplicationManifest.xml 文件。The ApplicationPackageRoot contains the ApplicationManifest.xml file that defines the application. 应用程序中包含的每个服务的子目录用于包含相应服务需要的所有项目。A subdirectory for each service included in the application is used to contain all the artifacts that the service requires. 这些子目录为 ServiceManifest.xml 以及如下目录(一般情况下):These subdirectories are the ServiceManifest.xml and, typically, the following:

  • CodeCode. 此目录包含服务代码。This directory contains the service code.
  • Config。此目录包含一个 Settings.xml 文件(必要时,还包含其他文件),服务可以在运行时访问该文件以检索特定的配置设置。Config. This directory contains a Settings.xml file (and other files if necessary) that the service can access at runtime to retrieve specific configuration settings.
  • DataData. 这是用于存储服务可能需要的其他本地数据的其他目录。This is an additional directory to store additional local data that the service may need. Data 只应用来存储暂存数据。Data should be used to store only ephemeral data. 如果服务需要进行重定位(例如,在故障转移期间),Service Fabric 不会复制数据目录所发生的变化。Service Fabric does not copy or replicate changes to the data directory if the service needs to be relocated (for example, during failover).

备注

如果不需要,就无需创建 configdata 目录。You don't have to create the config and data directories if you don't need them.

后续步骤Next steps

请参阅下面几篇文章,了解相关信息和任务。See the following articles for related information and tasks.