本文共 4841 字,大约阅读时间需要 16 分钟。
角色 | ip |
---|---|
代理服务器 | 192.168.148.101 |
后端服务器 | 192.168.148.102 |
测试主机 | 192.168.148.103 |
[root@localhost ~]# yum -y install httpd[root@localhost ~]# cp -v /etc/man_db.conf /var/www/html/man.html]# ls -lh /var/www/html/man.html-rw-r--r--. 1 root root 5.1K Jun 1 15:19 man.html[root@localhost ~]# systemctl start httpd
[root@localhost ~]# yum -y install httpd-tools curl# 测试网页访问,获取HTTP首部信息 Content-Length 大小 5K左右[root@localhost ~]# curl -I http://192.168.148.102/man.htmlHTTP/1.1 200 OKDate: Sat, 01 Jun 2019 07:22:37 GMTServer: Apache/2.4.6 (CentOS)Last-Modified: Sat, 01 Jun 2019 07:19:50 GMTETag: "1433-58a3df4ec4829"Accept-Ranges: bytesContent-Length: 5171Content-Type: text/html; charset=UTF-8
[root@localhost ~]# yum -y install nginx[root@localhost nginx]# vim nginx.confhttp { server { listen 80; location / { proxy_pass http://192.168.148.102/; proxy_http_version 1.1; }}
[root@localhost ~]# curl -I http://192.168.148.101/man.htmlHTTP/1.1 200 OKServer: openrestyDate: Sat, 01 Jun 2019 07:31:45 GMTContent-Type: text/html; charset=UTF-8Content-Length: 5171Connection: keep-aliveLast-Modified: Sat, 01 Jun 2019 07:19:50 GMTETag: "1433-58a3df4ec4829"Accept-Ranges: bytes
[root@localhost nginx]# vim nginx.confhttp { proxy_cache_key string; ##缓存中用于“键”的内容,默认值:proxy_cache_key $scheme$proxy_host$request_uri; proxy_cache_valid 200 301 302 10m; proxy_cache_valid 404 1m; proxy_cache_path /var/run/nginx/proxy_cache levels=1:2:2 keys_zone=proxycache:20m inactive=120s max_size=1g; #在硬盘上创建缓存目录 server { listen 80; location /web { proxy_pass http://192.168.148.102/; proxy_http_version 1.1; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache proxycache; #调用定义的缓存 proxy_cache_key $request_uri; #缓存访问的uri }}
[root@localhost ~]# modprobe -r e1000; modprobe e1000[root@localhost ~]# ifconfig eth0eth0: flags=4163mtu 1500 inet 192.168.148.101 netmask 255.255.255.0 broadcast 192.168.148.255 inet6 fe80::20c:29ff:febd:3f8b prefixlen 64 scopeid 0x20 ether 00:0c:29:bd:3f:8b txqueuelen 1000 (Ethernet) RX packets 39 bytes 3198 (3.1 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 35 bytes 3388 (3.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0[root@localhost ~]# modprobe -r e1000; modprobe e1000[root@localhost ~]# ifconfig eth0eth0: flags=4163 mtu 1500 inet 192.168.148.102 netmask 255.255.255.0 broadcast 192.168.148.255 inet6 fe80::20c:29ff:fe35:8bbe prefixlen 64 scopeid 0x20 ether 00:0c:29:35:8b:be txqueuelen 1000 (Ethernet) RX packets 23 bytes 1886 (1.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 20 bytes 1940 (1.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
# 测试主机测试网页访问[root@localhost ~]# curl http://192.168.148.101/man.html# 代理服务器上确认缓存生成结果[root@localhost ~]# tree /var/run/nginx/proxy_cache//var/run/nginx/proxy_cache/└── 3 └── 47 └── 3c └── 05d13bbd1e55c50b1408f46dce73c4733 directories, 1 file# 通过ab工具测试并发200个请求 总请求10000[root@localhost ~]# ab -n10000 -c200 http://192.168.148.101/man.htmlDocument Path: /man.htmlDocument Length: 5171 bytesConcurrency Level: 200Time taken for tests: 1.850 secondsComplete requests: 10000Failed requests: 0Write errors: 0Total transferred: 54230000 bytes #传输了54M的数据HTML transferred: 51710000 bytes # 代理服务器 网卡发送流量 TX packets 57M[root@localhost ~]# ifconfig eth0eth0: flags=4163mtu 1500 inet 192.168.148.101 netmask 255.255.255.0 broadcast 192.168.148.255 inet6 fe80::20c:29ff:febd:3f8b prefixlen 64 scopeid 0x20 ether 00:0c:29:bd:3f:8b txqueuelen 1000 (Ethernet) RX packets 62132 bytes 5110333 (4.8 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 82148 bytes 59774642 (57.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0# 后端服务器网卡发送流量 12KB (由于代理服务器有缓存不需要从后端服务器取数据)[root@localhost ~]# ifconfig eth0eth0: flags=4163 mtu 1500 inet 192.168.148.102 netmask 255.255.255.0 broadcast 192.168.148.255 inet6 fe80::20c:29ff:fe35:8bbe prefixlen 64 scopeid 0x20 ether 00:0c:29:35:8b:be txqueuelen 1000 (Ethernet) RX packets 81 bytes 6464 (6.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 72 bytes 12967 (12.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
转载于:https://blog.51cto.com/1012682/2403613