首页 > 解决方案 > 使用 PowerShell 将应用程序部署到服务结构

问题描述

我在 Azure 中启动并运行了服务结构。我也有两个项目的 Visual Studio 解决方案:Service Fabric 和 Web Service。我想将服务部署到 azure 中的服务结构。当我右键单击我的服务结构项目并单击“发布”时,服务会顺利部署到云结构。我想对 PowerShell 做同样的事情。

看来我需要运行这个脚本:

# 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 $packagename

# Register the application type.
Register-ServiceFabricApplicationType -ApplicationPathInImageStore $packagename

# Create the service instance.
$appName = <name that I see in fabric explorer under 'typeName' in azure>
New-ServiceFabricService -ApplicationName fabric:/$appName -ServiceName fabric:/$appName/MyApp -ServiceTypeName $serviceTypeName -Stateless -PartitionSchemeSingleton -InstanceCount -1

在运行脚本之前,我右键单击我的织物应用程序并选择“包”。

我的脚本的最后一个命令因“找不到应用程序”而失败

可以缺少什么?

标签: powershellazure-service-fabric

解决方案


构建并准备好包后,您可以尝试以下命令以使用 PowerShell 脚本部署 pkg。

如果您还没有尝试过以下选项,请尝试一下,看看它是否有效。

运行脚本需要几个先决条件:

  • 您已启动并运行集群。

  • 集群已部署所有必要的证书(例如 SSL 端点,如果有)

  • 您已准备好 ARM 模板和参数文件。

  • 您拥有部署新资源所需的权限,即 Contributor 角色(订阅或资源组级别)

  • 您已创建目标资源组

检查上述内容后,执行以下命令:

Copy-ServiceFabricApplicationPackage

注册-ServiceFabricApplicationType

新ServiceFabricApplication

如果这对您不起作用,请浏览以下站点以查看是否有帮助。

使用 PowerShell 部署应用程序

使用资源管理器模板和 Azure PowerShell 部署资源


推荐阅读