將現有可執行檔部署至 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.xsd**。The 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:

  • 程式代碼Code. 此目錄包含服務程式碼。This directory contains the service code.
  • Config。此目錄包含服務可在執行時間存取的 config.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.
  • 資料Data. 這是額外的目錄,用來儲存服務可能需要的其他本機資料。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).

注意

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