nginxのリバースプロキシキャッシュテスト結果

実験環境:3つのCentOSに7の仮想マシン

役割 IP
プロキシサーバー 192.168.148.101
バックエンドサーバー 192.168.148.102
テストホスト 192.168.148.103

バックエンドサーバーのテストページを展開するhttpdの準備ができて

[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

テスト用ホストインストールカールのhttpd-ツール

[root@localhost ~]# yum -y install httpd-tools curl
# 测试网页访问,获取HTTP首部信息 Content-Length 大小 5K左右
[root@localhost ~]# curl -I http://192.168.148.102/man.html
HTTP/1.1 200 OK
Date: Sat, 01 Jun 2019 07:22:37 GMT
Server: Apache/2.4.6 (CentOS)
Last-Modified: Sat, 01 Jun 2019 07:19:50 GMT
ETag: "1433-58a3df4ec4829"
Accept-Ranges: bytes
Content-Length: 5171
Content-Type: text/html; charset=UTF-8

nginxのは、Configuration Agentを取り付けプロキシ構成EPELソース

[root@localhost ~]# yum -y install nginx
[root@localhost nginx]# vim nginx.conf
http {
    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.html
HTTP/1.1 200 OK
Server: openresty
Date: Sat, 01 Jun 2019 07:31:45 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 5171
Connection: keep-alive
Last-Modified: Sat, 01 Jun 2019 07:19:50 GMT
ETag: "1433-58a3df4ec4829"
Accept-Ranges: bytes

オープンプロキシサーバーのキャッシュ

[root@localhost nginx]# vim nginx.conf
http {
    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
    }
}   

トラフィック統計情報のNICをクリアするプロキシサーバとバックエンドサーバー

[root@localhost ~]# modprobe -r e1000; modprobe e1000
[root@localhost ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 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<link>
        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 eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  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<link>
        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
            └── 05d13bbd1e55c50b1408f46dce73c473

3 directories, 1 file

# 通过ab工具测试并发200个请求 总请求10000
[root@localhost ~]# ab -n10000 -c200  http://192.168.148.101/man.html

Document Path:          /man.html
Document Length:        5171 bytes

Concurrency Level:      200
Time taken for tests:   1.850 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      54230000 bytes #传输了54M的数据
HTML transferred:       51710000 bytes 

# 代理服务器 网卡发送流量 TX packets 57M
[root@localhost ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 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<link>
        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 eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  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<link>
        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

オープンプロキシキャッシングリバースプロキシサーバとしてnginxのを効果的にバックエンドサーバの圧力を低減することができます。

おすすめ

転載: blog.51cto.com/1012682/2403613