將現有可執行檔封裝和部署至 Service FabricPackage and deploy an existing executable to Service Fabric

在封裝現有可執行檔作為來賓可執行檔時,您可以選擇使用 Visual Studio 專案範本,或是手動建立應用程式套件When packaging an existing executable as a guest executable, you can choose either to use a Visual Studio project template or to create the application package manually. 使用 Visual Studio 時,就可讓 [新增專案範本] 為您建立應用程式套件的結構和資訊清單檔案。Using Visual Studio, the application package structure and manifest files are created by the new project template for you.

提示

將現有 Windows 可執行檔封裝成服務的最簡單方式,就是使用 Visual Studio,而在 Linux 上則是使用 YeomanThe easiest way to package an existing Windows executable into a service is to use Visual Studio and on Linux to use Yeoman

使用 Visual Studio 來封裝及部署現有的可執行檔Use Visual Studio to package and deploy an existing executable

Visual Studio 會提供 Service Fabric 服務範本,協助您將來賓可執行檔部署至 Service Fabric 叢集。Visual Studio provides a Service Fabric service template to help you deploy a guest executable to a Service Fabric cluster.

  1. > 選擇 [ 檔案] [新增] [專案],然後建立 Service Fabric 應用程式。Choose File > New Project, and create a Service Fabric application.
  2. 選擇 [來賓執行檔]**** 做為服務範本。Choose Guest Executable as the service template.
  3. 按一下 [流覽] 以選取包含您可執行檔的資料夾,並填入其餘參數以建立服務。Click Browse to select the folder with your executable and fill in the rest of the parameters to create the service.
    • 程式代碼封裝行為Code Package Behavior. 可設定為將資料夾的所有內容複製到 Visual Studio 專案,這在執行檔沒有變更時很有用。Can be set to copy all the content of your folder to the Visual Studio Project, which is useful if the executable does not change. 如果您預期會變更可執行檔,並想要以動態方式取得新組建,則可以選擇改為連結到資料夾。If you expect the executable to change and want the ability to pick up new builds dynamically, you can choose to link to the folder instead. 在 Visual Studio 中建立應用程式專案時,您可以使用連結的資料夾。You can use linked folders when creating the application project in Visual Studio. 這會從專案內連結到來源位置,讓您可以在來源目的地更新來賓執行檔。This links to the source location from within the project, making it possible for you to update the guest executable in its source destination. 在組建時使這些更新會成為應用程式套件的一部分。Those updates become part of the application package on build.
    • 「Program」** 指定應執行以便啟動服務的執行檔。Program specifies the executable that should be run to start the service.
    • 「Arguments」** 指定應傳遞至執行檔的引數。Arguments specifies the arguments that should be passed to the executable. 這可以是具有引數的參數清單。It can be a list of parameters with arguments.
    • 「WorkingFolder」** 指定即將啟動之程序的工作目錄。WorkingFolder specifies the working directory for the process that is going to be started. 您可以指定三個值:You can specify three values:
      • CodeBase 指定工作目錄即將設為應用程式套件中的 code 目錄 (先前檔案結構中所示的 Code 目錄)。CodeBase specifies that the working directory is going to be set to the code directory in the application package (Code directory shown in the preceding file structure).
      • CodePackage 指定工作目錄即將設為應用程式套件中的根目錄 (先前檔案結構中所示的 GuestService1Pkg)。CodePackage specifies that the working directory is going to be set to the root of the application package (GuestService1Pkg shown in the preceding file structure).
      • Work 指定檔案放在名為 work 的子目錄中。Work specifies that the files are placed in a subdirectory called work.
  4. 指定服務的名稱,然後按一下 [確定]****。Give your service a name, and click OK.
  5. 如果服務需要用來進行通訊的端點,您現在可以將 protocol、port 和 type 新增至 ServiceManifest.xml 檔案。If your service needs an endpoint for communication, you can now add the protocol, port, and type to the ServiceManifest.xml file. 例如: <Endpoint Name="NodeAppTypeEndpoint" Protocol="http" Port="3000" UriScheme="http" PathSuffix="myapp/" Type="Input" />For example: <Endpoint Name="NodeAppTypeEndpoint" Protocol="http" Port="3000" UriScheme="http" PathSuffix="myapp/" Type="Input" />.
  6. 您現在可以藉由在 Visual Studio 中偵錯方案,對本機叢集執行封裝和發佈動作。You can now use the package and publish action against your local cluster by debugging the solution in Visual Studio. 準備好時,即可將應用程式發佈至遠端叢集,或將方案簽入到原始檔控制。When ready, you can publish the application to a remote cluster or check in the solution to source control.
  7. 請參閱檢查您的執行中應用程式,以了解如何檢視 Service Fabric Explorer 中執行的來賓執行檔服務。Read check your running application to see how to view your guest executable service running in Service Fabric Explorer.

如需逐步解說範例,請參閱使用 Visual Studio 建立第一個客體可執行檔應用程式For an example walkthrough, see Create your first guest executable application using Visual Studio.

使用 Visual Studio 封裝多個可執行檔Packaging multiple executables with Visual Studio

您可以使用 Visual Studio 來產生應用程式封裝,其中包含多個來賓可執行檔。You can use Visual Studio to produce an application package that contains multiple guest executables. 新增第一個來賓可執行檔之後,以滑鼠右鍵按一下應用程式專案,然後選取 [新增 >新 Service Fabric 服務,將第二個來賓可執行檔專案新增至方案。After adding the first guest executable, right click on the application project and select the Add->New Service Fabric service to add the second guest executable project to the solution.

注意

如果您選擇在 Visual Studio 專案中連結來源,則建置 Visual Studio 方案將可確保應用程式封裝是最新的,並且含有來源中的變更。If you choose to link the source in the Visual Studio project, building the Visual Studio solution, will make sure that your application package is up to date with changes in the source.

使用 Yoeman 在 Linux 上封裝及部署現有的可執行檔Use Yeoman to package and deploy an existing executable on Linux

在 Linux 上建立及部署來賓可執行檔的程序與部署 csharp 或 java 應用程式的程序相同。The procedure for creating and deploying a guest executable on Linux is the same as deploying a csharp or java application.

  1. 在終端機中,輸入 yo azuresfguestIn a terminal, type yo azuresfguest.
  2. 為您的應用程式命名。Name your application.
  3. 為您的服務命名並提供詳細資料,包括可執行檔的路徑,以及叫用它時所必須使用的參數。Name your service, and provide the details including path of the executable and the parameters it must be invoked with.

Yeoman 會建立應用程式套件,其中包含適當的應用程式和資訊清單檔案,以及安裝和解除安裝指令碼。Yeoman creates an application package with the appropriate application and manifest files along with install and uninstall scripts.

在 Linux 上使用 Yeoman 封裝多個可執行檔Packaging multiple executables using Yeoman on Linux

若要將其他服務新增至已使用 yo 建立的應用程式,請執行下列步驟︰To add another service to an application already created using yo, perform the following steps:

  1. 將目錄變更為現有應用程式的根目錄。Change directory to the root of the existing application. 例如,如果 MyApplication 是 Yeoman 所建立的應用程式,則為 cd ~/YeomanSamples/MyApplicationFor example, cd ~/YeomanSamples/MyApplication, if MyApplication is the application created by Yeoman.
  2. 執行 yo azuresfguest:AddService 並提供必要的詳細資料。Run yo azuresfguest:AddService and provide the necessary details.

手動封裝和部署現有執行檔Manually package and deploy an existing executable

手動封裝來賓執行檔的程序是基於下列步驟:The process of manually packaging a guest executable is based on the following general steps:

  1. 建立套件目錄結構。Create the package directory structure.
  2. 新增應用程式的程式碼和組態檔。Add the application's code and configuration files.
  3. 編輯服務資訊清單檔。Edit the service manifest file.
  4. 編輯應用程式資訊清單檔。Edit the application manifest file.

建立套件目錄結構Create the package directory structure

您可以從建立目錄結構開始,如封裝 Azure Service Fabric 應用程式中所述。You can start by creating the directory structure, as described in Package an Azure Service Fabric App.

新增應用程式的程式碼和組態檔Add the application's code and configuration files

建立目錄結構之後,您可以在 code 和 config 目錄之下新增應用程式的程式碼和組態檔。After you have created the directory structure, you can add the application's code and configuration files under the code and config directories. 您也可以在 code 和 config 目錄之下建立其他目錄或子目錄。You can also create additional directories or subdirectories under the code or config directories.

Service Fabric 會進行應用程式根目錄內容的 xcopy,所以除了建立兩個最上層目錄 code 和 settings 以外,沒有預先定義的結構可使用 Service Fabric does an xcopy of the content of the application root directory, so there is no predefined structure to use other than creating two top directories, code and settings. (您可以選擇不同的名稱。(You can pick different names if you want. 下一節中有更多詳細資訊)。More details are in the next section.)

注意

請確定您包含應用程式需要的所有檔案和相依項目。Make sure that you include all the files and dependencies that the application needs. Service Fabric 會將應用程式套件的內容,複製到即將部署應用程式服務的叢集中的所有節點上。Service Fabric copies the content of the application package on all nodes in the cluster where the application's services are going to be deployed. 該套件應包含應用程式需要執行的所有程式碼。The package should contain all the code that the application needs to run. 請勿假設已經安裝相依項目。Do not assume that the dependencies are already installed.

編輯服務資訊清單檔Edit the service manifest file

下一步就是編輯服務資訊清單檔以包含下列資訊:The next step is to edit the service manifest file to include the following information:

  • 服務類型的名稱。The name of the service type. 這是 Service Fabric 用來識別服務的識別碼。This is an ID that Service Fabric uses to identify a service.
  • 用來啟動應用程式 (ExeHost) 的命令。The command to use to launch the application (ExeHost).
  • 必須執行才能安裝應用程式 (SetupEntrypoint) 的任何指令碼。Any script that needs to be run to set up the application (SetupEntrypoint).

以下是 ServiceManifest.xml 檔案的範例:The following is an example of a ServiceManifest.xml file:

<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" Name="NodeApp" Version="1.0.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
   <ServiceTypes>
      <StatelessServiceType ServiceTypeName="NodeApp" UseImplicitHost="true"/>
   </ServiceTypes>
   <CodePackage Name="code" Version="1.0.0.0">
      <SetupEntryPoint>
         <ExeHost>
             <Program>scripts\launchConfig.cmd</Program>
         </ExeHost>
      </SetupEntryPoint>
      <EntryPoint>
         <ExeHost>
            <Program>node.exe</Program>
            <Arguments>bin/www</Arguments>
            <WorkingFolder>CodePackage</WorkingFolder>
         </ExeHost>
      </EntryPoint>
   </CodePackage>
   <Resources>
      <Endpoints>
         <Endpoint Name="NodeAppTypeEndpoint" Protocol="http" Port="3000" Type="Input" />
      </Endpoints>
   </Resources>
</ServiceManifest>

接下來幾節說明您需要更新的不同檔案部分。The following sections go over the different parts of the file that you need to update.

更新 ServiceTypesUpdate ServiceTypes

<ServiceTypes>
  <StatelessServiceType ServiceTypeName="NodeApp" UseImplicitHost="true" />
</ServiceTypes>
  • 您可以挑選任何您要用於 ServiceTypeName 的名稱。You can pick any name that you want for ServiceTypeName. 此值在 ApplicationManifest.xml 檔案中用來識別服務。The value is used in the ApplicationManifest.xml file to identify the service.
  • 指定 UseImplicitHost="true"Specify UseImplicitHost="true". 此屬性會告知 Service Fabric,此服務是以獨立式 (Self-Contained) 應用程式為基礎,所以 Service Fabric 只要將它當作程序啟動並監視其健康狀況即可。This attribute tells Service Fabric that the service is based on a self-contained app, so all Service Fabric needs to do is to launch it as a process and monitor its health.

更新 CodePackageUpdate CodePackage

CodePackage 元素指定服務程式碼的位置 (和版本)。The CodePackage element specifies the location (and version) of the service's code.

<CodePackage Name="Code" Version="1.0.0.0">

Name 元素用來在包含服務程式碼的應用程式套件中指定目錄的名稱。The Name element is used to specify the name of the directory in the application package that contains the service's code. CodePackage 也有 version 屬性。CodePackage also has the version attribute. 這可用來指定程式碼的版本,而在 Service Fabric 中利用應用程式生命週期管理基礎結構,也可能用來升級服務的程式碼。This can be used to specify the version of the code, and can also potentially be used to upgrade the service's code by using the application lifecycle management infrastructure in Service Fabric.

選擇性︰更新 SetupEntrypointOptional: Update SetupEntrypoint

<SetupEntryPoint>
   <ExeHost>
       <Program>scripts\launchConfig.cmd</Program>
   </ExeHost>
</SetupEntryPoint>

SetupEntryPoint 元素用來指定任何應在服務的程式碼啟動前執行的可執行檔或批次檔。The SetupEntryPoint element is used to specify any executable or batch file that should be executed before the service's code is launched. 這是選擇性步驟,因此如果不需要初始化,則不需納入此元素。It is an optional step, so it does not need to be included if there is no initialization required. 每次重新啟動服務時,就會執行 SetupEntrypoint。The SetupEntryPoint is executed every time the service is restarted.

只有一個 SetupEntryPoint,所以如果應用程式的 setup 需要多個指令碼,則必須將 setup 指令碼組合在單一批次檔中。There is only one SetupEntryPoint, so setup scripts need to be grouped in a single batch file if the application's setup requires multiple scripts. SetupEntryPoint 可以執行任何類型的檔案:執行檔、批次檔、PowerShell Cmdlet。The SetupEntryPoint can execute any type of file: executable files, batch files, and PowerShell cmdlets. 如需詳細資訊,請參閱設定 SetupEntryPointFor more details, see Configure SetupEntryPoint.

在上述範例中,SetupEntryPoint 會執行位於 code 目錄的 scripts 子目錄中的批次檔 LaunchConfig.cmd (假設 WorkingFolder 元素已設為 CodeBase)。In the preceding example, the SetupEntryPoint runs a batch file called LaunchConfig.cmd that is located in the scripts subdirectory of the code directory (assuming the WorkingFolder element is set to CodeBase).

更新 EntryPointUpdate EntryPoint

<EntryPoint>
  <ExeHost>
    <Program>node.exe</Program>
    <Arguments>bin/www</Arguments>
    <WorkingFolder>CodeBase</WorkingFolder>
  </ExeHost>
</EntryPoint>

服務資訊清單檔中的 EntryPoint 元素用來指定如何啟動服務。The EntryPoint element in the service manifest file is used to specify how to launch the service.

ExeHost 元素指定應用來啟動服務的可執行檔 (和引數)。The ExeHost element specifies the executable (and arguments) that should be used to launch the service. 您可以選擇性地將 IsExternalExecutable="true" 屬性新增至 ExeHost,表示此程式為程式碼套件之外的外部可執行檔。You can optionally add the IsExternalExecutable="true" attribute to ExeHost to indicate that the program is an external executable outside of the code package. 例如: <ExeHost IsExternalExecutable="true">For example, <ExeHost IsExternalExecutable="true">.

  • Program 指定應啟動服務的執行檔名稱。Program specifies the name of the executable that should start the service.
  • Arguments 指定應傳遞至可執行檔的引數。Arguments specifies the arguments that should be passed to the executable. 這可以是具有引數的參數清單。It can be a list of parameters with arguments.
  • WorkingFolder 指定即將啟動之程序的工作目錄。WorkingFolder specifies the working directory for the process that is going to be started. 您可以指定三個值:You can specify three values:
    • CodeBase 指定工作目錄即將設為應用程式套件中的 code 目錄 (先前檔案結構中的 Code 目錄)。CodeBase specifies that the working directory is going to be set to the code directory in the application package (Code directory in the preceding file structure).
    • CodePackage 指定工作目錄即將設為應用程式套件中的根目錄 (先前檔案結構中的 GuestService1Pkg)。CodePackage specifies that the working directory is going to be set to the root of the application package (GuestService1Pkg in the preceding file structure).
      • Work 指定檔案放在名為 work 的子目錄中。Work specifies that the files are placed in a subdirectory called work.

WorkingFolder 適合用來設定正確的工作目錄,以便應用程式或初始化指令碼可使用相對路徑。The WorkingFolder is useful to set the correct working directory so that relative paths can be used by either the application or initialization scripts.

更新端點,並向命名服務註冊以進行通訊Update Endpoints and register with Naming Service for communication

<Endpoints>
   <Endpoint Name="NodeAppTypeEndpoint" Protocol="http" Port="3000" Type="Input" />
</Endpoints>

在前述範例中,Endpoint 元素指定應用程式可以接聽的端點。In the preceding example, the Endpoint element specifies the endpoints that the application can listen on. 在此範例中,Node.js 應用程式會接聽 http 連接埠 3000。In this example, the Node.js application listens on http on port 3000.

此外,您可以要求 Service Fabric 將此端點發佈至命名服務,讓其他服務可以探索這項服務的端點位址。Furthermore you can ask Service Fabric to publish this endpoint to the Naming Service so other services can discover the endpoint address to this service. 這可讓您在服務 (來賓可執行檔) 之間通訊。This enables you to be able to communicate between services that are guest executables. 發佈的端點位址格式為 UriScheme://IPAddressOrFQDN:Port/PathSuffixThe published endpoint address is of the form UriScheme://IPAddressOrFQDN:Port/PathSuffix. UriSchemePathSuffix 是選擇性的屬性。UriScheme and PathSuffix are optional attributes. IPAddressOrFQDN 是此執行檔所在節點的 IP 位址或完整網域名稱,系統會自動為您計算。IPAddressOrFQDN is the IP address or fully qualified domain name of the node this executable gets placed on, and it is calculated for you.

在下列範例中,部署服務後,您在 Service Fabric Explorer 中會看到服務執行個體已發佈的端點,類似於 http://10.1.4.92:3000/myapp/In the following example, once the service is deployed, in Service Fabric Explorer you see an endpoint similar to http://10.1.4.92:3000/myapp/ published for the service instance. 或者,如果這是本機電腦,則您會看到 http://localhost:3000/myapp/Or if this is a local machine, you see http://localhost:3000/myapp/.

<Endpoints>
   <Endpoint Name="NodeAppTypeEndpoint" Protocol="http" Port="3000"  UriScheme="http" PathSuffix="myapp/" Type="Input" />
</Endpoints>

您可以使用這些位址搭配反向 Proxy,就能在服務之間進行通訊。You can use these addresses with reverse proxy to communicate between services.

編輯應用程式資訊清單檔Edit the application manifest file

設定 Servicemanifest.xml 檔案之後,您需要對 ApplicationManifest.xml 檔進行一些變更,以確保使用正確的服務類型和名稱。Once you have configured the Servicemanifest.xml file, you need to make some changes to the ApplicationManifest.xml file to ensure that the correct service type and name are used.

<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="NodeAppType" ApplicationTypeVersion="1.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
   <ServiceManifestImport>
      <ServiceManifestRef ServiceManifestName="NodeApp" ServiceManifestVersion="1.0.0.0" />
   </ServiceManifestImport>
</ApplicationManifest>

ServiceManifestImportServiceManifestImport

ServiceManifestImport 元素中,您可以指定要包含在應用程式中的一個或多項服務。In the ServiceManifestImport element, you can specify one or more services that you want to include in the app. ServiceManifestName 指定 ServiceManifest.xml 檔案所在的目錄名稱,用來參考服務。Services are referenced with ServiceManifestName, which specifies the name of the directory where the ServiceManifest.xml file is located.

<ServiceManifestImport>
  <ServiceManifestRef ServiceManifestName="NodeApp" ServiceManifestVersion="1.0.0.0" />
</ServiceManifestImport>

設定記錄Set up logging

對於來賓可執行檔,最好能夠查看主控台記錄,以查明應用程式和設定指令碼是否顯示任何錯誤。For guest executables, it is useful to be able to see console logs to find out if the application and configuration scripts show any errors. ServiceManifest.xml 檔案中,可使用 ConsoleRedirection 元素設定主控台重新導向。Console redirection can be configured in the ServiceManifest.xml file using the ConsoleRedirection element.

警告

切勿在實際部署的應用程式中使用主控台重新導向原則,因為這可能會影響應用程式容錯移轉。Never use the console redirection policy in an application that is deployed in production because this can affect the application failover. 僅** 將此原則用於本機開發及偵錯。Only use this for local development and debugging purposes.

<EntryPoint>
  <ExeHost>
    <Program>node.exe</Program>
    <Arguments>bin/www</Arguments>
    <WorkingFolder>CodeBase</WorkingFolder>
    <ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048"/>
  </ExeHost>
</EntryPoint>

ConsoleRedirection 可用來將主控台輸出 (stdout 和 stderr) 重新導向到工作目錄。ConsoleRedirection can be used to redirect console output (both stdout and stderr) to a working directory. 這提供了在 Service Fabric 叢集中設定或執行應用程式期間確認沒有發生任何錯誤的功能。This provides the ability to verify that there are no errors during the setup or execution of the application in the Service Fabric cluster.

FileRetentionCount 決定工作目錄中儲存多少個檔案。FileRetentionCount determines how many files are saved in the working directory. 例如,值為 5 表示工作目錄中會儲存先前 5 次執行的記錄檔。A value of 5, for example, means that the log files for the previous five executions are stored in the working directory.

FileMaxSizeInKb 指定記錄檔的大小上限。FileMaxSizeInKb specifies the maximum size of the log files.

記錄檔會儲存在服務的其中一個工作目錄中。Log files are saved in one of the service's working directories. 若要判斷檔案的位置,使用 Service Fabric Explorer 來判斷服務執行所在的節點以及目前使用的工作目錄。To determine where the files are located, use Service Fabric Explorer to determine which node the service is running on, and which working directory is being used. 本文稍後會說明此程序。This process is covered later in this article.

部署Deployment

最後一個步驟是部署應用程式The last step is to deploy your application. 下列 PowerShell 指令碼示範如何將應用程式部署至本機開發叢集,並啟動新的 Service Fabric 服務。The following PowerShell script shows how to deploy your application to the local development cluster, and start a new Service Fabric service.


Connect-ServiceFabricCluster localhost:19000

Write-Host 'Copying application package...'
Copy-ServiceFabricApplicationPackage -ApplicationPackagePath 'C:\Dev\MultipleApplications' -ImageStoreConnectionString 'file:C:\SfDevCluster\Data\ImageStoreShare' -ApplicationPackagePathInImageStore 'nodeapp'

Write-Host 'Registering application type...'
Register-ServiceFabricApplicationType -ApplicationPathInImageStore 'nodeapp'

New-ServiceFabricApplication -ApplicationName 'fabric:/nodeapp' -ApplicationTypeName 'NodeAppType' -ApplicationTypeVersion 1.0

New-ServiceFabricService -ApplicationName 'fabric:/nodeapp' -ServiceName 'fabric:/nodeapp/nodeappservice' -ServiceTypeName 'NodeApp' -Stateless -PartitionSchemeSingleton -InstanceCount 1

提示

如果封裝很大或有許多檔案,請在將它複製到映像存放區之前壓縮封裝Compress the package before copying to the image store if the package is large or has many files. 您可以在這裡進一步了解。Read more here.

Service Fabric 服務可以各種「組態」部署。A Service Fabric service can be deployed in various "configurations." 例如,它可部署為單一或多個執行個體,也可以 Service Fabric 叢集的每個節點上有一個服務執行個體的方式部署。For example, it can be deployed as single or multiple instances, or it can be deployed in such a way that there is one instance of the service on each node of the Service Fabric cluster.

New-ServiceFabricService Cmdlet 的 InstanceCount 參數用來指定應在 Service Fabric 叢集中啟動多少個服務執行個體。The InstanceCount parameter of the New-ServiceFabricService cmdlet is used to specify how many instances of the service should be launched in the Service Fabric cluster. 您可以根據要部署的應用程式類型來設定 InstanceCount 值。You can set the InstanceCount value, depending on the type of application that you are deploying. 兩個最常見的案例包括:The two most common scenarios are:

  • InstanceCount = "1".InstanceCount = "1". 在此案例中,叢集中只部署一個服務執行個體。In this case, only one instance of the service is deployed in the cluster. Service Fabric 的排程器會決定即將部署服務的節點。Service Fabric's scheduler determines which node the service is going to be deployed on.
  • InstanceCount ="-1".InstanceCount ="-1". 在此案例中,Service Fabric 叢集中的每個節點上都部署一個服務執行個體。In this case, one instance of the service is deployed on every node in the Service Fabric cluster. 結果,叢集中的每個節點都有一個 (且僅只一個) 服務執行個體。The result is having one (and only one) instance of the service for each node in the cluster.

這是前端應用程式 (例如 REST 端點) 很有用的組態,因為用戶端應用程式只需要「連線」到叢集中的任何節點,即可使用端點。This is a useful configuration for front-end applications (for example, a REST endpoint), because client applications need to "connect" to any of the nodes in the cluster to use the endpoint. 當 Service Fabric 叢集的所有節點都連線到負載平衡器時,也可使用此組態。This configuration can also be used when, for example, all nodes of the Service Fabric cluster are connected to a load balancer. 如此便可將用戶端流量分散於在叢集中所有節點上執行的服務。Client traffic can then be distributed across the service that is running on all nodes in the cluster.

來查執行中的應用程式Check your running application

在 Service Fabric Explorer 中,找出執行服務的節點。In Service Fabric Explorer, identify the node where the service is running. 在此範例中,它是在 Node1 上執行:In this example, it runs on Node1:

服務執行所在的節點

如果您巡覽至節點並瀏覽至應用程式,您會看到基本節點資訊,包括它在磁碟上的位置。If you navigate to the node and browse to the application, you see the essential node information, including its location on disk.

在磁碟上的位置

如果您使用「伺服器總管」來瀏覽至目錄,您可以找到工作目錄和服務的記錄檔資料夾,如以下螢幕擷取畫面所示:If you browse to the directory by using Server Explorer, you can find the working directory and the service's log folder, as shown in the following screenshot:

記錄檔的位置

後續步驟Next steps

在本文中,您已經學會如何封裝來賓可執行檔並部署至 Service Fabric。In this article, you have learned how to package a guest executable and deploy it to Service Fabric. 請參閱下列文章以了解相關資訊和工作。See the following articles for related information and tasks.