varnish 反向HTTP代理,做高性能的HTTP加速器,能极大的提高访问网站的速度和并发
1. Debian9.4 下安装varnish稳定版6.0.0:
http://varnish-cache.org/releases/index.html
http://varnish-cache.org/_downloads/varnish-6.0.0.tgz
2. 源码安装:
refer to:
http://varnish-cache.org/docs/6.0/installation/install.html#debian-ubuntu
apt-get install \
make \ automake \ autotools-dev \ libedit-dev \ libjemalloc-dev \ libncurses-dev \ libpcre3-dev \ libtool \ pkg-config \ python-docutils \ python-sphinx \ graphviz \ autoconf-archive
CentOS/RedHat :
yum install make automake autoconf libtool libedit-devel jemalloc-devel ncurses-devel python-docutils pcre-devel openssl-devel zlib-devel bzip2-devel
tar xf varnish-6.0.0.tgz
cd varnish-6.0.0/ sh autogen.sh sh configure make make install
或者可以apt-get安装:
apt-get install varnish
3. 配置
nginx做为http服务器,http端口为80端口
将varnish-6.0.0/etc/下的所有的 *.vcl文件拷贝到/etc/varnish/目录下:
cp -rf ./varnish-6.0.0/etc/* /etc/varnish/
再将example.vcl拷贝成 default.vcl
cp example.vcl default.vcl
修改default.vcl为如下:
backend default { .host = "192.168.0.112"; #.host = "127.0.0.1"; .port = "80"; }直接.host = "127.0.0.1";也可以
运行如下命令,查看varnishd 帮助信息:
varnishd -?
运行:
varnishd -a :6801 -f /etc/varnish/default.vcl -s malloc -l 512M
Debian浏览器下访问:
windows下访问:
4.查看varnish的工作状态
varnishstat命令可以查看varnish的工作状态,缓存命中率等信息