一.CDN推送平台管理的搭建
CDN推送平台管理:简单的说就是利用web界面批量清除缓存
第一步:
首先在nodel1安装推送平台所需的软件包中httpd unizp php
yum install -y unzip php httpd
将推送平台压缩包bansys.zip从真机上拷贝到nodel1(也就是Varnish服务器的主机)
将推送平台压缩包bansys.zip解压到共享目录下,并编辑config.php文件
unzip bansys.zip -d /var/www/html
cd /var/www/html
ls
cd bansys/
ls
mv * ../
cd ..
ls
vim config.php
<?php
//varnish主机列表
//可定义多个主机列表
$var_group1 = array(
'host' => array('172.25.11.11'),
'port' => '8080',
);
//varnish群组定义
//对主机列表进行绑定
$VAR_CLUSTER = array(
'www.westos.org' => $var_group1,
);
//varnish版本
//2.x和3.x推送命令不一样
$VAR_VERSION = "3";
?>
第二步:
修改httpd的端口
vim /etc/httpd/conf/httpd.conf
将端口改成8080
systemctl start httpd
修改httpd的端口,因为varnish已经占用了80端口,所以这里的httpd端口更改成了8080
重启网络
此时网页中可以打开这个推送平台页面,但是无法推送,因为没有配置推送。
第三步:
编辑varnish的配置文件,设置访问控制
vim /etc/varnish/default.vcl
vcl 4.0;
import directors from "/usr/lib64/varnish/vmods/libvmod_directors.so";
# Default backend definition. Set this to point to your content server.
acl meng { #设置的访问权限
"127.0.0.1"; 本机的回环接口
"172.25.11.0"/24; #使网段在172.25.11的ip都有权限清理反向代理服务器上的缓存
}
backend web1 {
.host = "172.25.11.2";
.port = "80";
}
backend web2 {
.host = "172.25.11.3";
.port = "80";
}
sub vcl_init {
new lb = directors.round_robin();
lb.add_backend(web1);
lb.add_backend(web2);
}
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); #会时时刻刻清除缓存,为了验证web网页是否可以清理缓存,实验效果明显,将这行注销掉
} elsif (req.http.host ~ "^bbs.westos.org") {
set req.backend_hint = web2;
} else {
return(synth(405));
}
if (req.method == "BAN") {
if (!client.ip ~ meng) {
return (synth(405,"Not allowed.")); #如果不是允许的ip就拒绝清理
}
ban("req.url ~ " + req.url); #如果是允许的ip就进行清理
return(purge);
}
}
systemctl restart varnish
第四步:在真机里测试
在浏览器输入172.25.11.11:8080,会出现以下界面
此时www.westos.org/index.html是有缓存的
此时目录有缓存