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

本文涉及的产品
可观测可视化 Grafana 版,10个用户账号 1个月
可观测监控 Prometheus 版,每月50GB免费额度
应用实时监控服务-应用监控,每月50GB免费额度
简介: 本文详细介绍了在中国区微软云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



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

目录
打赏
0
72
72
0
203
分享
相关文章
【Azure Fabric Service】分享使用Visual Studio 2022发布中国区Service Fabric服务应用的办法
本文介绍了在Visual Studio 2022中无法直接创建Service Fabric Cluster服务时的替代方案。通过使用PowerShell命令或修改Cloud.xml文件,可将应用部署到已创建的SF Cluster。具体步骤包括:1) 在Azure门户创建Service Fabric服务并安装客户端证书;2) 获取服务端和客户端证书指纹;3) 修改Cloud.xml中的ClusterConnectionParameters后发布应用。最后附有参考资料以供进一步学习。
【Azure Storage Account】利用App Service作为反向代理, 并使用.NET Storage Account SDK实现上传/下载操作
本文介绍了如何在Azure上使用App Service作为反向代理,以自定义域名访问Storage Account。主要内容包括: 1. **设置反向代理**:通过配置`applicationhost.xdt`和`web.config`文件,启用IIS代理功能并设置重写规则。 2. **验证访问**:测试原生URL和自定义域名的访问效果,确保两者均可正常访问Storage Account。 3. **.NET SDK连接**:使用共享访问签名(SAS URL)初始化BlobServiceClient对象,实现通过自定义域名访问存储服务。
【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
|
7月前
【Azure Fabric Service】Service Fabric部署失败问题 Provisioning of VM extension ConfigureVM has timed out.
【Azure Fabric Service】Service Fabric部署失败问题 Provisioning of VM extension ConfigureVM has timed out.
|
6月前
|
Powershell 重新排列去重 Windows环境变量
【9月更文挑战第13天】本文介绍如何使用PowerShell对Windows环境变量进行重新排列和去重。首先通过`$env:`访问环境变量,接着使用`-split`命令分割路径,再利用`Select-Object -Unique`去除重复项。之后可根据需要对路径进行排序,最后将处理后的路径组合并更新环境变量。注意修改环境变量前应备份重要数据并了解潜在影响。
210 10
PowerShell 脚本编写 :自动化Windows 开发工作流程
PowerShell 脚本编写 :自动化Windows 开发工作流程
242 0
|
10月前
|
windows可以安装Ubuntu,ubuntu上也可以安装Powershell
powerhsell除了可以在windows上使用外,还可以在Ubuntu上部署开发环境。下面介绍Ubuntu上安装powershell的方法。
278 0
windows中cmd和PowerShell批处理命令
之前在 Git 批量删除本地分支,有用到 Linux 或 MacOS 下的批处理命令,这个命令中的 grep、xargs 本身是 Shell script,在 windows 中的 cmd 和 PowerShell 中是不能用的
使用PowerShell获取Windows当前锁屏壁纸
使用PowerShell获取Windows当前锁屏壁纸 如果原始图片丢了,用这段代码就可以提取当前锁屏壁纸了!
224 0

云原生

+关注