1. 操作命令清理varnish缓存
新版varnish会有部分操作命令。
[root@server1 ~]# varnishadm
200
-----------------------------
Varnish Cache CLI 1.0
-----------------------------
Linux,3.10.0-514.el7.x86_64,x86_64,-junix,-smalloc,-sdefault,-hcritbit
varnish-6.3.1 revision 6e96ff048692235e64565211a38c41432a26c055
Type 'help' for command list.
Type 'quit' to close CLI session.
varnish> ban req.url ~ "/index.html" # 200表示清理成功
200
2. 安装bansys(帮助清除varnish内存)
步骤一:下载安装包。
[root@server1 ~]# yum install php unzip httpd -y
[root@server1 ~]# unzip bansys.zip -d /var/www/html/
[root@server1 ~]# mv /var/www/html/bansys/* /var/www/html/
因为bansys是用php语言编写的,因为需要下载php安装包。
步骤二:更改httpd的端口,(80端口被varnish占用)
[root@server1 ~]# vim /etc/httpd/conf/httpd.conf
#Listen 12.34.56.78:80
Listen 8080
[root@server1 ~]# cd /var/www/html/
[root@server1 html]# ls
bansys config.php purge_action.php
class_socket.php index.php static
[root@server1 html]# vim config.php
<?php
//varnish主机列表
//可定义多个主机列表
$var_group1 = array(
'host' => array('172.25.254.1'),
'port' => '8080',
);
//varnish群组定义
//对主机列表进行绑定
$VAR_CLUSTER = array(
'www.westos.org' => $var_group1,
);
//varnish版本
//2.x和3.x推送命令不一样
$VAR_VERSION = "3";
?>
[root@server1 html]# systemctl start httpd
测试:172.25.42.1:8080
3. varnish推送平台
[root@server1 html]# vim /etc/varnish/default.vcl
acl westos {
"127.0.0.1"; # 谁可以推送
"172.25.60.0"/24;
}
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.
# if (req.http.host ~ "^(www.)?westos.org"){
# set req.http.host = "www.westos.org";
# set req.backend_hint = lb.backend();
# return (pass);
#} elsif (req.http.host ~ "^bbs.westos.org"){
# set req.backend_hint = web2;
# } else {
# return (synth(405));
# }
if (req.method == "BAN"){
if (!client.ip ~ westos){
return (synth(405,"Not allowed"));
}
ban ("req.url ~" + req.url);
return (purge); # 取出相应的缓存对象清除
}
}
真机上修改域名解析
[root@foundation60 kiosk]# vim /etc/hosts
172.25.42.1 www.westos.org
server1:
[root@server1 html]# systemctl restart varnish
测试:真机(172.25.42.250)
推送测试
推送=清除
推送内容:**.***表示全部