• 产品与解决方案
  • 行业解决方案
  • 服务
  • 支持
  • 合作伙伴
  • 新华三人才研学中心
  • 关于我们

02-负载均衡配置指导

目录

03-Web缓存策略配置

本章节下载 03-Web缓存策略配置  (221.14 KB)

docurl=/cn/Service/Document_Software/Document_Center/IP_Security/YYAQWG_V7/H3C_vLB/Configure/Operation_Manual/H3C_vLB_CG(V7)(R1171)/02/202305/1841796_30005_0.htm

03-Web缓存策略配置


1 Web缓存策略

1.1  Web缓存策略简介

采用Web缓存策略可以将用户通过HTTP协议访问过的Web页面以文件形式缓存在设备本地,若用户在缓存文件的老化时间内访问相同URI,则设备可以直接从本地响应。从而减少设备到服务器的访问流量、降低传输成本、缓解目的端服务器压力,同时提高了用户访问网站的速度及响应时间,增强了用户体验。

其他功能模块(如负载均衡的虚服务器)可通过调用Web缓存策略实现对Web页面的缓存。

Web缓存策略的工作原理如图1-1所示:

图1-1 Web缓存策略工作原理示意图

 

(1)     当用户主机(Host)发送给Web服务器(Server)的HTTP GET请求报文到达设备(Device)后,Web缓存策略获取报文的URI,依据URI在Web Cache工作路径下的各个缓存文件中进行查找:

¡     若找到匹配项,则依据缓存内容构建响应报文,并直接返回给主机。Web缓存策略处理结束。

¡     若未找到匹配项,则继续进行下面的处理。

(2)     设备重新封装HTTP GET请求报文发送给Web服务器。

(3)     当设备收到Web服务器的响应后,检查其请求报文中是否包含允许缓存的URI。若包含,会将响应报文的数据部分保存到工作路径下的缓存文件中,并将缓存内容构造成响应报文发送给主机。若不包含,则直接构造成响应报文发送给主机。

1.2  配置限制和指导

目前Web缓存策略功能仅支持基于HTTP协议的Web界面缓存功能,暂不支持基于其他协议的数据缓存功能。

1.3  Web缓存策略配置任务简介

Web缓存策略的配置任务如下:

(1)     创建Web缓存策略

(2)     创建HTTP URI类型的缓存匹配规则

(3)     (可选)配置缓存参数

¡     配置缓存文件的老化时间

¡     配置缓存文件占用的内存空间大小

¡     配置单个缓存文件占用的内存空间大小

1.4  创建Web缓存策略

(1)     进入系统视图。

system-view

(2)     创建Web缓存策略,并进入Web缓存策略视图。

cache-policy cache-policy-name type http

创建Web缓存策略时必须为其指定类型;而在进入已创建的Web缓存策略视图时可以不指定类型,若要指定类型,则必须与创建时的类型一致。

1.5  创建HTTP URI类型的缓存匹配规则

1. 功能简介

创建HTTP URI类型的缓存匹配规则后,设备会对HTTP请求报文中的URI进行检查,若与配置的URI一致,则缓存其响应报文。若未配置缓存匹配规则,则不缓存任何HTTP报文。

2. 配置步骤

(1)     进入系统视图。

system-view

(2)     进入Web缓存策略视图。

cache-policy cache-policy-name[ type http ]

(3)     创建HTTP URI类型的缓存匹配规则。

match [ match-id ] uri uri

1.6  配置缓存文件的老化时间

1. 功能简介

当达到老化时间时,如果没有用户请求某个URI,则该URI对应的缓存文件将会被删除。

2. 配置限制和指导

设备收到相同HTTP请求时不会刷新已存在缓存文件的老化时间。

修改缓存文件的老化时间仅对新生成的缓存文件生效,已存在的缓存文件不受影响。

3. 配置步骤

(1)     进入系统视图。

system-view

(2)     进入Web缓存策略视图。

cache-policy cache-policy-name[ type http ]

(3)     配置缓存文件的老化时间。

aging-time time-value

缺省情况下,缓存文件的老化时间为60分钟。

1.7  配置缓存文件占用的内存空间大小

1. 功能简介

当缓存文件占用的内存空间总大小达到配置的内存空间大小时,若有新的数据进行缓存,会从最旧的缓存文件开始删除直到剩余空间足够保存新的缓存文件为止。

2. 配置步骤

(1)     进入系统视图。

system-view

(2)     进入Web缓存策略视图。

cache-policy cache-policy-name[ type http ]

(3)     配置缓存文件占用的内存空间大小。

size size-value

缺省情况下,缓存文件占用的内存空间大小为64MB。

1.8  配置单个缓存文件占用的内存空间大小

1. 功能简介

当单个缓存文件占用的内存空间超出配置的单个缓存文件占用的内存空间大小时,不对其缓存。

2. 配置步骤

(1)     进入系统视图。

system-view

(2)     进入Web缓存策略视图。

cache-policy cache-policy-name[ type http ]

(3)     配置单个缓存文件占用的内存空间大小。

file-max-size file-size

缺省情况下,单个缓存文件占用的内存空间大小为2048KB。

1.9  Web缓存策略显示和维护

在完成上述配置后,在任意视图下执行display命令可以显示配置后Web缓存策略的运行情况,通过查看显示信息验证配置的效果。

在用户视图下执行reset命令可以清除Web缓存策略的统计信息。

表1-1 Web缓存策略显示和维护

配置

命令

显示Web缓存策略的信息

display cache-policy [ name cache-policy-name ]

显示Web缓存策略的统计信息

display cache-policy statistics [ name cache-policy-name ]

清除Web缓存策略缓存的文件

reset cache-policy [ cache-policy-name ]

清除Web缓存策略的统计信息

reset cache-policy statistics [ cache-policy-name ]

 

1.10  Web缓存策略典型配置举例

1.10.1  七层服务器负载均衡调用Web缓存策略配置举例

1. 组网需求

图1-2所示,通过配置七层服务器负载均衡,使两台服务器联合提供HTTP服务,并通过配置Web缓存策略功能,达到缓存页面、节省带宽、缓解服务器压力的目的。

2. 组网图

图1-2 配置Web缓存策略组网图

3. 配置步骤

(1)     配置接口IP地址。

<Device> system-view

[Device] interface gigabitethernet 1/0

[Device-GigabitEthernet1/0] ip address 10.1.1.1 24

[Device-GigabitEthernet1/0] quit

(2)     配置Web缓存策略。

# 创建HTTP类型的Web缓存策略cp1,并进入Web缓存策略视图。

[Device] cache-policy cp1 type http

# 创建HTTP URI类型的缓存匹配规则为匹配index

[Device-cp-http-cp1] match 1 uri index

[Device-cp-http-cp1] quit

(3)     配置七层服务器负载均衡功能。

# 创建实服务器rsa,配置其IPv4地址为192.168.1.1,并加入实服务组sf。

[Device] real-server rsa

[Device-rserver-rsa] ip address 192.168.1.1

[Device-rserver-rsa] server-farm sf

[Device-rserver-rsa] quit

# 创建实服务器rsb,配置其IPv4地址为192.168.1.2,并加入实服务组sf。

[Device] real-server rsb

[Device-rserver-rsb] ip address 192.168.1.2

[Device-rserver-rsb] server-farm sf

[Device-rserver-rsb] quit

# 创建SNAT地址池sp1,配置其IP地址范围为192.168.1.166~192.168.1.166。

[Device] loadbalance snat-pool sp1

[Device-lbsnat-pool-sp1] ip range start 192.168.1.166 end 192.168.1.166

[Device-lbsnat-pool-sp1] quit

# 创建实服务组sf,并指定实服务组引用的SNAT地址池为sp1。

[Device] server-farm sf

[Device-sfarm-sf] snat-pool sp1

[Device-sfarm-sf] quit

# 创建HTTP类型的虚服务器vs1,配置其VSIP为10.1.1.1,指定其缺省主用实服务组为sf,引用的Web缓存策略为cp1,并开启此虚服务器。

[Device] virtual-server vs1 type http

[Device-vs-http-vs1] virtual ip address 10.1.1.1

[Device-vs-http-vs1] default server-farm sf

[Device-vs-http-vs1] lb-cache-policy cp1

[Device-vs-http-vs1] service enable

[Device-vs-http-vs1] quit

# 有关服务器负载均衡的更多配置,请参见“负载均衡配置指导”中的“服务器负载均衡”。

4. 验证配置

# 客户端第一次发送HTTP请求,携带URI为/index.php,显示Web缓存策略的信息。

[Device] display cache-policy

Policy name: cp1

  Description:

  Type: HTTP

  State: Enabled

  Max size: 64 MB

  Single file size: 2048 KB

  Aging time: 60 min

  Match rule:

    match 1 uri index

  Slot 1:

  File list:

    File name           Type        Encoding    Language    Timeout   Matches  FileSize

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

  10.1.1.1/index.php applicatio                          59        0        1200

                        n/octet-st

                        ream

  Total files: 1

 

# 显示Web缓存策略的统计信息。

<Device> display cache-policy statistics

Slot 2:

Cache policy: cp1

  Match requests: 0

 

# 显示虚服务器的统计信息。

<Device> display virtual-server statistics

Slot 2:

Virtual server: vs1

  Total connections: 1

  Active connections: 0

  Max connections: 1

  Connections per second: 0

  Max connections per second: 1

  Client input: 1372 bytes

  Client output: 39937 bytes

  Throughput: 0 bytes/s

  Inbound throughput: 0 bytes/s

  Outbound throughput: 0 bytes/s

  Max throughput: 41309 bytes/s

  Max inbound throughput: 1372 bytes/s

  Max outbound throughput: 39937 bytes/s

  Received packets: 31

  Sent packets: 54

  Dropped packets: 0

  Received requests: 1

  Dropped requests: 0

  Sent responses: 1

  Dropped responses: 0

 

# 显示实服务器的统计信息。

<Device> display real-server statistics

Slot 2:

Real server: rs1

  Total connections: 1

  Active connections: 0

  Max connections: 1

  Connections per second: 0

  Max connections per second: 1

  Server input: 1740 bytes

  Server output: 40633 bytes

  Throughput: 0 bytes/s

  Inbound throughput: 0 bytes/s

  Outbound throughput: 0 bytes/s

  Max throughput: 42373 bytes/s

  Max inbound throughput: 1740 bytes/s

  Max outbound throughput: 40633 bytes/s

  Received packets: 31

  Sent packets: 55

  Dropped packets: 0

  Received requests: 1

  Dropped requests: 0

  Sent responses: 1

  Dropped responses: 0

  Connection failures: 0

  Busy state: Normal

 

第一次发送请求时无缓存,实服务器发送一次应答,首次生成缓存文件,匹配次数为零。

# 客户端第二次发送HTTP请求,携带相同URI为/index.php,显示Web缓存策略的信息。

<Device> display cache-policy

[Device] display cache-policy

Policy name: cp1

  Description:

  Type: HTTP

  State: Enabled

  Max size: 64 MB

  Single file size: 2048 KB

  Aging time: 60 min

  Match rule:

    match 1 uri index

  Slot 1:

  File list:

    File name           Type        Encoding    Language    Timeout   Matches  FileSize

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

    10.1.1.1/index.php  applicatio                          59        1        1200

                        n/octet-st

                        ream

  Total files: 1

 

# 显示Web缓存策略的统计信息。

<Device> display cache-policy statistics

Slot 2:

Cache policy: cp1

  Match requests: 1

 

# 显示虚服务器的统计信息。

<Device> display virtual-server statistics

Slot 2:

Virtual server: vs1

  Total connections: 2

  Active connections: 0

  Max connections: 1

  Connections per second: 0

  Max connections per second: 1

  Client input: 2464 bytes

  Client output: 79506 bytes

  Throughput: 0 bytes/s

  Inbound throughput: 0 bytes/s

  Outbound throughput: 0 bytes/s

  Max throughput: 41309 bytes/s

  Max inbound throughput: 1372 bytes/s

  Max outbound throughput: 39937 bytes/s

  Received packets: 55

  Sent packets: 94

  Dropped packets: 0

  Received requests: 2

  Dropped requests: 0

  Sent responses: 2

  Dropped responses: 0

 

# 显示实服务器的统计信息。

<Device> display real-server statistics

Slot 2:

Real server: rs1

  Total connections: 1

  Active connections: 0

  Max connections: 1

  Connections per second: 0

  Max connections per second: 1

  Server input: 1740 bytes

  Server output: 40633 bytes

  Throughput: 0 bytes/s

  Inbound throughput: 0 bytes/s

  Outbound throughput: 0 bytes/s

  Max throughput: 42373 bytes/s

  Max inbound throughput: 1740 bytes/s

  Max outbound throughput: 40633 bytes/s

  Received packets: 31

  Sent packets: 55

  Dropped packets: 0

  Received requests: 1

  Dropped requests: 0

  Sent responses: 1

  Dropped responses: 0

  Connection failures: 0

  Busy state: Normal

 

第二次发送请求时已有缓存文件,命中Web缓存策略,匹配次数加一,实服务器应答计数不变,说明实服务器到Device无流量经过,Web缓存策略功能生效。

不同款型规格的资料略有差异, 详细信息请向具体销售和400咨询。H3C保留在没有任何通知或提示的情况下对资料内容进行修改的权利!

新华三官网
联系我们