七層負載(Application Gateway)+四層負載(LB)

來源:互聯網
上載者:User

標籤:ports   location   table   stand   ini   mic   gateway   技術   lsp   

 

上次有個電商客戶需要搭建如架構。

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

 

七層負載(Application Gateway)+四層負載(LB)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.