将现有可执行文件部署到 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 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).

Note

如果不需要 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.