zoukankan      html  css  js  c++  java
  • 七层负载(Application Gateway)+四层负载(LB)

    上次有个电商客户需要搭建如架构。

    192.168.1.100/url1(请求url)——>Node1:10.0.0.4、10.0.0.5(服务器IP)

    192.168.1.100/url2(请求url)——>Node2:10.0.0.6、10.0.0.7(服务器IP)

    一个客户端根据请求Url进行流量分配,/url1流量走到Node1,然后Node1这个节点再进行一次流量负载。那么这种应用场景可以使用七层负载均衡(Application Gateway)+四层负载均衡(LB),架构图如下:

    此种架构在Azure上实现起来是非常方便的,因为Azure直接就提供7层和4层负载均衡的Pass服务。

    1、创建虚拟机(应用服务器)

    按照上图架构中所示,这里我需要创建四台虚拟机,创建虚机的具体步骤这里就不赘述了。

    按照上图所示,我已经创建好了四台虚机:imagevm01、imagevm02、videovm01、videovm02

    然后,我分别给这四台虚拟机安装IIS,部署了一个网站,每个虚机部署的网站都带有自己的唯一标识。

    2、创建四层负载均衡器(Load Banlancer)

    按照如下图所示创建两个Load Banlancer

    按照上图我已经创建好了两个Load Banlancer:imagelb、videolb

    然后我们需要分别将imagevm01、imagevm02加入imagelb的后端池

    videovm01、videovm02加入videolb的后端池

    3、创建七层负载均衡(Application Gateway)

    登录到 Azure

    Login-AzureRmAccount -EnvironmentName AzureChinaCloud

     

     

     

    创建资源组或获取资源组

    因为我们创建虚拟机和四层负载均衡已经创建好了资源组,将Application Gateway和这些资源放在一个资源组即可

    Get-AzureRmResourceGroup -Name "{resource group name}" -Location ""

    或者也可以新建一个资源组。

    New-AzureRmResourceGroup -Name AppgwRG -Location "China East"

     

    获取虚拟网络

    $vnet = Get-AzureRmVirtualNetwork -ResourceGroupName "{resource group name}" -Name "{virual network name}"

    分配子网变量,便于完成后面的创建应用程序网关的步骤。

    $subnet=$vnet.Subnets[0]

     

    创建前端配置的公共 IP 地址

    创建前端的公共IP,这个IP就是我们最终访问的Application Gateway的IP地址

    $publicip = New-AzureRmPublicIpAddress -ResourceGroupName AppgwRG -name publicIP01 -location "China North" -AllocationMethod Dynamic

     

    创建应用程序网关配置

    创建名为“gatewayIP01”的应用程序网关 IP 配置。当应用程序网关启动时,它会从配置的子网获取 IP 地址,再将网络流量路由到后端 IP 池中的 IP 地址。请记住,每个实例需要一个 IP 地址。

    $gipconfig = New-AzureRmApplicationGatewayIPConfiguration -Name gatewayIP01 -Subnet $subnet

    分别配置名为“pool01”和“pool2”的后端 IP 地址池,其中,“pool1”的 IP 地址为imagelb的IP地址“42.159.242.134 (imagelbpublicip)”;“pool2”的 IP 地址为videolb的IP地址“139.219.185.186 (videolbpublicip)”。

    $pool1 = New-AzureRmApplicationGatewayBackendAddressPool -Name pool01 -BackendIPAddresses 134.170.185.46, 134.170.188.221,134.170.185.50

    $pool2 = New-AzureRmApplicationGatewayBackendAddressPool -Name pool02 -BackendIPAddresses 134.170.186.46, 134.170.189.221,134.170.186.50

    为后端池中进行了负载均衡的网络流量配置应用程序网关设置“poolsetting01”和“poolsetting02”

    $poolSetting01 = New-AzureRmApplicationGatewayBackendHttpSettings -Name "besetting01" -Port 80 -Protocol Http -CookieBasedAffinity Disabled -RequestTimeout 120

    $poolSetting02 = New-AzureRmApplicationGatewayBackendHttpSettings -Name "besetting02" -Port 80 -Protocol Http -CookieBasedAffinity Enabled -RequestTimeout 240

    使用公共 IP 终结点配置前端 IP

    $fipconfig01 = New-AzureRmApplicationGatewayFrontendIPConfig -Name "frontend1" -PublicIPAddress $publicip

    配置应用程序网关的前端端口

    $fp01 = New-AzureRmApplicationGatewayFrontendPort -Name "fep01" -Port 80

    配置侦听器。此步骤针对用于接收传入网络流量的公共 IP 地址和连接端口配置侦听器。

    $listener = New-AzureRmApplicationGatewayHttpListener -Name "listener01" -Protocol Http -FrontendIPConfiguration $fipconfig01 -FrontendPort $fp01

    配置后端池的 URL 规则路径

    $imagePathRule = New-AzureRmApplicationGatewayPathRuleConfig -Name "pathrule1" -Paths "/image/*" -BackendAddressPool $pool1 -BackendHttpSettings $poolSetting01

    $videoPathRule = New-AzureRmApplicationGatewayPathRuleConfig -Name "pathrule2" -Paths "/video/*" -BackendAddressPool $pool2 -BackendHttpSettings $poolSetting02

    配置默认的后端池,如果路径不符合任何预定义的路径规则,规则路径映射到默认后端池

    $urlPathMap = New-AzureRmApplicationGatewayUrlPathMapConfig -Name "urlpathmap" -PathRules $videoPathRule, $imagePathRule -DefaultBackendAddressPool $pool1 -DefaultBackendHttpSettings $poolSetting02

    创建规则设置

    $rule01 = New-AzureRmApplicationGatewayRequestRoutingRule -Name "rule1" -RuleType PathBasedRouting -HttpListener $listener -UrlPathMap $urlPathMap

    配置实例数目和应用程序网关的大小

    $sku = New-AzureRmApplicationGatewaySku -Name "Standard_Small" -Tier Standard -Capacity 2

     

     

    创建应用程序网关

    $appgw = New-AzureRmApplicationGateway -Name appgwtest -ResourceGroupName AppgwRG -Location "China East" -BackendAddressPools $pool1,$pool2 -BackendHttpSettingsCollection $poolSetting01, $poolSetting02 -FrontendIpConfigurations $fipconfig01 -GatewayIpConfigurations $gipconfig -FrontendPorts $fp01 -HttpListeners $listener -UrlPathMaps $urlPathMap -RequestRoutingRules $rule01 -Sku $sku

     

     

     

    获取应用程序网关 DNS 名称

    Get-AzureRmPublicIpAddress -ResourceGroupName Appgw-RG -Name publicIP01

     

    测试访问

    /image会路由到Image01或者Image02

    /video会路由到Video01或者Video02

  • 相关阅读:
    通过SQL Server 2008数据库复制实现数据库同步备份
    SQL Server进制
    Server2008+SQL2008 日志读取代理器未运行 进程无法在“WINXXX”上执行“sp_replcmds”
    swing中使用皮肤包
    JTextArea的自动定位最后一行
    JFrame如何设置背景图片
    swing中单击回车相当于点击登录
    execute、executeUpdate、executeQuery三者的区别(及返回值)
    JTable设置透明
    在eclipse中导入android项目
  • 原文地址:https://www.cnblogs.com/rampb/p/6542512.html
Copyright © 2011-2022 走看看