【Azure微服务 Service Fabric 】使用az命令创建Service Fabric集群

问题描述

在使用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 运行该脚本。谢谢大家!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

http://cn.global-trade-center.com/Products/k1004494561/
http://cn.global-trade-center.com/Products/k1004494580/
http://cn.global-trade-center.com/Products/k1004494587/
http://cn.global-trade-center.com/Products/k1004494590/
http://cn.global-trade-center.com/Products/k1004494595/
http://cn.global-trade-center.com/Products/k1004494604/
http://cn.global-trade-center.com/Products/k1004494618/
http://cn.global-trade-center.com/Products/k1004494633/
http://cn.global-trade-center.com/Products/k1004494643/
http://cn.global-trade-center.com/Products/k1004494645/
http://cn.global-trade-center.com/Products/k1004494686/
http://cn.global-trade-center.com/Products/k1004494590/
http://cn.global-trade-center.com/Products/k1004494700/
http://cn.global-trade-center.com/Products/k1004494708/
http://cn.global-trade-center.com/Products/k1004494713/
http://cn.global-trade-center.com/Products/k1004494714/
http://cn.global-trade-center.com/Products/k1004494727/
http://cn.global-trade-center.com/Products/k1004494733/
http://cn.global-trade-center.com/Products/k1004494735/
http://cn.global-trade-center.com/Products/k1004494739/
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E4%BB%A3%E7%90%86Q%E3%80%90%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%91_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%B9%B3%E5%8F%B0%E4%BB%A3%E7%90%86Q%E3%80%90%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%91_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%B9%B3%E5%8F%B0%E4%BB%A3%E7%90%86%E3%80%8A%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%A8%B1%E4%B9%90%E5%B9%B3%E5%8F%B0%E6%80%BB%E4%BB%A3%E7%90%86%E3%80%8A%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E6%80%BB%E4%BB%A3%E3%80%8A%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%B9%B3%E5%8F%B0%E6%80%BB%E4%BB%A3%E3%80%8A%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%A8%B1%E4%B9%90%E5%B9%B3%E5%8F%B0%E6%80%BB%E4%BB%A3%E3%80%8A%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%A8%B1%E4%B9%90%E6%80%BB%E4%BB%A3%E3%80%8A%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E6%80%BB%E4%BB%A3%E7%90%86%E3%80%8A%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%A8%B1%E4%B9%90%E6%80%BB%E4%BB%A3%E7%90%86%E3%80%8A%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%A8%B1%E4%B9%90%E5%B9%B3%E5%8F%B0%E6%80%BB%E4%BB%A3%E7%90%86%E3%80%8A%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E6%B3%A8%E5%86%8C%E3%80%8AQ%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%B9%B3%E5%8F%B0%E6%B3%A8%E5%86%8C%E3%80%8AQ%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%A8%B1%E4%B9%90%E6%B3%A8%E5%86%8C%E3%80%8AQ%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%A8%B1%E4%B9%90%E5%B9%B3%E5%8F%B0%E6%B3%A8%E5%86%8C%E3%80%8AQ%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E6%B3%A8%E5%86%8C%E5%9C%B0%E5%9D%80%E3%80%8AQ%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%B9%B3%E5%8F%B0%E6%B3%A8%E5%86%8C%E5%9C%B0%E5%9D%80%E3%80%8AQ%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%A8%B1%E4%B9%90%E6%B3%A8%E5%86%8C%E5%9C%B0%E5%9D%80%E3%80%8AQ%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
http://search.dangdang.com/author/%E6%9D%8F%E5%BD%A9%E5%A8%B1%E4%B9%90%E5%B9%B3%E5%8F%B0%E6%B3%A8%E5%86%8C%E5%9C%B0%E5%9D%80%E3%80%8AQ%E2%92%88%E2%92%8C%E2%92%8AO%E2%92%8D%E2%92%8D%E2%92%8E%E3%80%8B_1
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值