【Azure Fabric Service】演示使用PowerShell命令部署SF应用程序(.NET)

简介: 本文详细介绍了在中国区微软云Azure上使用Service Fabrics服务时,通过PowerShell命令发布.NET应用的全过程。由于Visual Studio 2022无法直接发布应用,需借助PowerShell脚本完成部署。文章分三步讲解:首先在Visual Studio 2022中打包应用部署包,其次连接SF集群并上传部署包,最后注册应用类型、创建实例并启动服务。过程中涉及关键参数如服务器证书指纹和服务端证书指纹的获取,并附带图文说明,便于操作。参考官方文档,帮助用户成功部署并运行服务。

问题描述

在中国区微软云Azure上使用Service Fabrics服务,本地通过Visual Studio 2022的发布.NET应用,发现无法发布!

在搜寻官方文档之后,可以通过PowerShell命令来进行发布。本文参考的文档如下:

1:将应用程序部署到 Service Fabric 群集 (https://docs.azure.cn/zh-cn/service-fabric/scripts/service-fabric-powershell-deploy-application

2:使用 PowerShell 部署和删除应用程序(https://docs.azure.cn/zh-cn/service-fabric/service-fabric-deploy-remove-applications

需要使用到的PowerShell脚本如下:

# Login China Azure
Connect-AzAccount -Environment AzureChinaCloud

# set your  default subscription
Select-AzSubscription -Subscription 'xx-x-x-x-xxx'


# Variables
$endpoint = 'mysftestcluster.chinaeast.cloudapp.chinacloudapi.cn:19000'
#获取SF托管集群的服务证书指纹
$serverThumbprint = (Get-AzResource -ResourceId /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.ServiceFabric/managedclusters/mysfcluster)
.Properties.clusterCertificateThumbprints
$clientThumbprint = '2779F0BB9A969FB88E04915FFE7955D0389DA7AF'

$packagepath="C:\....\Projects\MyApplication\MyApplication\pkg\Release"


##连接到SF托管集群
Connect-ServiceFabricCluster -ConnectionEndpoint $endpoint -KeepAliveIntervalInSec 10 `
      -X509Credential `
      -ServerCertThumbprint $serverThumbprint  `
      -FindType FindByThumbprint `
      -FindValue $clientThumbprint `
      -StoreLocation CurrentUser `
      -StoreName My 


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

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

 
# list application type in SF Cluster
Get-ServiceFabricApplicationType

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


本文通过图文方式来一步一步展示 部署过程!

 

问题解答

按照以上脚本,登录到China Azure后,最重要的操作是如何使用 Connect-ServiceFabricCluster 连接到SF托管集群。

PS: SF托管集群和自建集群在这里的区别主要是服务器证书指纹需要通过命令获取。而自建集群的服务证书指纹(serverThumbprint)和客户端证书指纹(clientThumbprint)是相同的。

当然,也可以直接在门户中同时获取这两个证书指纹值(Azure 门户 --> SF Overview页面 --> JSON View -> 查看 Properties 值)

 

准备好参数后,开始一步一步部署SF应用!

第一步:在Visual Studio 2022中打包应用部署包

  • 右键,选择Package, 在输出结果中复制应用包路径

第二步:连接到SF集群,上传部署包,并在Service Fabric Explorer中查看

PS: SF Explorer地址:https://<your sf cluster name>.<chinanorth3>.cloudapp.chinacloudapi.cn:19080/Explorer,在打开页面时需要验证本地证书,所以需要在本地环境中安装客户端证书(创建集群时候所设置的证书)。

第三步:注册并创建应用实例并启动服务

  • Register-ServiceFabricApplicationType : 在群集上注册应用程序类型和版本。
  • Get-ServiceFabricApplicationType : 获取集群上已经注册的应用程序类型 和版本。
  • New-ServiceFabricApplication   : 从注册的应用程序类型创建应用程序。

特别注意:还差最后一步让服务运行起来。

进入SF explorer页面中,选择第三步创建的Application,在Service Types部分中,点击Create后,才能让服务正真的运行起来。

 

当应用中的服务状态变为OK后,即是成功!

 

PS: 此种方式,确实比Visual Studio 2022的直接部署步骤复杂很多。

 

 

参考资料

将应用程序部署到 Service Fabric 群集 (https://docs.azure.cn/zh-cn/service-fabric/scripts/service-fabric-powershell-deploy-application

使用 PowerShell 部署和删除应用程序(https://docs.azure.cn/zh-cn/service-fabric/service-fabric-deploy-remove-applications



当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

相关文章
|
人工智能
D1net阅闻 | 奥特曼:把期望降低100倍,OpenAI下月不会部署AGI
D1net阅闻 | 奥特曼:把期望降低100倍,OpenAI下月不会部署AGI
|
人工智能 自动驾驶 机器人
D1net阅闻|国务院国资委部署深化中央企业“AI+”专项行动
D1net阅闻|国务院国资委部署深化中央企业“AI+”专项行动
|
开发框架 监控 .NET
【Azure App Service】部署在App Service上的.NET应用内存消耗不能超过2GB的情况分析
x64 dotnet runtime is not installed on the app service by default. Since we had the app service running in x64, it was proxying the request to a 32 bit dotnet process which was throwing an OutOfMemoryException with requests >100MB. It worked on the IaaS servers because we had the x64 runtime install
449 5
|
监控 网络安全 调度
Quartz.Net整合NetCore3.1,部署到IIS服务器上后台定时Job不被调度的解决方案
解决Quartz.NET在.NET Core 3.1应用中部署到IIS服务器上不被调度的问题,通常需要综合考虑应用配置、IIS设置、日志分析等多个方面。采用上述策略,结合细致的测试和监控,可以有效地提高定时任务的稳定性和可靠性。在实施任何更改后,务必进行充分的测试,以验证问题是否得到解决,并监控生产环境的表现,确保长期稳定性。
1846 1
|
开发框架 前端开发 .NET
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
968 0
|
监控 前端开发 API
一款基于 .NET MVC 框架开发、功能全面的MES系统
一款基于 .NET MVC 框架开发、功能全面的MES系统
825 5
|
开发框架 前端开发 JavaScript
ASP.NET MVC 教程
ASP.NET 是一个使用 HTML、CSS、JavaScript 和服务器脚本创建网页和网站的开发框架。
499 7
|
存储 开发框架 前端开发
ASP.NET MVC 迅速集成 SignalR
ASP.NET MVC 迅速集成 SignalR
410 0
|
开发框架 前端开发 .NET
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
437 0
|
开发框架 前端开发 安全
ASP.NET MVC 如何使用 Form Authentication?
ASP.NET MVC 如何使用 Form Authentication?
569 0