当前位置: 首页 > Microsoft Azure > 正文

Azure Administrator认证学习指南之管理与维护Azure虚拟机规模集-45-A

上一篇文章中简单介绍了Azure中的虚拟机规模集并演示可如何创建一个Azure VMSS,今天将从以下几个方面管理Azure VMSS服务。

修改规模集

前端业务和后端IT是相辅相成的,随着前端业务的变化,后端IT基础架构也会随之发生变更,需要对业务中的应用程序做相关调整。

    规模集有一个”规模集模型”,用于以整体方式捕获规模集的所需状态。需要使用过 Azure PowerShell、 Azure CLI 或者通过 REST API方式进行查看。以下以 Azure PowerShell为例

az vmss get-instance-view –resource-group myResourceGroup –name myScaleSet

输出之后

az vmss show –resource-group myResourceGroup –name myScaleSet

{

“location”: “westus”,

“overprovision”: true,

“plan”: null,

“singlePlacementGroup”: true,

“sku”: {

“additionalProperties”: {},

“capacity”: 1,

“name”: “Standard_D2_v2”,

“tier”: “Standard”

},

}

而另外一个概念”规模集实例视图”,用于以整体方式捕获规模集当前的”运行时”状态。** 若要查询规模集的实例视图,可使用以下命令:

az vmss get-instance-view –resource-group myResourceGroup –name myScaleSet

输出之后

$ az vmss get-instance-view –resource-group myResourceGroup –name myScaleSet

{

“statuses”: [

{

“additionalProperties”: {},

“code”: “ProvisioningState/succeeded”,

“displayStatus”: “Provisioning succeeded”,

“level”: “Info”,

“message”: null,

“time”: “{time}”

}

],

“virtualMachine”: {

“additionalProperties”: {},

“statusesSummary”: [

{

“additionalProperties”: {},

“code”: “ProvisioningState/succeeded”,

“count”: 1

}

]

}

}

若要查询规模集中特定 VM 实例的模型视图,可使用以下命令:

az vmss show –resource-group myResourceGroup –name myScaleSet –instance-id instanceId

输出之后

$ az vmss show –resource-group myResourceGroup –name myScaleSet

{

“location”: “westus”,

“name”: “{name}”,

“sku”: {

“name”: “Standard_D2_v2”,

“tier”: “Standard”

},

}

若要查询规模集中特定 VM 实例的实例视图,可使用以下命令:

az vmss get-instance-view –resource-group myResourceGroup –name myScaleSet –instance-id instanceId

输出之后

$ az vmss get-instance-view –resource-group myResourceGroup –name myScaleSet –instance-id instanceId

{

“additionalProperties”: {

“osName”: “ubuntu”,

“osVersion”: “16.04”

},

“disks”: [

{

“name”: “{name}”,

“statuses”: [

{

“additionalProperties”: {},

“code”: “ProvisioningState/succeeded”,

“displayStatus”: “Provisioning succeeded”,

“time”: “{time}”

}

]

}

],

“statuses”: [

{

“additionalProperties”: {},

“code”: “ProvisioningState/succeeded”,

“displayStatus”: “Provisioning succeeded”,

“time”: “{time}”

},

{

“additionalProperties”: {},

“code”: “PowerState/running”,

“displayStatus”: “VM running”

}

],

“vmAgent”: {

“statuses”: [

{

“additionalProperties”: {},

“code”: “ProvisioningState/succeeded”,

“displayStatus”: “Ready”,

“level”: “Info”,

“message”: “Guest Agent is running”,

“time”: “{time}”

}

],

“vmAgentVersion”: “{version}”

},

}

Azur虚拟机规模集中,有一项″升级策略”,该策略决定了如何使用最新的规模集模型对 VM 进行更新。升级策略的三种模式是:

  • 自动 – 在此模式下,规模集无法保证 VM 的关闭顺序。规模集可能同时关闭所有 VM。
  • 滚动 – 在此模式下,规模集以批次的方式推出更新,批次之间的暂停时间为可选。
  • 手动 – 在此模式下,对规模集模型进行更新时,现有的 VM 不会发生任何事情。

若要更新现有的 VM,必须对每个现有的 VM 进行”手动升级”。可通过以下方式进行此手动升级:

az vmss update-instances –resource-group myResourceGroup –name myScaleSet –instance-ids {instanceIds}

需要注意的是,有一类对全局规模集属性的修改不遵循升级策略。对规模集 OS 和数据磁盘配置文件(如管理员用户名和密码)的更改只能在 API 版本2017-12-01或更高版本中更改。这些更改仅适用于在对规模集模型进行更改后创建的 VM。若要更新现有的 VM,必须对每个现有的 VM 执行”重置映像”操作。可通过以下方式执行此重置映像操作:

az vmss reimage –resource-group myResourceGroup –name myScaleSet –instance-id instanceId

当前已经部署Ubuntu LTS 16.04 的规模集【假如版本为16.04.001】。希望更新规模集的 OS 映像以更好的支持业务系统运行,因此希望将其更新到新版 Ubuntu LTS 16.04,例如版本 16.04.201801090 因此可以使用下列命令之一直接修改这些属性:

az vmss update –resource-group myResourceGroup –name myScaleSet –set virtualMachineProfile.storageProfile.imageReference.version=16.04.201801090

或者,您可能想要更改规模集使用的映像。例如,可能想要更新或更改规模集使用的自定义映像。可以通过更新”映像引用 ID”属性来更改规模集使用的映像。

az vmss update –resource-group

myResourceGroup –name

myScaleSet –set virtualMachineProfile.storageProfile.imageReference.id=/subscriptions/

{subscriptionID}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/images/myNewImage

假设在已经部署的Azure虚拟机规模集中部署了 Azure 负载均衡器,现在需要将 Azure 负载均衡器替换为 Azure 应用程序网关。规模集的负载均衡器和应用程序网关属性是列表的一部分,因此可以使用以下命令来删除或添加列表元素,而不必直接修改属性:

# Remove the load balancer backend pool from the scale set model

az vmss update –resource-group myResourceGroup –name myScaleSet

–remove virtualMachineProfile.networkProfile.networkInterfaceConfigurations

[0].ipConfigurations[0].loadBalancerBackendAddressPools 0

# Remove the load balancer backend pool from the scale set model; only

necessary if you have NAT pools configured on the scale set

az vmss update –resource-group myResourceGroup –name myScaleSet

–remove virtualMachineProfile.networkProfile.networkInterfaceConfigurations

[0].ipConfigurations[0].loadBalancerInboundNatPools 0

# Add the application gateway backend pool to the scale set model

az vmss update –

-resource-group myResourceGroup –name myScaleSet –add

virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].

ipConfigurations[0].ApplicationGatewayBackendAddressPools

‘{“id”: “/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/

providers/Microsoft.Network/applicationGateways/

{applicationGatewayName}/backendAddressPools/{applicationGatewayBackendPoolName}”}’

规模集网络

通过门户部署 Azure 虚拟机规模集时,某些网络属性(例如带入站 NAT 规则的 Azure 负载均衡器)是默认设置的。 本小节介绍如何使用部分较高级的可以对规模集配置的网络功能。

Azure 加速网络(FPGA)可以实现对虚拟机的单根 I/O 虚拟化 (SR-IOV),从而提升网络性能。若要对规模集使用加速网络,请在规模集的 networkInterfaceConfigurations 设置中将 enableAcceleratedNetworking 设置为 **** true。 例如:

“networkProfile”: {

“networkInterfaceConfigurations”: [

{

“name”: “niconfig1”,

“properties”: {

“primary”: true,

“enableAcceleratedNetworking” : true,

“ipConfigurations”: [


]

}

}

]

}

这里需要强调的是,Azure VM Size中并不是所有的都支持FPGA,因此我们需要确保VM Size支持该功能然后才能使用上述脚本。

使用 Azure 门户创建规模集时一般默认都是创建新的负载均衡器。如果创建需引用现有负载均衡器的规模集,可以使用 CLI。以下示例脚本先创建负载均衡器,然后创建规模集来引用该均衡器:

az network lb create -g lbtest -n mylb –vnet-name myvnet –subnet mysubnet –public-ip-address-allocation Static –backend-pool-name mybackendpool

az vmss create -g lbtest -n myvmss –image Canonical:UbuntuServer:16.04-LTS:latest \

–admin-username negat –ssh-key-value /home/myuser/.ssh/id_rsa.pub –upgrade-policy-mode Automatic –instance-count 3 –vnet-name myvnet –subnet mysubnet –lb mylb –backend-pool-name mybackendpool

可以使用网络安全组通过安全规则来筛选 Azure 虚拟网络中出入 Azure 资源的流量。 可以通过应用程序安全组来处理 Azure 资源的网络安全问题,并将其作为应用程序结构的扩展组合起来。

可以直接向规模集应用网络安全组,只需将引用添加到规模集虚拟机属性的网络接口配置节即可。

也可以直接为规模集指定应用程序安全组,只需将引用添加到规模集虚拟机属性的网络接口 IP 配置节即可。

“networkProfile”: {

“networkInterfaceConfigurations”: [

{

“name”: “nic1”,

“properties”: {

“primary”: true,

“ipConfigurations”: [

{

“name”: “ip1”,

“properties”: {

“subnet”: {

“id”: “[concat(‘/subscriptions/’, subscription().subscriptionId,’/resourceGroups/’, resourceGroup().name, ‘/providers/Microsoft.Network/virtualNetworks/’, variables(‘vnetName’), ‘/subnets/subnet1’)]”

},

“applicationSecurityGroups”: [

{

“id”: “[concat(‘/subscriptions/’, subscription().subscriptionId,’/resourceGroups/’, resourceGroup().name, ‘/providers/Microsoft.Network/applicationSecurityGroups/’, variables(‘asgName’))]”

}

],

“loadBalancerInboundNatPools”: [

{

“id”: “[concat(‘/subscriptions/’, subscription().subscriptionId,’/resourceGroups/’, resourceGroup().name, ‘/providers/Microsoft.Network/loadBalancers/’, variables(‘lbName’), ‘/inboundNatPools/natPool1’)]”

}

],

“loadBalancerBackendAddressPools”: [

{

“id”: “[concat(‘/subscriptions/’, subscription().subscriptionId,’/resourceGroups/’, resourceGroup().name, ‘/providers/Microsoft.Network/loadBalancers/’, variables(‘lbName’), ‘/backendAddressPools/addressPool1’)]”

}

]

}

}

],

“networkSecurityGroup”: {

“id”: “[concat(‘/subscriptions/’, subscription().subscriptionId,’/resourceGroups/’, resourceGroup().name, ‘/providers/Microsoft.Network/networkSecurityGroups/’, variables(‘nsgName’))]”

}

}

}

]

}

本文固定链接: http://365vcloud.azurewebsites.net/2020/04/16/manage-and-operate-azure-virtual-machine-scale-set-a/ | 365vCloud的云计算之旅

该日志由 TingXu 于2020年04月16日发表在 Microsoft Azure 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: Azure Administrator认证学习指南之管理与维护Azure虚拟机规模集-45-A | 365vCloud的云计算之旅
关键字: , ,

Azure Administrator认证学习指南之管理与维护Azure虚拟机规模集-45-A:目前有253 条留言

发表评论

您必须 [ 登录 ] 才能发表留言!