Azure的SLB和ILB是最常用的4层负载均衡工具。但有些场景是7层的负载均衡,SLB和ILB就无能为力了。

Azure上已经推出了APP Gateway的服务,就是7层负载均衡的负载均衡器。

如上图,APP Gateway实现用户HTTPS网站的SSL Offload,还可以实现多个VM的负载均衡。而且可以实现Cookie Affinity功能,这也是7层负载均衡的一种功能。

通过App Gateway、SLB、Traffic Manager综合使用,可以实现对应用系统的高扩展性:

可以通过智能DNS选择北部的Azure的数据中心还是东部的Azure的数据中心,再通过4层的SLB把流量分担到多个Application Gateway上,Application Gateway再根据策略,把流量分担到各个虚拟机上。

Application Gateway的部署基于VNet,但其负载均衡的节点可以是非本VNet的虚拟机。如下图:

其负载均衡的节点除本VNet的虚拟机外,可以是其他的Cloud Service,其他VNet内的虚拟机(需要VPN打通),甚至外部的虚拟机都可以成为Application Gateway的负载均衡节点。

App Gateway一共有3中型号:

  1. Small – Dev/Test使用,不建议部署在生产环境
  2. Medium – 可以支持150Mbps的SSL流量
  3. Large – 可以支持200Mbps的SSL流量

具体配置命令:

  1. 创建Application Gateway

    New-AzureApplicationGateway -Name hwappgw -VnetName hwvnet -Subnets Subnet-1 -InstanceCount 2 -GatewaySize Medium

    New-AzureApplicationGateway -Name hwappgw02 -VnetName hwvnet -Subnets Subnet-1 -InstanceCount 2 -GatewaySize Medium

    上面的配置中配置了两个APP Gateway。

    第一个会把其对外的地址设定为Subnet-1的地址,将采用ILB的四层负载均衡;第二个会让其自动获得公网的VIP地址,将采用SLB的四层负载均衡。

  2. 设置Application Gateway的配置文件

    首先编辑Application Gateway的配置文件,a.xml将采用ILB的方式实现负载均衡,c.xml将采用SLB的方式实现负载均衡:

a.xml

<?xml version="1.0" encoding="utf-8"?>

<ApplicationGatewayConfiguration xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">

<FrontendIPConfigurations>

<FrontendIPConfiguration>

<Name>fip1</Name>

<Type>Private</Type>

<StaticIPAddress>10.1.1.140</StaticIPAddress>

</FrontendIPConfiguration>

</FrontendIPConfigurations>

<FrontendPorts>

<FrontendPort>

<Name>FrontendPort1</Name>

<Port>80</Port>

</FrontendPort>

</FrontendPorts>

<BackendAddressPools>

<BackendAddressPool>

<Name>BackendPool1</Name>

<IPAddresses>

<IPAddress>10.1.1.151</IPAddress>

<IPAddress>10.1.1.152</IPAddress>

</IPAddresses>

</BackendAddressPool>

</BackendAddressPools>

<BackendHttpSettingsList>

<BackendHttpSettings>

<Name>BackendSetting1</Name>

<Port>80</Port>

<Protocol>Http</Protocol>

<CookieBasedAffinity>Enabled</CookieBasedAffinity>

</BackendHttpSettings>

</BackendHttpSettingsList>

<HttpListeners>

<HttpListener>

<Name>HTTPListener1</Name>

<FrontendIP>fip1</FrontendIP>

<FrontendPort>FrontendPort1</FrontendPort>

<Protocol>Http</Protocol>

</HttpListener>

</HttpListeners>

<HttpLoadBalancingRules>

<HttpLoadBalancingRule>

<Name>HttpLBRule1</Name>

<Type>basic</Type>

<BackendHttpSettings>BackendSetting1</BackendHttpSettings>

<Listener>HTTPListener1</Listener>

<BackendAddressPool>BackendPool1</BackendAddressPool>

</HttpLoadBalancingRule>

</HttpLoadBalancingRules>

</ApplicationGatewayConfiguration>

可以注意到其前端的IP地址是10.1.1.140。

c.xml

<?xml version="1.0" encoding="utf-8"?>

<ApplicationGatewayConfiguration xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">

<FrontendPorts>

<FrontendPort>

<Name>FrontendPort1</Name>

<Port>80</Port>

</FrontendPort>

</FrontendPorts>

<BackendAddressPools>

<BackendAddressPool>

<Name>BackendPool1</Name>

<IPAddresses>

<IPAddress>10.1.1.151</IPAddress>

<IPAddress>10.1.1.152</IPAddress>

</IPAddresses>

</BackendAddressPool>

</BackendAddressPools>

<BackendHttpSettingsList>

<BackendHttpSettings>

<Name>BackendSetting1</Name>

<Port>80</Port>

<Protocol>Http</Protocol>

<CookieBasedAffinity>Enabled</CookieBasedAffinity>

</BackendHttpSettings>

</BackendHttpSettingsList>

<HttpListeners>

<HttpListener>

<Name>HTTPListener1</Name>

<FrontendPort>FrontendPort1</FrontendPort>

<Protocol>Http</Protocol>

</HttpListener>

</HttpListeners>

<HttpLoadBalancingRules>

<HttpLoadBalancingRule>

<Name>HttpLBRule1</Name>

<Type>basic</Type>

<BackendHttpSettings>BackendSetting1</BackendHttpSettings>

<Listener>HTTPListener1</Listener>

<BackendAddressPool>BackendPool1</BackendAddressPool>

</HttpLoadBalancingRule>

</HttpLoadBalancingRules>

</ApplicationGatewayConfiguration>

这个配置中的前端IP不进行设置,讲自动获得VIP地址。

  1. 设置Application Gateway的配置

    Set-AzureApplicationGatewayConfig -Name hwappgw -ConfigFile D:\a.xml

    Set-AzureApplicationGatewayConfig -Name hwappgw02 -ConfigFile D:\c.xml

  2. 启动Application Gateway

    Start-AzureApplicationGateway -Name hwappgw

    Start-AzureApplicationGateway -Name hwappgw02

    这个过程将比较耗时,这一步需要大约20分钟的时间创建。这个过程中,Azure会在后台创建多台Application Gateway的VM,实现HA的配置。

  3. 获得Application Gateway的状态

    Get-AzureApplicationGateway

Name

hwappgw

Description

VnetName

hwvnet

Subnets

{Subnet-1}

InstanceCount

2

GatewaySize

Medium

State

Running

VirtualIPs

{10.1.1.140}

DnsName

Name

hwappgw02

Description

VnetName

hwvnet

Subnets

{Subnet-1}

InstanceCount

2

GatewaySize

Medium

State

Running

VirtualIPs

{42.159.241.87}

DnsName

70da9ed4-cf13-45a9-9fa3-c44f7e98e73a.chinacloudapp.cn

可以观察到,hwappgw的地址是一个内部地址,而hwappgw02的地址是一个公网地址,并有DNS的域名。

这时已经可以通过这个两个负载均衡的地址访问后台的服务了。Application Gateway会根据10.1.1.151和10.1.1.152两台虚拟机的状态进行负载均衡的流量转发。

  1. 上传SSL证书

    Add-AzureApplicationGatewaySslCertificate -Name hwappgw02 -CertificateName hengweicert -Password xxxx -CertificateFile D:\HengweiCert.pfx

    Name HTTP Status Code Operation ID Error

    ---- ---------------- ------------ -----

    Successful OK ae3d3289-618f-4da0-bf45-56ed2542d098

  2. 确认证书状态

    Get-AzureApplicationGatewaySslCertificate -Name hwappgw02

    Name     : hengweicert

    SubjectName     : CN=ClientCertificateHengwei

    Thumbprint     : 1336E8F9BB18A947AD79F0A2939411B0BC3D893B

    ThumbprintAlgo     : sha1RSA

    State         : Provisioned

  3. 更改hwappgw02的配置文件

    修改c.xml配置文件,修改协议为https、443端口,以及添加证书配置:

    <?xml version="1.0" encoding="utf-8"?>

    <ApplicationGatewayConfiguration xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">

    <FrontendPorts>

    <FrontendPort>

    <Name>FrontendPort1</Name>

    <Port>443</Port>

    </FrontendPort>

    </FrontendPorts>

    <BackendAddressPools>

    <BackendAddressPool>

    <Name>BackendPool1</Name>

    <IPAddresses>

    <IPAddress>10.1.1.151</IPAddress>

    <IPAddress>10.1.1.152</IPAddress>

    </IPAddresses>

    </BackendAddressPool>

    </BackendAddressPools>

    <BackendHttpSettingsList>

    <BackendHttpSettings>

    <Name>BackendSetting1</Name>

    <Port>80</Port>

    <Protocol>Http</Protocol>

    <CookieBasedAffinity>Enabled</CookieBasedAffinity>

    </BackendHttpSettings>

    </BackendHttpSettingsList>

    <HttpListeners>

    <HttpListener>

    <Name>HTTPListener1</Name>

    <FrontendPort>FrontendPort1</FrontendPort>

    <Protocol>Https</Protocol>

    <SslCert>hengweicert</SslCert>

    </HttpListener>

    </HttpListeners>

    <HttpLoadBalancingRules>

    <HttpLoadBalancingRule>

    <Name>HttpLBRule1</Name>

    <Type>basic</Type>

    <BackendHttpSettings>BackendSetting1</BackendHttpSettings>

    <Listener>HTTPListener1</Listener>

    <BackendAddressPool>BackendPool1</BackendAddressPool>

    </HttpLoadBalancingRule>

    </HttpLoadBalancingRules>

    </ApplicationGatewayConfiguration>

  4. 上传APP Gateway的设置

    Set-AzureApplicationGatewayConfig -Name hwappgw02 -ConfigFile D:\c.xml

    此时通过https访问这个网站,会提示证书不受信任(自签名证书)

点击继续后,出现网站主页面:

而此时虚拟机提供的只是HTTP服务,由application gateway做了SSL的加密发送给用户。

目前Application Gateway可以实现的功能主要是基于CookieAffinity的负载均衡和SSL的Offload。

将来还会出基于URL的HTTP路由策略。新功能出来后,再做更新!

转载于:https://www.cnblogs.com/hengwei/p/5052052.html

Azure上七层负载均衡APP Gateway相关推荐

  1. 七层负载均衡--Haproxy

    七层负载均衡--Haproxy 1 Haproxy的定义 2 七层负载均衡的概念 3 四层和七层负载均衡的对比 4 Haproxy的安装及部署 4.1 Haproxy实现负载均衡 4.2 建立监控 4 ...

  2. f5 会话保持 负载均衡_四层负载均衡和七层负载均衡区别在哪里?

    年后至今这段时间工作重心都在调整公司现有API Gateway的系统架构以及对现有技术栈选型.经过对主流互联网网关所实现各种方案的调研,我们在API Gateway前置一层接入层,接入层主要用于实现限 ...

  3. 四层和七层负载均衡的区别

    负载均衡设备也常被称为"四到七层交换机",那补充: 所谓四层就是基于IP+端口的负载均衡:七层就是基于URL等应用层信息的负载均衡:同理,还有基于MAC地址的二层负载均衡和基于IP ...

  4. 七层负载均衡 nginx

    七层负载均衡 简单解说: ============================================================== 一.集群的分类:(cluster) 1.高可用集 ...

  5. FastDFS蛋疼的集群和负载均衡(十五)之lvs四层+Nginx七层负载均衡

    ###Interesting things lvs+nginx的拓扑图 准备环境,基于上一篇[Diary Report 2018-1-3]关于FastDFS蛋疼的集群和负载均衡(十三)之LVS-DR环 ...

  6. 四层和七层负载均衡的区别介绍--转

    简单理解四层和七层负载均衡:①所谓四层就是基于IP+端口的负载均衡:七层就是基于URL等应用层信息的负载均衡:同理,还有基于MAC地址的二层负载均衡和基于IP地址的三层负载均衡. 换句换说,二层负载均 ...

  7. 四层负载均衡与七层负载均衡

    lvs+nginx的拓扑结构 四层负载均衡 四层的负载均衡就是基于IP+端口的负载均衡:在三层负载均衡的基础上,通过发布三层的IP地址(VIP),然后加四层的端口号,来决定哪些流量需要做负载均衡,对需 ...

  8. Nginx七层负载均衡配置

    Nginx七层负载均衡 Nginx要实现七层负载均衡需要用到proxy_pass代理模块配置.Nginx默认安装支持这个模块,我们不需要再做任何处理.Nginx的负载均衡是在Nginx的反向代理基础上 ...

  9. Web负载均衡学习笔记之四层和七层负载均衡的区别

    0x00 简介 简单理解四层和七层负载均衡: ① 所谓四层就是基于IP+端口的负载均衡:七层就是基于URL等应用层信息的负载均衡:同理,还有基于MAC地址的二层负载均衡和基于IP地址的三层负载均衡. ...

最新文章

  1. 5月第4周网络安全报告:应用程序漏洞占比达70.3%
  2. oracle 加全文索引,oracle全文索引的创建和使用
  3. unity5.x C# 获取屏幕宽度 设置不受重力影响
  4. 面对1.3 亿用户数据泄露,企业如何围绕核心数据构建安全管理体系?
  5. Java虚拟机(七)——本地方法接口与本地方法栈
  6. python是一种面向过程的编程语言_python协成与面向过程编程
  7. 多控制器之UIWindow
  8. 【渝粤题库】陕西师范大学201831 课程论 作业
  9. redis系列--深入哨兵集群
  10. 一台机器安装两个LINUX系统的操作与经验
  11. nexus4刷机 android6.0,谷歌nexus 5刷机工具
  12. 四足机器人关节锁死故障的容错问题
  13. XtraReport打印二维码
  14. 1. 数组:为什么数组要从0开始编号,而不是1开始呢?
  15. python提高图片分辨率_python 获取图片分辨率的方法
  16. 安装的计算机语言不受支持,win10提示安装程序包的语言不受系统支持解决方案...
  17. 【Python小游戏】俄罗斯方块
  18. 《秘密》卷一:秘密-吸引力法则
  19. thinkphp框架源码交易系统资源网站源码
  20. 有趣的马氏链及其平稳分布

热门文章

  1. c# 链接mongDB集群实战开发2
  2. C# ashx生成的验证码
  3. 使用 Navicat Premium12 创建报表
  4. java和jsp交互 structs_Struts与jsp+javabean+servlet区别
  5. go语言 html 5 gui,仅需简单 5 步,给你的 Golang 程序添加 GUI (使用 Electron )
  6. 系统学习深度学习(七)--主流深度学习开源框架对比
  7. java语言是那年_Java语言是在()年正式推出的_学小易找答案
  8. php的$符的作用,PHP引用符的用法举例
  9. java ArrayList扩容入门
  10. Windows核心编程_异型窗口