varnish是一个http缓存方案。它使用纯内存作为缓存对象,所以在速度上非常有优势。如果打算加速web服务器的图片等静态资源或者cookie、某些变动不频繁的接口等资源都可以使用Varnish来做加速。
普通情况下也可以使用nginx来做缓存,但是ngxin毕竟主业是反代。如果遇到大规模使用的情况下还是换个专业的吧。
可以使用安装包安装,这里给出一个在Red Hat和centos上安装的地址:https://packagecloud.io/varnishcache/varnish60/install#manual-rpm
也可以使用源代码安装git clone https://github.com/varnishcache/varnish-cache
还需要安装下面的几个依赖
- autoconf
- automake
- jemalloc-devel
- libedit-devel
- libtool
- ncurses-devel
- pcre-devel
- pkgconfig
- python-docutils
- python-sphinx
之后编译源代码1
2
3
4cd varnish-cache
sh autogen.sh
sh configure
make
也可以在编译的时候做一次检测1
make check
最后只需要安装到系统中就可以了1
sudo make install
之后可以启动varnish服务了1
service varnish start