CLI举例:配置HTTP服务器的负载均衡

CLI举例:配置HTTP服务器的负载均衡

本举例介绍了如何配置HTTP服务器的负载均衡。

组网需求

图1所示,企业有三台Web服务器Server1、Server2和Server3,且这三台服务器的硬件性能顺次降低,Server1性能是Server2的两倍、Server2性能是Server3的两倍。通过配置负载均衡,让这三台服务器联合对外提供HTTP服务,且三台服务器承载业务的多少与服务器硬件性能的高低匹配。通过配置健康检测实时监控这三台服务器是否可达。

图1 配置HTTP服务器的负载均衡组网图

配置思路
  1. 三台服务器的性能不同,要根据性能来负载均衡,所以负载均衡算法可以选择“加权最小连接算法”。Server1性能是Server2的两倍、Server2性能是Server3的两倍,所以三台服务器的权值比为4:2:1。
  2. 为了监控三台服务器是否可达,需要在FW上配置健康检查。本举例中健康检查的协议类型配置为ICMP,您也可以配置为HTTP。FW要发送健康检查报文,需要配置local到服务器所在安全区域(dmz)的安全策略。
  3. 客户端可能需要与服务器建立多条连接才能完成一项操作,为此需要在FW上配置会话保持,让同一个客户端的连接分配到同一台服务器上。服务器提供的是HTTP服务,所以会话保持方法可以配置成HTTP Cookie。

操作步骤
  1. 配置各个接口的IP地址,并将接口加入相应的安全区域。

    <FW> system-view
    [FW] interface GigabitEthernet 1/0/1
    [FW-GigabitEthernet1/0/1] ip address 1.1.1.1 24
    [FW-GigabitEthernet1/0/1] quit
    [FW] interface GigabitEthernet 1/0/2
    [FW-GigabitEthernet1/0/2] ip address 192.168.1.254 24
    [FW-GigabitEthernet1/0/2] quit
    [FW] firewall zone untrust
    [FW-zone-untrust] add interface GigabitEthernet 1/0/1
    [FW-zone-untrust] quit
    [FW] firewall zone dmz
    [FW-zone-dmz] add interface GigabitEthernet 1/0/2
    [FW-zone-dmz] quit

  2. 配置安全策略。

    # 配置untrust到dmz的安全策略,允许Internet用户访问内网的Web服务器。策略的目的地址应该配置虚拟服务器的IP地址。
    
    [FW] security-policy
    [FW-policy-security] rule name policy1
    [FW-policy-security-rule-policy1] source-zone untrust
    [FW-policy-security-rule-policy1] destination-zone dmz
    [FW-policy-security-rule-policy1] destination-address 1.1.1.10 24
    [FW-policy-security-rule-policy1] action permit
    [FW-policy-security-rule-policy1] quit
    [FW-policy-security] quit
    # 配置local到dmz的安全策略,允许FW向实服务器发送健康探测报文。
    
    [FW] security-policy
    [FW-policy-security] rule name policy2
    [FW-policy-security-rule-policy2] source-zone local
    [FW-policy-security-rule-policy2] destination-zone dmz
    [FW-policy-security-rule-policy2] destination-address range 192.168.1.1 192.168.1.3
    [FW-policy-security-rule-policy2] action permit
    [FW-policy-security-rule-policy2] quit
    [FW-policy-security] quit

  3. 配置服务器负载均衡功能和健康检查功能。

    # 开启服务器负载均衡功能。
    
    [FW] slb enable
    # 配置会话保持。
    
    [FW] slb
    [FW-slb] persistence 0 Session
    [FW-slb-persistence-1] type cookie-insert aging-time 600
    [FW-slb-persistence-1] quit
    # 配置负载均衡算法。
    
    [FW-slb] group 0 Rserver
    [FW-slb-group-0] metric weight-least-connection
    # 配置实服务器Server1、Server2、Server3,服务器的权重值依次为4、2、1。
    
    [FW-slb-group-0] rserver 0 rip 192.168.1.1 port 8080 weight 4 description server1
    [FW-slb-group-0] rserver 1 rip 192.168.1.2 port 8080 weight 2 description server2
    [FW-slb-group-0] rserver 2 rip 192.168.1.3 port 8080 weight 1 description server3
    # 配置健康检查功能。
    
    [FW-slb-group-0] health-check type icmp tx-interval 5 times 3
    [FW-slb-group-0] quit
    # 配置虚拟服务器的协议类型。
    
    [FW-slb] vserver 0 vs-http-1.1.1.10
    [FW-slb-vserver-0] protocol http
    # 配置虚拟服务器的IP地址和端口号。
    
    [FW-slb-vserver-0] vip 0 1.1.1.10
    [FW-slb-vserver-0] vport 80
    # 配置会话保持。
    
    [FW-slb-vserver-0] persistence Session
    # 关联虚拟服务器和实服务器组。
    
    [FW-slb-vserver-0] group Rserver
    [FW-slb-vserver-0] quit

结果验证
  1. 在FW上查看静态Server-map表,存在相应表项证明服务器负载均衡功能配置成功。
    
    [FW] display firewall server-map static
     Current Total Server-map : 1
     Type: SLB,  ANY -> 1.1.1.10:80[vs-http-1.1.1.10/0],  Zone:---,  protocol:tcp              
     Vpn: public -> public
    Client访问http://1.1.1.10可以连接到HTTP服务器。
    
    当服务器请求流量较大时,经过一段时间后,在FW上查看虚拟服务器和实服务器的运行情况,可见3个实服务器的总会话数、并发会话数比约为4:2:1。
    
    [FW] display slb vserver vs-http-1.1.1.10 verbose
    Virtual Server Information(Total 1)
    -------------------------------------------------------------------------------------------
      Virtual Server Name      : vs-http-1.1.1.10
      Virtual Server ID        : 0
      Virtual Server IP        : 1.1.1.10
      Protocol                 : http
      Virtual Server Port      : 80
      Http X-forward Enable    : Disable
      Virtual Server Max-conn  : -
      Persistence Name/ID(Type): Session/0(cookie-insert)
      Group Name               : vs-http-1.1.1.10
      Group ID                 : 0
      Virtual Server Statistics
       Current Connection       :215
       Total connection         :400
       Total Flow               :12478.0_B
    ---------------------------------------------
    [FW] display slb group Rserver verbose
    Group Information(Total 1)                                                      
    --------------------------------------------------------------------------------
    ----------------------------                                                    
      Group Name               : Rserver                                   
      Group ID                 : 0                                                  
      Metric                   : weight-least-connection                            
      Source-nat Type          : NA                                                 
      Health Check Type        : icmp                                               
      Real Server Number       : 3                                                  
        RserverID  IP Address       Weight  Max-connection  Status               Rat
    io  TotalSession  CurSession                                                    
        0          192.168.1.1      4       -               Admin-Active         57.
    85%            4112        126                                                  
        1          192.168.1.2      2       -               Admin-Active         28.
    11%            1998        63                                                    
        2          192.168.1.3      1       -               Admin-Active         14.
    04%            998         31                                                    
    --------------------------------------------------------------------------------
    ---------------------------- 

配置脚本
interface GigabitEthernet 1/0/1
 ip address 1.1.1.1 24
#
interface GigabitEthernet 1/0/2
 ip address 192.168.1.254 24
#
firewall zone untrust
 add interface GigabitEthernet 1/0/1
#
firewall zone dmz
 add interface GigabitEthernet 1/0/2
#
security-policy
 rule name policy1
  source-zone untrust
  destination-zone dmz
  destination-address 1.1.1.10 24
  action permit
 rule name policy2
  source-zone local
  destination-zone dmz
  destination-address range 192.168.1.1 192.168.1.3
  action permit
#
slb enable
#
slb
 group 0 Rserver
  metric weight-least-connection
  health-check type icmp tx-interval 5 times 3
  rserver 0 rip 192.168.1.1 port 8080 weight 4 description server1
  rserver 1 rip 192.168.1.2 port 8080 weight 2 description server2
  rserver 2 rip 192.168.1.3 port 8080 weight 1 description server3
 persistence 0 Session
  type cookie-insert aging-time 600
 vserver 0 vs-http-1.1.1.10
  vip 0 1.1.1.10
  protocol http
  persistence Session
  vport 80
  group Rserver

相关推荐

  1. AWS Elastic Beanstalk通过应用负载均衡配置https

    2024-05-10 16:04:03       44 阅读
  2. # 如何在Nginx中配置服务器负载均衡(SLB)

    2024-05-10 16:04:03       60 阅读
  3. haproxy配置安装,实现web服务器负载均衡

    2024-05-10 16:04:03       33 阅读
  4. Nginx 负载均衡配置

    2024-05-10 16:04:03       36 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-10 16:04:03       99 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-10 16:04:03       107 阅读
  3. 在Django里面运行非项目文件

    2024-05-10 16:04:03       90 阅读
  4. Python语言-面向对象

    2024-05-10 16:04:03       98 阅读

热门阅读

  1. Vue10 组件通信-插槽

    2024-05-10 16:04:03       35 阅读
  2. C++单例模式(三种方式)

    2024-05-10 16:04:03       41 阅读
  3. python列表生成式学习

    2024-05-10 16:04:03       32 阅读
  4. 仿真相关知识积累

    2024-05-10 16:04:03       34 阅读
  5. 国内不同领域对应的AI简谈

    2024-05-10 16:04:03       34 阅读
  6. Python 基础入门

    2024-05-10 16:04:03       33 阅读
  7. [GStreamer][LearnGst] setup.sh 脚本

    2024-05-10 16:04:03       35 阅读
  8. 【论文合集 2】- 基于忆阻器的存内计算

    2024-05-10 16:04:03       29 阅读
  9. MySql开源闪回工具MyFlash —— 筑梦之路

    2024-05-10 16:04:03       37 阅读
  10. 少的缓存穿透是缓存击穿,大量的是缓存雪崩

    2024-05-10 16:04:03       31 阅读