将应用程序部署到 Service Fabric 群集Deploy an application to a Service Fabric cluster

此示例脚本将应用程序包复制到群集映像存储,并在群集中注册了应用程序类型,同时还删除了不必要的应用程序包,并根据应用程序类型创建了应用程序实例。This sample script copies an application package to a cluster image store, registers the application type in the cluster, removes the unnecessary application package, and creates an application instance from the application type. 如果目标应用程序类型的应用程序清单中定义了任何默认服务,则此时还会创建那些服务。If any default services were defined in the application manifest of the target application type, then those services are created at this time. 根据需要自定义参数。Customize the parameters as needed.

必要时,使用 Service Fabric SDK 安装 Service Fabric PowerShell 模块。If needed, install the Service Fabric PowerShell module with the Service Fabric SDK.

示例脚本Sample script

# Variables
$endpoint = 'mysftestcluster.chinaeast.cloudapp.chinacloudapi.cn:19000'
$thumbprint = '2779F0BB9A969FB88E04915FFE7955D0389DA7AF'
$packagepath="C:\Users\sfuser\Documents\Visual Studio 2017\Projects\MyApplication\MyApplication\pkg\Release"

# Connect to the cluster using a client certificate.
Connect-ServiceFabricCluster -ConnectionEndpoint $endpoint `
          -KeepAliveIntervalInSec 10 `
          -X509Credential -ServerCertThumbprint $thumbprint `
          -FindType FindByThumbprint -FindValue $thumbprint `
          -StoreLocation CurrentUser -StoreName My

# Copy the application package to the cluster image store.
Copy-ServiceFabricApplicationPackage $packagepath -ImageStoreConnectionString fabric:ImageStore -ApplicationPackagePathInImageStore MyApplication

# Register the application type.
Register-ServiceFabricApplicationType -ApplicationPathInImageStore MyApplication

# Remove the application package to free system resources.
Remove-ServiceFabricApplicationPackage -ImageStoreConnectionString fabric:ImageStore -ApplicationPackagePathInImageStore MyApplication

# Create the application instance.
New-ServiceFabricApplication -ApplicationName fabric:/MyApplication -ApplicationTypeName MyApplicationType -ApplicationTypeVersion 1.0.0

清理部署Clean up deployment

运行脚本示例后,可以使用删除应用程序中的脚本删除应用程序实例,取消注册应用程序类型,并从映像存储中删除应用程序包。After the script sample has been run, the script in Remove an application can be used to remove the application instance, unregister the application type, and delete the application package from the image store.

脚本说明Script explanation

此脚本使用以下命令。This script uses the following commands. 表中的每条命令均链接到特定于命令的文档。Each command in the table links to command specific documentation.

CommandCommand 说明Notes
Connect-ServiceFabricClusterConnect-ServiceFabricCluster 与 Service Fabric 群集建立连接。Creates a connection to a Service Fabric cluster.
Copy-ServiceFabricApplicationPackageCopy-ServiceFabricApplicationPackage 将应用程序包复制到群集映像存储。Copies an application package to the cluster image store.
Register-ServiceFabricApplicationTypeRegister-ServiceFabricApplicationType 在群集上注册应用程序类型和版本。Registers an application type and version on the cluster.
New-ServiceFabricApplicationNew-ServiceFabricApplication 从注册的应用程序类型创建应用程序。Creates an application from a registered application type.
Remove-ServiceFabricApplicationPackageRemove-ServiceFabricApplicationPackage 从映像存储区中删除 Service Fabric 应用程序包。Removes a Service Fabric application package from the image store.

后续步骤Next steps

有关 Service Fabric PowerShell 模块的详细信息,请参阅 Azure PowerShell 文档For more information on the Service Fabric PowerShell module, see Azure PowerShell documentation.

可以在 Azure PowerShell 示例中找到 Azure Service Fabric 的其他 Powershell 示例。Additional Powershell samples for Azure Service Fabric can be found in the Azure PowerShell samples.