As shown in Figure 1, configure Layer 7 server load balancing to load balance HTTP services between the two servers. Configure a Web cache policy to cache web pages, saving bandwidth and reducing workload of the servers.
This configuration example was created and verified on R9071 of the M9000-AI-E8 device.
1. Assign an IP address to Ten-GigabitEthernet 1/1/1/1.
<Device> system-view
[Device] interface ten-gigabitethernet 1/1/1/1
[Device-Ten-gigabitethernet1/1/1/1] ip address 10.1.1.1 24
[Device-Ten-gigabitethernet1/1/1/1] quit
2. Configure a Web cache policy:
# Create a Web cache policy named cp1 and enter its view.
[Device] cache-policy cp1 type http
# Configure a URI match rule to match URIs with index.
[Device-cp-http-cp1] match 1 uri index
[Device-cp-http-cp1] quit
3. Configure Layer 7 server load balancing:
# Create a real server named rsa, specify its IPv4 address as 192.168.1.1, and add it to server farm sf.
[Device] real-server rsa
[Device-rserver-rsa] ip address 192.168.1.1
[Device-rserver-rsa] server-farm sf
[Device-rserver-rsa] quit
# Create a real server named rsb, specify its IPv4 address as 192.168.1.2, and add it to server farm sf.
[Device] real-server rsb
[Device-rserver-rsb] ip address 192.168.1.2
[Device-rserver-rsb] server-farm sf
[Device-rserver-rsb] quit
# Create a SNAT address pool named sp1, and add address 192.168.1.166 to the pool.
[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
# Create the server farm sf, and specify SNAT address pool sp1 for it.
[Device] server-farm sf
[Device-sfarm-sf] snat-pool sp1
[Device-sfarm-sf] quit
# Create an HTTP virtual server named vs1 and specify its VSIP as 10.1.1.1. Specify the default primary server farm sf, specify Web cache policy cp1, and enable the virtual server.
[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
# After a client sends an HTTP request with URI /index.php, display Web cache policy information.
[Device] display cache-policy
Policy name: cp1
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
# Display statistics for the Web cache policy.
<Device> display cache-policy statistics
Slot 2:
Cache policy: cp1
Matching requests: 0
# Display statistics for the virtual server.
<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
# Display statistics for the real server.
<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
The output shows that no matching URI is found and a cached file is generated.
# After a client sends another HTTP request with the same URI, display Web cache policy information.
[Device] display cache-policy
Policy name: cp1
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
# Display statistics for the Web cache policy.
<Device> display cache-policy statistics
Slot 2:
Cache policy: cp1
Matching requests: 1
# Display statistics for the virtual server.
<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
# Display statistics for the real server.
<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
The output shows that the Web cache policy was hit, the hit count incremented from 0 to 1, and the number of sent responses on the real server did not change (the request is serviced locally).
#
interface Ten-gigabitethernet1/1/1/1
ip address 10.1.1.1 255.255.255.0
#
cache-policy cp1 type http
match 1 uri index
#
real-server rsa
ip address 192.168.1.1
server-farm sf
#
real-server rsb
ip address 192.168.1.2
server-farm sf
#
loadbalance snat-pool sp1
ip range start 192.168.1.166 end 192.168.1.166
#
server-farm sf
snat-pool sp1
#
virtual-server vs1 type http
virtual ip address 10.1.1.1
default server-farm sf
lb-cache-policy cp1
service enable