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

简介: 【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>

psping下载地址(https://docs.microsoft.com/en-us/sysinternals/downloads/psping) 及psping后验证端口是否已通。如出现Timeout period expired,则需要到负载均衡资源中添加Load balancing rules

 

引用使用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

相关文章
|
20天前
|
数据安全/隐私保护
【Azure Service Fabric】关于Service Fabric的相关问题
【Azure Service Fabric】关于Service Fabric的相关问题
|
20天前
|
安全 数据可视化 数据安全/隐私保护
【Azure 微服务】新创建的Service Fabric集群,如何从本地机器上连接到Service Fabric Explorer(Service Fabric状态/错误查看工具)呢?
【Azure 微服务】新创建的Service Fabric集群,如何从本地机器上连接到Service Fabric Explorer(Service Fabric状态/错误查看工具)呢?
【Azure 微服务】新创建的Service Fabric集群,如何从本地机器上连接到Service Fabric Explorer(Service Fabric状态/错误查看工具)呢?
|
20天前
【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.
|
20天前
|
安全 网络安全
【Service Fabric】Service Fabric删不掉的问题
【Service Fabric】Service Fabric删不掉的问题
|
16天前
|
Kubernetes Cloud Native Docker
云原生之旅:从容器到微服务的架构演变
【8月更文挑战第29天】在数字化时代的浪潮下,云原生技术以其灵活性、可扩展性和弹性管理成为企业数字化转型的关键。本文将通过浅显易懂的语言和生动的比喻,带领读者了解云原生的基本概念,探索容器化技术的奥秘,并深入微服务架构的世界。我们将一起见证代码如何转化为现实中的服务,实现快速迭代和高效部署。无论你是初学者还是有经验的开发者,这篇文章都会为你打开一扇通往云原生世界的大门。
|
17天前
|
负载均衡 应用服务中间件 持续交付
微服务架构下的Web服务器部署
【8月更文第28天】随着互联网应用的不断发展,传统的单体应用架构逐渐显露出其局限性,特别是在可扩展性和维护性方面。为了解决这些问题,微服务架构应运而生。微服务架构通过将应用程序分解成一系列小型、独立的服务来提高系统的灵活性和可维护性。本文将探讨如何在微服务架构中有效部署和管理Web服务器实例,并提供一些实际的代码示例。
51 0
|
1天前
|
运维 Cloud Native Devops
云原生架构的崛起与实践云原生架构是一种通过容器化、微服务和DevOps等技术手段,帮助应用系统实现敏捷部署、弹性扩展和高效运维的技术理念。本文将探讨云原生的概念、核心技术以及其在企业中的应用实践,揭示云原生如何成为现代软件开发和运营的主流方式。##
云原生架构是现代IT领域的一场革命,它依托于容器化、微服务和DevOps等核心技术,旨在解决传统架构在应对复杂业务需求时的不足。通过采用云原生方法,企业可以实现敏捷部署、弹性扩展和高效运维,从而大幅提升开发效率和系统可靠性。本文详细阐述了云原生的核心概念、主要技术和实际应用案例,并探讨了企业在实施云原生过程中的挑战与解决方案。无论是正在转型的传统企业,还是寻求创新的互联网企业,云原生都提供了一条实现高效能、高灵活性和高可靠性的技术路径。 ##
9 3
|
9天前
|
存储 Java Maven
从零到微服务专家:用Micronaut框架轻松构建未来架构
【9月更文挑战第5天】在现代软件开发中,微服务架构因提升应用的可伸缩性和灵活性而广受欢迎。Micronaut 是一个轻量级的 Java 框架,适合构建微服务。本文介绍如何从零开始使用 Micronaut 搭建微服务架构,包括设置开发环境、创建 Maven 项目并添加 Micronaut 依赖,编写主类启动应用,以及添加控制器处理 HTTP 请求。通过示例代码展示如何实现简单的 “Hello, World!” 功能,并介绍如何通过添加更多依赖来扩展应用功能,如数据访问、验证和安全性等。Micronaut 的强大和灵活性使你能够快速构建复杂的微服务系统。
32 5
|
22天前
|
Kubernetes 安全 微服务
使用 Istio 缓解电信 5G IoT 微服务 Pod 架构的安全挑战
在5G电信领域,Kubernetes集群中部署微服务至关重要,但也带来了重大的安全挑战。Istio作为一个强大的开源服务网格,能有效地管理这些微服务间的通信,通过其控制平面自动将Sidecar代理注入到各微服务Pod中,确保了安全且高效的通信。Istio的架构由数据平面和控制平面组成,其中Sidecar代理作为Envoy代理运行在每个Pod中,拦截并管理网络流量。此外,Istio支持多种Kubernetes发行版和服务,如EKS等,不仅增强了安全性,还提高了应用性能和可观测性。
52 0
使用 Istio 缓解电信 5G IoT 微服务 Pod 架构的安全挑战
|
24天前
|
Java Docker 微服务
微服务架构的概念、特点以及如何在Java Web开发中实现微服务。
微服务架构的概念、特点以及如何在Java Web开发中实现微服务。
50 1