我正在尝试将Varnish 6.0.3作为安装在CentOS 7.6上的缓存服务器社区版本。
我将Varnish部署在NGINX后面,用作SSL卸载和代理。 Varnish服务器将请求发送到另一个NGINX(Kubernetes入口控制器),然后再次将其代理到JAVA SpringBoot后端。
NGINX前端Varnish的配置如下:
server {
listen 443 ssl;
server_name cache.mydomain.io;
ssl_certificate /opt/ssl/my.crt;
ssl_certificate_key /opt/ssl/my.key;
access_log /var/log/nginx/cache.mydomain.io-access.log;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://10.100.0.7:6081;
}
}
我正在使用具有非常默认配置的Varnish:
backend default {
.host = "10.100.16.128";
.port = "80";
}
sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.
}
sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.
}
sub vcl_deliver {
# Happens when we have all the pieces we need and are about to send the
# response to the client.
#
# You can do accounting or modifying the final object here.
}
此后,我开始发送请求,如下所示:
curl 'https://cache.mydomain.io/health'
{"status":"UP"}
,我可以看到请求遵循了从NGINX到Varnish和JAVA后端的所有链条。 但是用相同的GET请求一次又一次地尝试,我在Varnish端从来没有HIT缓存。根据varnishstat cmd,所有请求都将丢失,并从后端提供服务。
Uptime mgt: 0+00:22:30 Hitrate n: 10 100 133
Uptime child: 0+00:22:31 avg(n): 0.0000 0.0000 0.0000
NAME CURRENT CHANGE AVERAGE AVG_10 AVG_100 AVG_1000
MGT.uptime 0+00:22:30
MAIN.uptime 0+00:22:31
MAIN.sess_conn 37 0.00 0.03 0.00 0.23 0.24
MAIN.client_req 37 0.00 0.03 0.00 0.23 0.24
MAIN.cache_hitmiss 35 0.00 0.03 0.00 0.22 0.23
MAIN.cache_miss 37 0.00 0.03 0.00 0.23 0.24
MAIN.backend_conn 2 0.00 0.00 0.00 0.01 0.01
MAIN.backend_reuse 35 0.00 0.03 0.00 0.22 0.23
MAIN.backend_recycle 37 0.00 0.03 0.00 0.23 0.24
MAIN.fetch_chunked 37 0.00 0.03 0.00 0.23 0.24
MAIN.pools 2 0.00 . 2.00 2.00 2.00
MAIN.threads 200 0.00 . 200.00 200.00 200.00
MAIN.threads_created 200 0.00 0.15 0.00 0.00 0.00
MAIN.n_object 1 0.00 . 1.00 1.00 1.00
MAIN.n_objectcore 1 0.00 . 1.00 1.00 1.00
MAIN.n_objecthead 3 0.00 . 3.00 2.93 2.92
MAIN.n_backend 1 0.00 . 1.00 1.00 1.00
MAIN.n_expired 1 0.00 0.00 0.00 0.00 0.00
MAIN.s_sess 37 0.00 0.03 0.00 0.23 0.24
MAIN.s_fetch 37 0.00 0.03 0.00 0.23 0.24
MAIN.s_req_hdrbytes 7.37K 0.00 5.59 0.00 47.23 49.35
MAIN.s_resp_hdrbytes 31.26K 0.00 23.70 0.01 200.29 209.30
MAIN.s_resp_bodybytes 555 0.00 0.41 0.00 3.47 3.63
MAIN.sess_closed 37 0.00 0.03 0.00 0.23 0.24
MAIN.backend_req 37 0.00 0.03 0.00 0.23 0.24
MAIN.n_vcl 1 0.00 . 1.00 1.00 1.00
MAIN.bans 1 0.00 . 1.00 1.00 1.00
SMA.s0.g_space 256.00M 0.00 . 256.00M 256.00M 256.00M
SMA.Transient.c_req 111 0.00 0.08 0.00 0.69 0.73
SMA.Transient.c_bytes 624.05K 0.00 473.00 0.29 3.90K 4.08K
SMA.Transient.c_freed 623.20K 0.00 472.36 0.29 3.90K 4.07K
SMA.Transient.g_alloc 1 0.00 . 1.00 1.00 1.00
SMA.Transient.g_bytes 872 0.00 . 872.00 872.00 872.00
VBE.boot.default.bereq_hdrbytes 8.54K 0.00 6.47 0.00 54.75 57.22
VBE.boot.default.beresp_hdrbytes 29.16K 0.00 22.10 0.01 186.84 195.24
VBE.boot.default.beresp_bodybytes 555 0.00 0.41 0.00 3.47 3.63
VBE.boot.default.req 37 0.00 0.03 0.00 0.23 0.24
您能帮助我了解我的实际配置出了什么问题吗?