问题描述

在使用Service Fabric的快速入门文档: 将 Windows 容器部署到 Service Fabric。 其中在创建Service Fabric时候,示例代码中使用的是PowerShell脚本调用AZ模块来执行创建命令。但是在本地执行时,遇见了无法运行'Connect-AzAccount'等命令。

Connect-AzAccount : The term 'Connect-AzAccount' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ Connect-AzAccount -Environment AzureChinaCloud
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-AzAccount:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

所以决定使用az cli命令来代替,但官方文档中只给出了PowerShell的命令,所以需要使用对应的az命令来替换。主要替换的命令有三个。

1) Connect-AzAccount -Environment AzureChinaCloud 替换为 az cloud set --name AzureChinaCloud

2) Select-AzSubscription -SubscriptionId $subscriptionId 替换为 az account set --subscription $subscriptionId

3) New-AzServiceFabricCluster 替换为 az sf cluster create

# Create the Service Fabric cluster.
New-AzServiceFabricCluster -Name $clustername -ResourceGroupName $groupname -Location $clusterloc `
-ClusterSize $clustersize -VmUserName $adminuser -VmPassword $adminpwd -CertificateSubjectName $subname `
-CertificatePassword $certpwd -CertificateOutputFolder $certfolder `
-OS WindowsServer2016DatacenterwithContainers -VmSku $vmsku -KeyVaultName $vaultname

:在命令New-AzServiceFabricCluster中替换对应的参数即可。

如出现参数名不存在的情况,可以使用-h 帮助命令来获取正常的参数。如az sf cluster create -h

参数错误:cli.azure.cli.core.parser : az: error: unrecognized arguments

使用help命令查看正确参数

重要部分(使用az CLI命令替换后的全部命令)

#Provide the subscription Id
$subscriptionId = 'yourSubscriptionId' # Certificate variables.
$certpwd="Password#1234" | ConvertTo-SecureString -AsPlainText -Force
$certfolder="c:\mycertificates\" # Variables for VM admin.
$adminuser="vmadmin"
$adminpwd="Password#1234" | ConvertTo-SecureString -AsPlainText -Force # Variables for common values
$clusterloc="chinaeast"
$clustername = "mysfcluster"
$groupname="mysfclustergroup"
$vmsku = "Standard_D2_v2"
$vaultname = "mykeyvault"
$subname="$clustername.$clusterloc.cloudapp.chinacloudapi.cn" # Set the number of cluster nodes. Possible values: 1, 3-99
$clustersize=5 # Set the context to the subscription Id where the cluster will be created
az cloud set --name AzureChinaCloud
az login
az account set --subscription $subscriptionId # Create the Service Fabric cluster.
az sf cluster create --cluster-name $clustername --resource-group $groupname --location $clusterloc `
--cluster-size $clustersize --vm-user-name $adminuser --vm-password $adminpwd --certificate-subject-name $subname `
--certificate-password $certpwd --certificate-output-folder $certfolder `
--os WindowsServer2016DatacenterwithContainers --vm-sku $vmsku --vault-name $vaultname --debug

注:

  • 脚本创建一个由五个节点组成的 Service Fabric 群集(使用 X.509 证书保护的群集)。该命令将创建一个自签名证书,并将其上传到新的 Key Vault。 该证书也会复制到本地目录"c:\mycertificates\"中。
  • 在执行中如需要查看日志输出,可以添加 --debug。

成功结果

当Service Fabric创建完成后,可以通过Visual Studio 2019发布创建好的Container到集群中。发布成功后,通过Service Fabric Explorer查看效果:

当根据文档部署Container后,访问SF集群URL并加上80端口(端口由发布Container时指定),既可以查看到IIS的默认页面.

在ServiceManifest.xml文件中配置Endpoint端口,在访问时候需要非常注意的一点是:确保SF的Load Balance中已开启该端口。可以通过psping方式来验证。

  <Resources>
<Endpoints>
<!-- This endpoint is used by the communication listener to obtain the port on which to
listen. Please note that if your service is partitioned, this port is shared with
replicas of different partitions that are placed in your code. -->
<Endpoint Name="MyContainerServiceTypeEndpoint" Port="80" />
</Endpoints>

引用使用PowerShell AzModule命令创建SF集群的全部代码为:

创建群集

以下示例脚本创建一个由五个节点组成的 Service Fabric 群集(使用 X.509 证书保护的群集)。 该命令将创建一个自签名证书,并将其上传到新的 Key Vault。 该证书也会复制到本地目录。 可在创建 Service Fabric 群集中详细了解如何使用此脚本创建群集。

必要时,请使用 Azure PowerShell 指南中的说明安装 Azure PowerShell。

在运行以下脚本之前,请在 PowerShell 中运行 Connect-AzAccount -Environment AzureChinaCloud 来与 Azure 建立连接。

将以下脚本复制到剪贴板,并打开 Windows PowerShell ISE 。 将内容粘贴到空的 Untitled1.ps1 窗口。 然后,为脚本中的变量提供值:subscriptionIdcertpwdcertfolderadminuseradminpwd 等等。 运行该脚本之前,为 certfolder 指定的目录必须存在。

#Provide the subscription Id
$subscriptionId = 'yourSubscriptionId' # Certificate variables.
$certpwd="Password#1234" | ConvertTo-SecureString -AsPlainText -Force
$certfolder="c:\mycertificates\" # Variables for VM admin.
$adminuser="vmadmin"
$adminpwd="Password#1234" | ConvertTo-SecureString -AsPlainText -Force # Variables for common values
$clusterloc="chinaeast"
$clustername = "mysfcluster"
$groupname="mysfclustergroup"
$vmsku = "Standard_D2_v2"
$vaultname = "mykeyvault"
$subname="$clustername.$clusterloc.cloudapp.chinacloudapi.cn" # Set the number of cluster nodes. Possible values: 1, 3-99
$clustersize=5 # Set the context to the subscription Id where the cluster will be created
Select-AzSubscription -SubscriptionId $subscriptionId # Create the Service Fabric cluster.
New-AzServiceFabricCluster -Name $clustername -ResourceGroupName $groupname -Location $clusterloc `
-ClusterSize $clustersize -VmUserName $adminuser -VmPassword $adminpwd -CertificateSubjectName $subname `
-CertificatePassword $certpwd -CertificateOutputFolder $certfolder `
-OS WindowsServer2016DatacenterwithContainers -VmSku $vmsku -KeyVaultName $vaultname

为变量提供值后,按 F5 运行该脚本。

运行脚本并创建群集后,在输出中查找 ClusterEndpoint。 例如:

ClusterEndpoint : https://mysfcluster.chinaeast.cloudapp.chinacloudapi.cn/runtime/clusters/b76e757d-0b97-4037-a184-9046a7c818c0  

参考文档:

将 Windows 容器部署到 Service Fabrichttps://docs.azure.cn/zh-cn/service-fabric/service-fabric-quickstart-containers

az sf cluster: https://docs.microsoft.com/en-us/cli/azure/sf/cluster?view=azure-cli-latest#az_sf_cluster_create

【Azure微服务 Service Fabric 】使用az命令创建Service Fabric集群的更多相关文章

  1. 庐山真面目之十微服务架构 Net Core 基于 Docker 容器部署 Nginx 集群

    庐山真面目之十微服务架构 Net Core 基于 Docker 容器部署 Nginx 集群 一.简介      前面的两篇文章,我们已经介绍了Net Core项目基于Docker容器部署在Linux服 ...

  2. 微服务之:从零搭建ocelot网关和consul集群

    介绍 微服务中有关键的几项技术,其中网关和服务服务发现,服务注册相辅相成. 首先解释几个本次教程中需要的术语 网关 Gateway(API GW / API 网关),顾名思义,是企业 IT 在系统边界 ...

  3. 【微服务架构】SpringCloud之Eureka(注册中心集群篇)(三)

    上一篇讲解了spring注册中心(eureka),但是存在一个单点故障的问题,一个注册中心远远无法满足实际的生产环境,那么我们需要多个注册中心进行集群,达到真正的高可用.今天我们实战来搭建一个Eure ...

  4. 【Azure 微服务】基于已经存在的虚拟网络(VNET)及子网创建新的Service Fabric并且为所有节点配置自定义DNS服务

    问题描述 创建新的Service Fabric集群,可以通过门户,Powershell命令,或者是ARM模板.但是通过门户和PowerShell命令时,创建的SF集群都会自动新建一个虚拟网络而无法使用 ...

  5. 【Azure微服务 Service Fabric 】Service Fabric中应用开启外部访问端口及微服务之间通过反向代理端口访问问题

    问题描述 1) 当成功的在Service Fabric集群中部署了应用后,如何来访问呢?如果是一个Web服务,它的URL又是什么呢? 2) 当Service Fabric集群中,服务之间如需要相互访问 ...

  6. 【Azure微服务 Service Fabric 】因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)

    问题描述 创建Service Fabric时,证书在整个集群中是非常重要的部分,有着用户身份验证,节点之间通信,SF升级时的身份及授权认证等功能.如果证书过期则会导致节点受到影响集群无法正常工作. 当 ...

  7. 【Azure 微服务】Service Fabric, 使用ARM Template方式来更新SF集群的证书(Renew SF Certificate)

    问题描述 因证书过期导致Service Fabric集群挂掉(升级无法完成,节点不可用)一文中,描述了因为证书过期而导致了SF集群不可用,并且通过命令dd-AzServiceFabricCluster ...

  8. 【Azure 微服务】Service Fabric中微服务在升级时,遇见Warning - System.Collections.Generic.KeyNotFoundException 服务无法正常运行

    问题描述 使用.Net Framework 4.5.2为架构的Service Fabric微服务应用,在升级后发布到Azure Fabric中,服务无法运行.通过Service Fabric Expl ...

  9. 【Azure微服务 Service Fabric 】如何转移Service Fabric集群中的种子节点(Seed Node)

    注意:在对Service Fabric的节点做操作之前,请务必确认是否是种子节点(Seed Node)且当前节点的数量是否与SF的持久层要求的数量一致. 可靠性级别是 Service Fabric 群 ...

随机推荐

  1. 二进制K8S集群使用Bootstrap Token 方式增加Node

    TLS Bootstraping:在kubernetes集群中,Node上组件kebelet和kube-proxy都需要与kube-apiserver进行通信,为了增加传输安全性,采用https方式, ...

  2. 解Bug之路-记一次线上请求偶尔变慢的排查

    解Bug之路-记一次线上请求偶尔变慢的排查 前言 最近解决了个比较棘手的问题,由于排查过程挺有意思,于是就以此为素材写出了本篇文章. Bug现场 这是一个偶发的性能问题.在每天几百万比交易请求中,平均 ...

  3. tmpwatch命令清除旧文件

    我们知道系统里面常常会有一些忘记删除的长时间不用而且确实没有用处的文件,如果不去处理,这些无用的文件会越来越多,浪费许多系统资源.在不知道文件名的情况下,很难去检查某一目录下到底是哪些文件长时间没有被 ...

  4. 配置DVWA漏洞环境

    web萌新,因为在别人的环境上练习总有点不舒服,所以在本地搭建了网站:下面记录一下搭建的步骤 DVWA:是一个漏洞环境包,可以用phpstudy或者wamp解析:所以要想配置这个环境,就必须有这两个软 ...

  5. CS61A Homework: Church Numerals

    Church Numerals Nagging 南大的 SICP 实际上是 Berkeley CS61A 的 clone ,所以我有幸做到了这个 Homework02. 此外要感谢选课系统,让我一个工 ...

  6. day39 Pyhton 并发编程02

    一.内容回顾 并发和并行的区别 并发 宏观上是在同时运行的 微观上是一个一个顺序执行 同一时刻只有一个cpu在工作 并行 微观上就是同时执行的 同一时刻不止有一个cpu在工作 什么是进程 一个运行中的 ...

  7. day32 Pyhton 异常处理

    一.内容回顾 反射的另外两个内置函数 setattr delattr a.b=c 与 setattr(a,'b',c)相对 del a.b 与 delattr(a,'b') 两个内置函数 A,B(A) ...

  8. 会用Docker的人都别装了,这多简单呐

    学术又官方的说法 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器或Windows 机器上,也可以实现虚拟化,容器是 ...

  9. laravel重写

    laravel location / { try_files $uri $uri/ /index.php?$query_string; } ci location / { try_files $uri ...

  10. 远程Jenkins新增Mac电脑节点

    一,前言 上一篇博客Jenkins集成appium自动化测试(Windows篇)介绍了怎么使用远程Jenkins新建节点连接本地Windows电脑进行Appium自动化测试集成. 但是在做ios Ap ...