缓存服务器配置及维护,03-Web缓存策略配置

1Web缓存策略

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

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

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

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

0f60a7d70e14323b615b7d2fd69f197c.png

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

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

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

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

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

1.2  Web缓存策略与硬件适配关系

本特性的支持情况与设备型号有关,请以设备的实际情况为准。

设备型号

业务板类型

说明

M9006

M9010

M9014

Blade IV防火墙业务板

支持

Blade V防火墙业务板

支持

NAT业务板

支持

应用交付业务板

支持

异常流量清洗业务板

不支持

M9010-GM

加密业务板

支持

M9016-V

Blade V防火墙业务板

支持

M9008-S

M9012-S

Blade IV防火墙业务板

支持

应用交付业务板

支持

入侵防御业务板

支持

视频网关业务板

支持

异常流量清洗业务板

不支持

M9008-S-6GW

IPv6业务板

支持

M9008-S-V

Blade IV防火墙业务板

支持

M9000-AI-E8

Blade V防火墙业务板

支持

应用交付业务板

支持

M9000-AI-E16

Blade V防火墙业务板

支持

1.3  配置限制和指导

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

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

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

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

1.5  创建Web缓存策略

(1)     进入系统视图。

system-view

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

cache-policycache-policy-name type http

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

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

1. 功能简介

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

2. 配置步骤

(1)     进入系统视图。

system-view

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

cache-policycache-policy-name[ type http

]

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

match [ match-id ] uriuri

1. 功能简介

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

2. 配置限制和指导

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

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

3. 配置步骤

(1)     进入系统视图。

system-view

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

cache-policycache-policy-name[ type http

]

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

aging-timetime-value

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

1. 功能简介

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

2. 配置步骤

(1)     进入系统视图。

system-view

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

cache-policycache-policy-name[ type http

]

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

sizesize-value

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

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

1. 功能简介

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

2. 配置步骤

(1)     进入系统视图。

system-view

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

cache-policycache-policy-name[ type http

]

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

file-max-sizefile-size

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

1.10  Web缓存策略显示和维护

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

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

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

显示Web缓存策略的信息

display cache-policy [namecache-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.11  Web缓存策略典型配置举例

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

2. 组网图

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

58a1fab1ca701df9896fa33918c5b843.png

(1)     配置接口IP地址。

system-view

[Device]interfacegigabitethernet 1/0/1

[Device-GigabitEthernet1/0/1]ip address 10.1.1.1 24

[Device-GigabitEthernet1/0/1]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缓存策略的统计信息。

display cache-policy statistics

Slot 2:

Cache policy: cp1

Match requests:0

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

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

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

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缓存策略的信息。

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缓存策略的统计信息。

display cache-policy statistics

Slot 2:

Cache policy: cp1

Match requests:1

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

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

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

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缓存策略功能生效。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值