Varnish缓存服务器概述

  • Varnish一款高性能且开源的反向代理服务器
  • Varnish具有性能高、速度更快、管理更方便等优点

CDN(内容分发网络)

  • 让用户访问距离最近的缓存服务器

安装软件包

1
2
3
4
5
6
[root@web1 ~]# yum install gcc readline-devel pcre-devel python-docutils -y         #安装软件依赖包
[root@web1 ~]# useradd -s /sbin/nologin varnish
[root@web1 ~]# tar xf varnish-5.2.1.tgz
[root@web1 ~]# cd varnish-5.2.1/
[root@web1 varnish-5.2.1]# ./configure
[root@web1 varnish-5.2.1]# make && make install

配置代理服务

1
2
3
4
5
6
7
8
9
10
11
12
[root@web1 varnish-5.2.1]# cp etc/example.vcl /usr/local/etc/default.vcl
#拷贝配置文件模板
[root@web1 ~]# vim /usr/local/etc/default.vcl
backend default {
.host = "192.168.1.10";
.port = "81";
}
#防止端口冲突关闭nginx
[root@web1 ~]# /usr/local/nginx/sbin/nginx -s stop
#开启服务
[root@web1 ~]# varnishd -f /usr/local/etc/default.vcl

手动清除缓存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@web1 ~]# varnishadm 
200

Varnish Cache CLI 1.0

Linux,3.10.0-862.el7.x86_64,x86_64,-junix,-smalloc,-smalloc,-hcritbit
varnish-5.2.1 revision 67e562482

Type 'help' for command list.
Type 'quit' to close CLI session.

varnish> ban req.url ~ c.html
200

varnish>