[CDN]搭建Varnish代理环境,加速web访问速度。
Varnish代理服务器,可用理解为缓存服务器,经常被访问的内容,自动生成缓存到代理服务器上,以便于用户可用更快速的访问自己想要的内容。
Varnish代理服务器,也可以与Nginx调度服务器并行使用。
Varnish服务器可放置在各个城市(CDN,内容分发网络),以加速各个地域的访问速度。
Nginx也可以部署CND服务。
CDN建设需要庞大的资源,所以一般企业不会自己做CDN。
源码安装:Varnish
下载:http://dl.teddyou.cn/download/varnish-5.2.1.tar.gz
环境搭建:
yum -y install gcc readline-devel ncurses-devel pcre-devel python-docutils
tar xf解压,进目录编译安装 ./configure && make && make install
cp etc/example.vcl /usr/local/etc/default.vcl //拷贝文件
修改配置文件。
vim /usr/local/etc/default.vcl
backend default {
.host = "192.168.2.100"; //设定加入缓存的服务器
.port = "80"; //设定端口
}
varnishd -f /usr/local/etc/default.vcl //启动服务
其他命令选项:
-s malloc,128M //使用内存作为缓存,其空间为128M
-s file,路径,1G //定义varnishd使用文件作为缓存
curl 访问测试
varnishncsa //访问日志,有人访问则会跳出内容
更新缓存数据:
varnishadm
ban req.url ~ .* //输入,更新全部页面。
发表评论