Azure--Lab:配置公共负载均衡器

概述

通过 Azure 负载均衡器,你可以将用户请求分散到多台虚拟机或其他服务,使你能够将应用缩放到超过单台虚拟机可支持的大小,并确保即使虚拟机出现故障时用户也可以获得服务。

Azure 负载均衡器是一种可用于在多个虚拟机之间分配流量的服务。 使用负载均衡器可以缩放应用程序,并为虚拟机和服务提供高可用性。 负载均衡器使用基于哈希的分配算法。 默认情况下,使用 5 元组哈希将流量映射到可用服务器。 哈希由以下元素组成:

  • 源 IP:发出请求的客户端的 IP 地址。
  • 源端口:发出请求的客户端的端口。
  • 目标 IP:请求的目标 IP。
  • 目标端口:请求的目标端口。
  • 协议类型:指定的协议类型(TCP 或 UDP)。
    在这里插入图片描述
    使用可用性集和可用性区域来确保虚拟机始终可用:
配置服务级别协议 (SLA)信息
可用性集0.9995防止数据中心中出现硬件失败
可用性区域0.9998999999999999防止整个数据中心发生失败

可用性集

可用性集是一种逻辑分组,可用于将部署的虚拟机资源相互隔离。 Azure 确保可用性集中部署的虚拟机能够跨多个物理服务器、计算机架、存储单元和网络交换机运行。 如果发生硬件或软件失败,只有一部分虚拟机会受到影响。 整体解决方案仍会保持正常运行。 可用性集对于构建可靠的云解决方案至关重要。

可用性区域

可用性区域包含多个组,组中包含一个或多个数据中心,这些数据中心都具有独立电源、冷却设备和网络。 可用性区域中的虚拟机位于同一区域内的不同物理位置。 如果要确保在整个数据中心失败时可以继续为用户提供服务,请使用此体系结构。

选择合适的负载均衡器产品

基本负载均衡器和标准负载均衡器。

在 Azure 中创建负载均衡器时可以使用两种产品:基本负载均衡器和标准负载均衡器。

基本负载均衡器允许执行以下操作:

  • 端口转发
  • 自动重新配置
  • 运行状况探测
  • 通过源网络地址转换 (SNAT) 进行出站连接。
  • 通过 Azure 日志分析对面向公众的负载均衡器进行诊断

基本负载均衡器只能与可用性集一起使用

标准负载均衡器支持所有基本负载均衡器功能。 它们还允许执行以下操作:

  • HTTPS 运行状况探测
  • 可用性区域
  • 通过支持多维指标的 Azure Monitor 进行诊断
  • 高可用性 (HA) 端口
  • 出站规则
  • 有保证的 SLA(99.99% 针对两个或多个虚拟机)

内部和外部负载均衡器

外部负载均衡器通过在多个虚拟机之间分配客户端流量来运行。 外部负载均衡器允许来自 Internet 的流量。 流量可能来自浏览器、移动应用或其他源。
在这里插入图片描述

内部负载均衡器将内部 Azure 资源的负载分配给其他 Azure 资源。 例如,如果前端 Web 服务器需要调用托管在多个中间层服务器上的业务逻辑,则可以使用内部负载均衡器均匀分配该负载。 不允许任何来自 Internet 源的流量。

LAB 配置公共负载均衡器

本实验来自于:https://docs.microsoft.com/zh-cn/learn/modules/improve-app-scalability-resiliency-with-load-balancer/

可使用 Azure 门户、PowerShell 或 Azure CLI 配置 Azure 负载均衡器。

在某组织中,你希望根据门户 Web 服务器的运行状况对客户端流量进行负载均衡,以提供一致的响应。 可用性集中的两个虚拟机 (VM) 可以充当医疗保健门户 Web 应用程序。

此处将创建负载均衡器资源,并将其用于在 VM 之间分配负载。

部署门户 Web 应用程序

首先,在单个可用性集中的两个虚拟机上部署门户应用程序。 为节约时间,先运行脚本来创建此应用程序。 脚本将执行以下操作:

  • 针对 VM 创建虚拟网络和网络基础结构。
  • 在此虚拟网络中创建两个 VM。

要部署门户 Web 应用程序,执行以下操作:

  1. 在 Azure Cloud Shell 中运行以下 git clone 命令。 该命令会克隆包含应用的源的存储库,并运行 GitHub 中的设置脚本。 然后更改为克隆存储库的目录。
izhao_yiyi@Azure:~$ git clone https://github.com/MicrosoftDocs/mslearn-improve-app-scalability-resiliency-with-load-balancer.git
Cloning into 'mslearn-improve-app-scalability-resiliency-with-load-balancer'...
remote: Enumerating objects: 40, done.
remote: Total 40 (delta 0), reused 0 (delta 0), pack-reused 40
Unpacking objects: 100% (40/40), done.
izhao_yiyi@Azure:~$ ll
total 40K
drwxr-xr-x 4 izhao_yiyi izhao_yiyi 4.0K Dec 21 13:53 ./
drwxrwxrwx 3 root       root       4.0K Dec 21 13:53 ../
drwx------ 5 izhao_yiyi izhao_yiyi 4.0K Dec 21 13:53 .azure/
-rw------- 1 izhao_yiyi izhao_yiyi  109 Dec 21 13:53 .bash_history
-rw-r--r-- 1 izhao_yiyi izhao_yiyi  220 Apr 18  2019 .bash_logout
-rw-r--r-- 1 izhao_yiyi izhao_yiyi 3.8K Dec 21 13:53 .bashrc
lrwxrwxrwx 1 izhao_yiyi izhao_yiyi   22 Dec 21 13:53 clouddrive -> /usr/csuser/clouddrive/
drwxr-xr-x 3 izhao_yiyi izhao_yiyi 4.0K Dec 21 13:53 mslearn-improve-app-scalability-resiliency-with-load-balancer/
-rw-r--r-- 1 izhao_yiyi izhao_yiyi  807 Apr 18  2019 .profile
-rw-r--r-- 1 izhao_yiyi izhao_yiyi   42 Dec 21 13:53 .tmux.conf
-rw-r--r-- 1 izhao_yiyi izhao_yiyi  100 Oct 27  2020 .vimrc
  1. 此脚本将在单个可用性集中生成两个 VM。 运行该脚本需要大约 2 分钟。
izhao_yiyi@Azure:~$ cd mslearn-improve-app-scalability-resiliency-with-load-balancer/
izhao_yiyi@Azure:~/mslearn-improve-app-scalability-resiliency-with-load-balancer$ ls
backend-init.txt    create-high-availability-vm-with-sets.sh   LICENSE-CODE
cloud-init.txt      create-high-availability-vm-with-zones.sh  README.md
CODE_OF_CONDUCT.md  LICENSE
izhao_yiyi@Azure:~/mslearn-improve-app-scalability-resiliency-with-load-balancer$ *. create-high-availability-vm-with-sets.sh learn-db921f0e-864a-4ad7-9486-de5963f5562b*
Tue 21 Dec 2021 01:54:41 PM UTC
------------------------------------------
Creating a Virtual Network for the VMs
{
  "newVNet": {
    "addressSpace": {
      "addressPrefixes": [
        "10.0.0.0/16"
      ]
    },
    "bgpCommunities": null,
    "ddosProtectionPlan": null,
    "dhcpOptions": {
      "dnsServers": []
    },
    "enableDdosProtection": false,
    "enableVmProtection": null,
    "encryption": null,
    "etag": "W/\"77ac96b7-cf50-4987-80ca-44f76ff54b04\"",
    "extendedLocation": null,
    "flowTimeoutInMinutes": null,
    "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/virtualNetworks/bePortalVnet",
    "ipAllocations": null,
    "location": "westus",
    "name": "bePortalVnet",
    "provisioningState": "Succeeded",
    "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
    "resourceGuid": "0a507d3b-7add-4874-854b-dddefde4a449",
    "subnets": [
      {
        "addressPrefix": "10.0.0.0/24",
        "addressPrefixes": null,
        "applicationGatewayIpConfigurations": null,
        "delegations": [],
        "etag": "W/\"77ac96b7-cf50-4987-80ca-44f76ff54b04\"",
        "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/virtualNetworks/bePortalVnet/subnets/bePortalSubnet",
        "ipAllocations": null,
        "ipConfigurationProfiles": null,
        "ipConfigurations": null,
        "name": "bePortalSubnet",
        "natGateway": null,
        "networkSecurityGroup": {
          "defaultSecurityRules": null,
          "etag": null,
          "flowLogs": null,
          "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/SandboxNSGs/providers/Microsoft.Network/networkSecurityGroups/NSG-westus",
          "location": null,
          "name": null,
          "networkInterfaces": null,
          "provisioningState": null,
          "resourceGroup": "SandboxNSGs",
          "resourceGuid": null,
          "securityRules": null,
          "subnets": null,
          "tags": null,
          "type": null
        },
        "privateEndpointNetworkPolicies": "Enabled",
        "privateEndpoints": null,
        "privateLinkServiceNetworkPolicies": "Enabled",
        "provisioningState": "Succeeded",
        "purpose": null,
        "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
        "resourceNavigationLinks": null,
        "routeTable": null,
        "serviceAssociationLinks": null,
        "serviceEndpointPolicies": null,
        "serviceEndpoints": null,
        "type": "Microsoft.Network/virtualNetworks/subnets"
      }
    ],
    "tags": {},
    "type": "Microsoft.Network/virtualNetworks",
    "virtualNetworkPeerings": []
  }
}
------------------------------------------
Creating a Network Security Group
{
  "NewNSG": {
    "defaultSecurityRules": [
      {
        "access": "Allow",
        "description": "Allow inbound traffic from all VMs in VNET",
        "destinationAddressPrefix": "VirtualNetwork",
        "destinationAddressPrefixes": [],
        "destinationApplicationSecurityGroups": null,
        "destinationPortRange": "*",
        "destinationPortRanges": [],
        "direction": "Inbound",
        "etag": "W/\"cb1abaca-062f-4ea1-8b15-18d3cabeef1d\"",
        "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkSecurityGroups/bePortalNSG/defaultSecurityRules/AllowVnetInBound",
        "name": "AllowVnetInBound",
        "priority": 65000,
        "protocol": "*",
        "provisioningState": "Succeeded",
        "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
        "sourceAddressPrefix": "VirtualNetwork",
        "sourceAddressPrefixes": [],
        "sourceApplicationSecurityGroups": null,
        "sourcePortRange": "*",
        "sourcePortRanges": [],
        "type": "Microsoft.Network/networkSecurityGroups/defaultSecurityRules"
      },
      {
        "access": "Allow",
        "description": "Allow inbound traffic from azure load balancer",
        "destinationAddressPrefix": "*",
        "destinationAddressPrefixes": [],
        "destinationApplicationSecurityGroups": null,
        "destinationPortRange": "*",
        "destinationPortRanges": [],
        "direction": "Inbound",
        "etag": "W/\"cb1abaca-062f-4ea1-8b15-18d3cabeef1d\"",
        "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkSecurityGroups/bePortalNSG/defaultSecurityRules/AllowAzureLoadBalancerInBound",
        "name": "AllowAzureLoadBalancerInBound",
        "priority": 65001,
        "protocol": "*",
        "provisioningState": "Succeeded",
        "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
        "sourceAddressPrefix": "AzureLoadBalancer",
        "sourceAddressPrefixes": [],
        "sourceApplicationSecurityGroups": null,
        "sourcePortRange": "*",
        "sourcePortRanges": [],
        "type": "Microsoft.Network/networkSecurityGroups/defaultSecurityRules"
      },
      {
        "access": "Deny",
        "description": "Deny all inbound traffic",
        "destinationAddressPrefix": "*",
        "destinationAddressPrefixes": [],
        "destinationApplicationSecurityGroups": null,
        "destinationPortRange": "*",
        "destinationPortRanges": [],
        "direction": "Inbound",
        "etag": "W/\"cb1abaca-062f-4ea1-8b15-18d3cabeef1d\"",
        "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkSecurityGroups/bePortalNSG/defaultSecurityRules/DenyAllInBound",
        "name": "DenyAllInBound",
        "priority": 65500,
        "protocol": "*",
        "provisioningState": "Succeeded",
        "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
        "sourceAddressPrefix": "*",
        "sourceAddressPrefixes": [],
        "sourceApplicationSecurityGroups": null,
        "sourcePortRange": "*",
        "sourcePortRanges": [],
        "type": "Microsoft.Network/networkSecurityGroups/defaultSecurityRules"
      },
      {
        "access": "Allow",
        "description": "Allow outbound traffic from all VMs to all VMs in VNET",
        "destinationAddressPrefix": "VirtualNetwork",
        "destinationAddressPrefixes": [],
        "destinationApplicationSecurityGroups": null,
        "destinationPortRange": "*",
        "destinationPortRanges": [],
        "direction": "Outbound",
        "etag": "W/\"cb1abaca-062f-4ea1-8b15-18d3cabeef1d\"",
        "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkSecurityGroups/bePortalNSG/defaultSecurityRules/AllowVnetOutBound",
        "name": "AllowVnetOutBound",
        "priority": 65000,
        "protocol": "*",
        "provisioningState": "Succeeded",
        "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
        "sourceAddressPrefix": "VirtualNetwork",
        "sourceAddressPrefixes": [],
        "sourceApplicationSecurityGroups": null,
        "sourcePortRange": "*",
        "sourcePortRanges": [],
        "type": "Microsoft.Network/networkSecurityGroups/defaultSecurityRules"
      },
      {
        "access": "Allow",
        "description": "Allow outbound traffic from all VMs to Internet",
        "destinationAddressPrefix": "Internet",
        "destinationAddressPrefixes": [],
        "destinationApplicationSecurityGroups": null,
        "destinationPortRange": "*",
        "destinationPortRanges": [],
        "direction": "Outbound",
        "etag": "W/\"cb1abaca-062f-4ea1-8b15-18d3cabeef1d\"",
        "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkSecurityGroups/bePortalNSG/defaultSecurityRules/AllowInternetOutBound",
        "name": "AllowInternetOutBound",
        "priority": 65001,
        "protocol": "*",
        "provisioningState": "Succeeded",
        "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
        "sourceAddressPrefix": "*",
        "sourceAddressPrefixes": [],
        "sourceApplicationSecurityGroups": null,
        "sourcePortRange": "*",
        "sourcePortRanges": [],
        "type": "Microsoft.Network/networkSecurityGroups/defaultSecurityRules"
      },
      {
        "access": "Deny",
        "description": "Deny all outbound traffic",
        "destinationAddressPrefix": "*",
        "destinationAddressPrefixes": [],
        "destinationApplicationSecurityGroups": null,
        "destinationPortRange": "*",
        "destinationPortRanges": [],
        "direction": "Outbound",
        "etag": "W/\"cb1abaca-062f-4ea1-8b15-18d3cabeef1d\"",
        "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkSecurityGroups/bePortalNSG/defaultSecurityRules/DenyAllOutBound",
        "name": "DenyAllOutBound",
        "priority": 65500,
        "protocol": "*",
        "provisioningState": "Succeeded",
        "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
        "sourceAddressPrefix": "*",
        "sourceAddressPrefixes": [],
        "sourceApplicationSecurityGroups": null,
        "sourcePortRange": "*",
        "sourcePortRanges": [],
        "type": "Microsoft.Network/networkSecurityGroups/defaultSecurityRules"
      }
    ],
    "etag": "W/\"cb1abaca-062f-4ea1-8b15-18d3cabeef1d\"",
    "flowLogs": null,
    "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkSecurityGroups/bePortalNSG",
    "location": "westus",
    "name": "bePortalNSG",
    "networkInterfaces": null,
    "provisioningState": "Succeeded",
    "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
    "resourceGuid": "cbe80d50-7107-4a7a-bb63-6f40766e57d3",
    "securityRules": [],
    "subnets": null,
    "tags": null,
    "type": "Microsoft.Network/networkSecurityGroups"
  }
}
------------------------------------------
Allowing access on port 80
{
  "access": "Allow",
  "description": "Allow inbound on port 80.",
  "destinationAddressPrefix": "*",
  "destinationAddressPrefixes": [],
  "destinationApplicationSecurityGroups": null,
  "destinationPortRange": "80",
  "destinationPortRanges": [],
  "direction": "Inbound",
  "etag": "W/\"c058ae62-57d1-4aac-a1d6-85b16f8557ba\"",
  "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkSecurityGroups/bePortalNSG/securityRules/Allow-80-Inbound",
  "name": "Allow-80-Inbound",
  "priority": 110,
  "protocol": "Tcp",
  "provisioningState": "Succeeded",
  "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
  "sourceAddressPrefix": "*",
  "sourceAddressPrefixes": [],
  "sourceApplicationSecurityGroups": null,
  "sourcePortRange": "*",
  "sourcePortRanges": [],
  "type": "Microsoft.Network/networkSecurityGroups/securityRules"
}
------------------------------------------
Creating **webNic1**
{
  "NewNIC": {
    "dnsSettings": {
      "appliedDnsServers": [],
      "dnsServers": [],
      "internalDnsNameLabel": null,
      "internalDomainNameSuffix": "hn4vacw3pj0erbkl1xpp1zfejb.dx.internal.cloudapp.net",
      "internalFqdn": null
    },
    "dscpConfiguration": null,
    "enableAcceleratedNetworking": false,
    "enableIpForwarding": false,
    "etag": "W/\"17e4fefc-6ccc-4b8f-9cc5-a05fadd97daf\"",
    "extendedLocation": null,
    "hostedWorkloads": [],
    "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkInterfaces/webNic1",
    "ipConfigurations": [
      {
        "applicationGatewayBackendAddressPools": null,
        "applicationSecurityGroups": null,
        "etag": "W/\"17e4fefc-6ccc-4b8f-9cc5-a05fadd97daf\"",
        "gatewayLoadBalancer": null,
        "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkInterfaces/webNic1/ipConfigurations/ipconfig1",
        "loadBalancerBackendAddressPools": null,
        "loadBalancerInboundNatRules": null,
        "name": "ipconfig1",
        "primary": true,
        "privateIpAddress": "**10.0.0.4**",
        "privateIpAddressVersion": "IPv4",
        "privateIpAllocationMethod": "Dynamic",
        "privateLinkConnectionProperties": null,
        "provisioningState": "Succeeded",
        "publicIpAddress": null,
        "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
        "subnet": {
          "addressPrefix": null,
          "addressPrefixes": null,
          "applicationGatewayIpConfigurations": null,
          "delegations": null,
          "etag": null,
          "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/virtualNetworks/bePortalVnet/subnets/bePortalSubnet",
          "ipAllocations": null,
          "ipConfigurationProfiles": null,
          "ipConfigurations": null,
          "name": null,
          "natGateway": null,
          "networkSecurityGroup": null,
          "privateEndpointNetworkPolicies": null,
          "privateEndpoints": null,
          "privateLinkServiceNetworkPolicies": null,
          "provisioningState": null,
          "purpose": null,
          "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
          "resourceNavigationLinks": null,
          "routeTable": null,
          "serviceAssociationLinks": null,
          "serviceEndpointPolicies": null,
          "serviceEndpoints": null,
          "type": null
        },
        "type": "Microsoft.Network/networkInterfaces/ipConfigurations",
        "virtualNetworkTaps": null
      }
    ],
    "location": "westus",
    "macAddress": null,
    "migrationPhase": null,
    "name": "webNic1",
    "networkSecurityGroup": {
      "defaultSecurityRules": null,
      "etag": null,
      "flowLogs": null,
      "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkSecurityGroups/bePortalNSG",
      "location": null,
      "name": null,
      "networkInterfaces": null,
      "provisioningState": null,
      "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
      "resourceGuid": null,
      "securityRules": null,
      "subnets": null,
      "tags": null,
      "type": null
    },
    "nicType": "Standard",
    "primary": null,
    "privateEndpoint": null,
    "privateLinkService": null,
    "provisioningState": "Succeeded",
    "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
    "resourceGuid": "f7590b62-424b-4102-b115-7be39948d602",
    "tags": null,
    "tapConfigurations": [],
    "type": "Microsoft.Network/networkInterfaces",
    "virtualMachine": null,
    "vnetEncryptionSupported": false,
    "workloadType": null
  }
}
------------------------------------------
Creating **webNic2**
{
  "NewNIC": {
    "dnsSettings": {
      "appliedDnsServers": [],
      "dnsServers": [],
      "internalDnsNameLabel": null,
      "internalDomainNameSuffix": "hn4vacw3pj0erbkl1xpp1zfejb.dx.internal.cloudapp.net",
      "internalFqdn": null
    },
    "dscpConfiguration": null,
    "enableAcceleratedNetworking": false,
    "enableIpForwarding": false,
    "etag": "W/\"d05c9953-edef-4a69-bf67-2d0f361dfb66\"",
    "extendedLocation": null,
    "hostedWorkloads": [],
    "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkInterfaces/webNic2",
    "ipConfigurations": [
      {
        "applicationGatewayBackendAddressPools": null,
        "applicationSecurityGroups": null,
        "etag": "W/\"d05c9953-edef-4a69-bf67-2d0f361dfb66\"",
        "gatewayLoadBalancer": null,
        "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkInterfaces/webNic2/ipConfigurations/ipconfig1",
        "loadBalancerBackendAddressPools": null,
        "loadBalancerInboundNatRules": null,
        "name": "ipconfig1",
        "primary": true,
        "privateIpAddress": "**10.0.0.5**",
        "privateIpAddressVersion": "IPv4",
        "privateIpAllocationMethod": "Dynamic",
        "privateLinkConnectionProperties": null,
        "provisioningState": "Succeeded",
        "publicIpAddress": null,
        "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
        "subnet": {
          "addressPrefix": null,
          "addressPrefixes": null,
          "applicationGatewayIpConfigurations": null,
          "delegations": null,
          "etag": null,
          "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/virtualNetworks/bePortalVnet/subnets/bePortalSubnet",
          "ipAllocations": null,
          "ipConfigurationProfiles": null,
          "ipConfigurations": null,
          "name": null,
          "natGateway": null,
          "networkSecurityGroup": null,
          "privateEndpointNetworkPolicies": null,
          "privateEndpoints": null,
          "privateLinkServiceNetworkPolicies": null,
          "provisioningState": null,
          "purpose": null,
          "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
          "resourceNavigationLinks": null,
          "routeTable": null,
          "serviceAssociationLinks": null,
          "serviceEndpointPolicies": null,
          "serviceEndpoints": null,
          "type": null
        },
        "type": "Microsoft.Network/networkInterfaces/ipConfigurations",
        "virtualNetworkTaps": null
      }
    ],
    "location": "westus",
    "macAddress": null,
    "migrationPhase": null,
    "name": "webNic2",
    "networkSecurityGroup": {
      "defaultSecurityRules": null,
      "etag": null,
      "flowLogs": null,
      "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkSecurityGroups/bePortalNSG",
      "location": null,
      "name": null,
      "networkInterfaces": null,
      "provisioningState": null,
      "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
      "resourceGuid": null,
      "securityRules": null,
      "subnets": null,
      "tags": null,
      "type": null
    },
    "nicType": "Standard",
    "primary": null,
    "privateEndpoint": null,
    "privateLinkService": null,
    "provisioningState": "Succeeded",
    "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
    "resourceGuid": "2b020a7d-452b-4c93-9ece-ac3202b7e907",
    "tags": null,
    "tapConfigurations": [],
    "type": "Microsoft.Network/networkInterfaces",
    "virtualMachine": null,
    "vnetEncryptionSupported": false,
    "workloadType": null
  }
}
------------------------------------------
Creating an availability set
{
  "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Compute/availabilitySets/portalAvailabilitySet",
  "location": "westus",
  "name": "portalAvailabilitySet",
  "platformFaultDomainCount": 2,
  "platformUpdateDomainCount": 5,
  "proximityPlacementGroup": null,
  "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
  "sku": {
    "capacity": null,
    "name": "Aligned",
    "tier": null
  },
  "statuses": null,
  "tags": {},
  "type": "Microsoft.Compute/availabilitySets",
  "virtualMachines": []
}
------------------------------------------
Creating **webVM1**
SSH key files '/home/izhao_yiyi/.ssh/id_rsa' and '/home/izhao_yiyi/.ssh/id_rsa.pub' have been generated under ~/.ssh to allow SSH access to the VM. If using machines without permanent storage, back up your keys to a safe location.
It is recommended to use parameter "--public-ip-sku Standard" to create new VM with Standardpublic IP. Please note that the default public IP used for VM creation will be changed from Basic to Standard in the future.
{
  "fqdns": "",
  "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Compute/virtualMachines/webVM1",
  "location": "**westus**",
  "macAddress": "00-0D-3A-59-2C-45",
  "powerState": "VM running",
  "privateIpAddress": "**10.0.0.4**",
  "publicIpAddress": "",
  "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
  "zones": ""
}
------------------------------------------
Creating **webVM2**
It is recommended to use parameter "--public-ip-sku Standard" to create new VM with Standardpublic IP. Please note that the default public IP used for VM creation will be changed from Basic to Standard in the future.
{
  "fqdns": "",
  "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Compute/virtualMachines/webVM2",
  "location": "westus",
  "macAddress": "00-22-48-04-98-D4",
  "powerState": "VM running",
  "privateIpAddress": "**10.0.0.5**",
  "publicIpAddress": "",
  "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
  "zones": ""
}
--------------------------------------------------------
             VM Setup Script Completed
--------------------------------------------------------

从这里可以看到:

webVM1—>webNic1:10.0.0.4

webVM2—>webNic2:10.0.0.5

About this sh:

izhao_yiyi@Azure:~/mslearn-improve-app-scalability-resiliency-with-load-balancer$ cat create-high-availability-vm-with-sets.sh
#!/bin/bash
# Usage: bash create-high-availability-vm-with-sets.sh <Resource Group Name>

RgName=$1

date
# Create a Virtual Network for the VMs
echo '------------------------------------------'
echo 'Creating a Virtual Network for the VMs'
az network vnet create \
    --resource-group $RgName \
    --name bePortalVnet \
    --subnet-name bePortalSubnet

# Create a Network Security Group
echo '------------------------------------------'
echo 'Creating a Network Security Group'
az network nsg create \
    --resource-group $RgName \
    --name bePortalNSG

# Add inbound rule on port 80
echo '------------------------------------------'
echo 'Allowing access on port 80'
az network nsg rule create \
    --resource-group $RgName \
    --nsg-name bePortalNSG \
    --name Allow-80-Inbound \
    --priority 110 \
    --source-address-prefixes '*' \
    --source-port-ranges '*' \
    --destination-address-prefixes '*' \
    --destination-port-ranges 80 \
    --access Allow \
    --protocol Tcp \
    --direction Inbound \
    --description "Allow inbound on port 80."

# Create the NIC
for i in `seq 1 2`; do
  echo '------------------------------------------'
  echo 'Creating webNic'$i
  az network nic create \
    --resource-group $RgName \
    --name webNic$i \
    --vnet-name bePortalVnet \
    --subnet bePortalSubnet \
    --network-security-group bePortalNSG
done

# Create an availability set
echo '------------------------------------------'
echo 'Creating an availability set'
az vm availability-set create -n portalAvailabilitySet -g $RgName

# Create 2 VM's from a template
for i in `seq 1 2`; do
    echo '------------------------------------------'
    echo 'Creating webVM'$i
    az vm create \
        --admin-username azureuser \
        --resource-group $RgName \
        --name webVM$i \
        --nics webNic$i \
        --image UbuntuLTS \
        --availability-set portalAvailabilitySet \
        --generate-ssh-keys \
        --custom-data cloud-init.txt
done

# Done
echo '--------------------------------------------------------'
echo '             VM Setup Script Completed'
echo '--------------------------------------------------------'
  1. 脚本运行完成后,在 Azure 门户菜单查看脚本创建的资源。

创建负载均衡器

使用 Azure CLI 来创建负载均衡器及其相关资源。

  1. 创建新的公共 IP 地址。
izhao_yiyi@Azure:~$ az network public-ip create \
>   --resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b \
>   --allocation-method Static \
>   --name **myPublicIP**
{
  "publicIp": {
    "ddosSettings": null,
    "deleteOption": null,
    "dnsSettings": null,
    "etag": "W/\"ac1ca328-eeb9-47fd-b17c-5f93e79aa72b\"",
    "extendedLocation": null,
    "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/publicIPAddresses/myPublicIP",
    "idleTimeoutInMinutes": 4,
    "ipAddress": "**168.62.212.104**",
    "ipConfiguration": null,
    "ipTags": [],
    "linkedPublicIpAddress": null,
    "location": "westus",
    "migrationPhase": null,
    "name": "myPublicIP",
    "natGateway": null,
    "provisioningState": "Succeeded",
    "publicIpAddressVersion": "IPv4",
    "publicIpAllocationMethod": "Static",
    "publicIpPrefix": null,
    "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
    "resourceGuid": "3c20b27c-0562-4834-b2f3-deba21e65dea",
    "servicePublicIpAddress": null,
    "sku": {
      "name": "Basic",
      "tier": "Regional"
    },
    "tags": null,
    "type": "Microsoft.Network/publicIPAddresses",
    "zones": null
  }
}
  1. 创建负载均衡器。
izhao_yiyi@Azure:~$ az network lb create \
>   --resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b \
>   --name **myLoadBalancer** \
>   --public-ip-address ***myPublicIP*** \
>   --frontend-ip-name **myFrontEndPool** \
>   --backend-pool-name **myBackEndPool**
{
  "**loadBalancer**": {
    "backendAddressPools": [
      {
        "etag": "W/\"0ed9ae2b-e3c5-4f07-84f0-56809d84ecc3\"",
        "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/loadBalancers/myLoadBalancer/backendAddressPools/myBackEndPool",
        "name": "**myBackEndPool**",
        "properties": {
          "provisioningState": "Succeeded"
        },
        "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
        "type": "Microsoft.Network/loadBalancers/backendAddressPools"
      }
    ],
    "frontendIPConfigurations": [
      {
        "etag": "W/\"0ed9ae2b-e3c5-4f07-84f0-56809d84ecc3\"",
        "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/loadBalancers/myLoadBalancer/frontendIPConfigurations/myFrontEndPool",
        "name": "**myFrontEndPool**",
        "properties": {
          "privateIPAllocationMethod": "Dynamic",
          "provisioningState": "Succeeded",
          "publicIPAddress": {
            "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/publicIPAddresses/myPublicIP",
            "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b"
          }
        },
        "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
        "type": "Microsoft.Network/loadBalancers/frontendIPConfigurations"
      }
    ],
    "inboundNatPools": [],
    "inboundNatRules": [],
    "loadBalancingRules": [],
    "probes": [],
    "provisioningState": "Succeeded",
    "resourceGuid": "4a9c1e82-d943-43a5-aca5-6629bf5991e2"
  }
}
  1. 创建运行状况探测,允许负载均衡器监视医疗保健门户的状态。 运行状况探测器基于其对运行状况检查的响应,从负载均衡器中动态添加或删除 VM。
izhao_yiyi@Azure:~$ az network **lb probe** create \
>   --resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b \
>   --lb-name **myLoadBalancer** \
>   --name **myHealthProbe** \
>   --protocol tcp \
>   --port **80**
{
  "etag": "W/\"e5a3523b-fb66-4acb-9195-dee53dfe0579\"",
  "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/loadBalancers/myLoadBalancer/probes/myHealthProbe",
  "intervalInSeconds": 15,
  "loadBalancingRules": null,
  "name": "myHealthProbe",
  "numberOfProbes": 2,
  "port": 80,
  "protocol": "Tcp",
  "provisioningState": "Succeeded",
  "requestPath": null,
  "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
  "type": "**Microsoft.Network/loadBalancers/probes**"
}
  1. 现在,需要一个负载均衡器规则,用于定义将流量分配给 VM 的方式。 定义传入流量的前端 IP 配置和后端 IP 池以接收流量,同时定义所需源和目标端口。 若要确保仅正常运行的 VM 接收流量,还需定义要使用的运行状况探测。
izhao_yiyi@Azure:~$ az network **lb rule** create \
>   --resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b \
>   --lb-name **myLoadBalancer** \
>   --name **myHTTPRule** \
>   --protocol tcp \
>   --frontend-port 80 \
>   --backend-port 80 \
>   --frontend-ip-name myFrontEndPool \
>   --backend-pool-name myBackEndPool \
>   --probe-name myHealthProbe
{
  "backendAddressPool": {
    "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/loadBalancers/myLoadBalancer/backendAddressPools/myBackEndPool",
    "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b"
  },
  "backendAddressPools": [
    {
      "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/loadBalancers/myLoadBalancer/backendAddressPools/myBackEndPool",
      "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b"
    }
  ],
  "backendPort": 80,
  "disableOutboundSnat": null,
  "enableFloatingIp": false,
  "enableTcpReset": false,
  "etag": "W/\"fc12f19a-4e6b-45fe-abb5-786c5a49c923\"",
  "frontendIpConfiguration": {
    "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/loadBalancers/myLoadBalancer/frontendIPConfigurations/myFrontEndPool",
    "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b"
  },
  "frontendPort": 80,
  "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/loadBalancers/myLoadBalancer/loadBalancingRules/myHTTPRule",
  "idleTimeoutInMinutes": 4,
  "loadDistribution": "Default",
  "name": "myHTTPRule",
  "probe": {
    "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/loadBalancers/myLoadBalancer/probes/myHealthProbe",
    "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b"
  },
  "protocol": "Tcp",
  "provisioningState": "Succeeded",
  "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
  "type": "**Microsoft.Network/loadBalancers/loadBalancingRules**"
}
  1. 通过更新为使用后端池信息而在脚本中创建的网络接口,将 VM 连接到后端池。

回顾前面配置的VM:

webVM1—>webNic1:10.0.0.4

webVM2—>webNic2:10.0.0.5

izhao_yiyi@Azure:~$ az network nic ip-config update \
>   --resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b \
>   --nic-name **webNic1** \
>   --name ipconfig1 \
>   --lb-name **myLoadBalancer** \
>   --lb-address-pools **myBackEndPool**
{
  "applicationGatewayBackendAddressPools": null,
  "applicationSecurityGroups": null,
  "etag": "W/\"eae5cba8-351d-43fb-af8c-f833942aab22\"",
  "gatewayLoadBalancer": null,
  "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkInterfaces/webNic1/ipConfigurations/ipconfig1",
  "loadBalancerBackendAddressPools": [
    {
      "backendIpConfigurations": null,
      "etag": null,
      "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/loadBalancers/myLoadBalancer/backendAddressPools/myBackEndPool",
      "inboundNatRules": null,
      "loadBalancerBackendAddresses": null,
      "loadBalancingRules": null,
      "location": null,
      "name": null,
      "outboundRule": null,
      "outboundRules": null,
      "provisioningState": null,
      "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
      "tunnelInterfaces": null,
      "type": null
    }
  ],
  "loadBalancerInboundNatRules": null,
  "name": "ipconfig1",
  "primary": true,
  "privateIpAddress": "10.0.0.4",
  "privateIpAddressVersion": "IPv4",
  "privateIpAllocationMethod": "Dynamic",
  "privateLinkConnectionProperties": null,
  "provisioningState": "Succeeded",
  "publicIpAddress": null,
  "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
  "subnet": {
    "addressPrefix": null,
    "addressPrefixes": null,
    "applicationGatewayIpConfigurations": null,
    "delegations": null,
    "etag": null,
    "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/virtualNetworks/bePortalVnet/subnets/bePortalSubnet",
    "ipAllocations": null,
    "ipConfigurationProfiles": null,
    "ipConfigurations": null,
    "name": null,
    "natGateway": null,
    "networkSecurityGroup": null,
    "privateEndpointNetworkPolicies": null,
    "privateEndpoints": null,
    "privateLinkServiceNetworkPolicies": null,
    "provisioningState": null,
    "purpose": null,
    "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
    "resourceNavigationLinks": null,
    "routeTable": null,
    "serviceAssociationLinks": null,
    "serviceEndpointPolicies": null,
    "serviceEndpoints": null,
    "type": null
  },
  "type": "Microsoft.Network/networkInterfaces/ipConfigurations",
  "virtualNetworkTaps": null
}
izhao_yiyi@Azure:~$
izhao_yiyi@Azure:~$ az network nic ip-config update \
>   --resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b \
>   --nic-name **webNic2** \
>   --name ipconfig1 \
>   --lb-name **myLoadBalancer** \
>   --lb-address-pools **myBackEndPool**
{
  "applicationGatewayBackendAddressPools": null,
  "applicationSecurityGroups": null,
  "etag": "W/\"5f122b31-d428-4c4b-b36b-5076dffb4cb4\"",
  "gatewayLoadBalancer": null,
  "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/networkInterfaces/webNic2/ipConfigurations/ipconfig1",
  "loadBalancerBackendAddressPools": [
    {
      "backendIpConfigurations": null,
      "etag": null,
      "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/loadBalancers/myLoadBalancer/backendAddressPools/myBackEndPool",
      "inboundNatRules": null,
      "loadBalancerBackendAddresses": null,
      "loadBalancingRules": null,
      "location": null,
      "name": null,
      "outboundRule": null,
      "outboundRules": null,
      "provisioningState": null,
      "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
      "tunnelInterfaces": null,
      "type": null
    }
  ],
  "loadBalancerInboundNatRules": null,
  "name": "ipconfig1",
  "primary": true,
  "privateIpAddress": "10.0.0.5",
  "privateIpAddressVersion": "IPv4",
  "privateIpAllocationMethod": "Dynamic",
  "privateLinkConnectionProperties": null,
  "provisioningState": "Succeeded",
  "publicIpAddress": null,
  "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
  "subnet": {
    "addressPrefix": null,
    "addressPrefixes": null,
    "applicationGatewayIpConfigurations": null,
    "delegations": null,
    "etag": null,
    "id": "/subscriptions/f27a2135-1ae7-44b2-b514-f0b7b1dcbfba/resourceGroups/learn-db921f0e-864a-4ad7-9486-de5963f5562b/providers/Microsoft.Network/virtualNetworks/bePortalVnet/subnets/bePortalSubnet",
    "ipAllocations": null,
    "ipConfigurationProfiles": null,
    "ipConfigurations": null,
    "name": null,
    "natGateway": null,
    "networkSecurityGroup": null,
    "privateEndpointNetworkPolicies": null,
    "privateEndpoints": null,
    "privateLinkServiceNetworkPolicies": null,
    "provisioningState": null,
    "purpose": null,
    "resourceGroup": "learn-db921f0e-864a-4ad7-9486-de5963f5562b",
    "resourceNavigationLinks": null,
    "routeTable": null,
    "serviceAssociationLinks": null,
    "serviceEndpointPolicies": null,
    "serviceEndpoints": null,
    "type": null
  },
  "type": "Microsoft.Network/networkInterfaces/ipConfigurations",
  "virtualNetworkTaps": null
}
  1. 运行以下命令,获取负载均衡器的公共 IP 地址和网站的 URL。
izhao_yiyi@Azure:~$ echo http://$(az network public-ip show \
>                 --resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b \
>                 --name myPublicIP \
>                 --query ipAddress \
>                 --output tsv)
**http://168.62.212.104**

该地址就是第一步创建的公共IP地址。
在这里插入图片描述
在这里插入图片描述

本实验使用的命令:

  • git clone https://github.com/MicrosoftDocs/mslearn-improve-app-scalability-resiliency-with-load-balancer.git
  • cd mslearn-improve-app-scalability-resiliency-with-load-balancer
  • . create-high-availability-vm-with-sets.sh learn-db921f0e-864a-4ad7-9486-de5963f5562b
  • az network public-ip create
    –resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b
    –allocation-method Static
    –name myPublicIP
  • az network lb create
    –resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b
    –name myLoadBalancer
    –public-ip-address myPublicIP
    –frontend-ip-name myFrontEndPool
    –backend-pool-name myBackEndPool
  • az network lb probe create
    –resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b
    –lb-name myLoadBalancer
    –name myHealthProbe
    –protocol tcp
    –port 80
  • az network lb rule create
    –resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b
    –lb-name myLoadBalancer
    –name myHTTPRule
    –protocol tcp
    –frontend-port 80
    –backend-port 80
    –frontend-ip-name myFrontEndPool
    –backend-pool-name myBackEndPool
    –probe-name myHealthProbe
  • az network nic ip-config update
    –resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b
    –nic-name webNic1
    –name ipconfig1
    –lb-name myLoadBalancer
    –lb-address-pools myBackEndPool
  • az network nic ip-config update
    –resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b
    –nic-name webNic2
    –name ipconfig1
    –lb-name myLoadBalancer
    –lb-address-pools myBackEndPool
  • echo http://$(az network public-ip show
    –resource-group learn-db921f0e-864a-4ad7-9486-de5963f5562b
    –name myPublicIP
    –query ipAddress
    –output tsv)
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值