引用自:http://www.fkblog.org/blog53
1、源码下载
下载地址:http://sourceforge.net/projects/varnish/files/ 可以找最新稳定版下载
官网:https://www.varnish-cache.org
2、解压安装
tar -zxvf varnish-2.1.3.tar.gz cd /usr/local/src/varnish-2.1.3 ./autogen.sh ./configure --prefix=/usr/local/varnish --enable-debugging-symbols --enable-developer-warnings --enable-dependency-trackingmake && make install
注:编译过程可能出现:No package 'libpcre' found 是pcre少了开发包
解决办法:yum -y install pcre pcre-devel
To build Varnish on a Red Hat or Centos system you need the following packages installed:
(centos下以上的包必须确保安装 其他系统参见: https://www.varnish-cache.org/docs/2.1/installation/install.html)
- automake
- autoconf
- libtool
- ncurses-devel
- libxslt
- groff
- pcre-devel
- pkgconfig
yum -y install automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig
3、配置参数说明
启动参数说明 -a address:port # varnishd httpd监听地址及其端口 -b address:port # 后台服务器地址及其端口 # -b # -b ':' -d # 使用debug模式 -f file # varnishd 服务器存取规则文件 -F # Run in foreground -h kind[,hashoptions] # Hash specification # -h simple_list # -h classic [default] # -h classic, -n dir # varnishd working directory -P file # PID file -p param=value # 服务器参数,用来优化性能 -s kind[,storageoptions] # 缓存内容存放方式 # -s malloc # -s file [default: use /tmp] # -s file, # -s file,, -t # Default TTL -T address:port # telnet管理地址及其端口 -V # version -w int[,int[,int]] # 工作线程数 # -w # -w min,max一般使用varnishd -a address:port -b address:port 其他使用默认即可启动(注意:vcl 中指定 后台服务器的话就不用使用-b 参数了 )
4、 配置文件说明
进入配置文件目录
cd /usr/local/varnish/etc/varnish
cp default.vcl varnish.vcl
vim varnish.vcl(拷贝以下参数)
backend server { .host = "127.0.0.1"; .port = "80"; } acl purge { "localhost"; "127.0.0.1"; "192.168.1.0"/24; } sub vcl_recv { if (req.request == "PURGE") { if (!client.ip ~ purge) { error 405 "Not allowed."; } return(lookup); } } sub vcl_hit { if (req.request == "PURGE") { set obj.ttl = 0s; error 200 "Purged."; } } sub vcl_miss { if (req.request == "PURGE") { error 404 "Not in cache."; } } sub vcl_fetch { if (req.request == "GET" && req.url ~ "\.(txt|js){1}quot;) { set beresp.ttl = 3600s; } else { set beresp.ttl = 30d; } }
由于版本不同有关配置请参看官网: https://www.varnish-cache.org/docs/2.1/tutorial/index.html#tutorial-index(2.1版本配置地址)更多版本配置见:https://www.varnish-cache.org/docs/
参考文章:http://kerry.blog.51cto.com/172631/402923
启动命令:
/usr/local/varnish/sbin/varnishd -f /usr/local/varnish/etc/varnish/varnish.vcl -a 0.0.0:800 -s file,/var/vcache/varnish_cache.data,1G -g www -u www -w 30000,51200,10 -T 127.0.0.1:3500
Now you have Varnish running. Let us make sure that it works properly. Use your browser to go to http://youwebsite:800/ - you should now see your web application running there.
在你浏览器输入:http://youwebsite:800/ 即可
本人手头有份pdf手册需要的可以联系我:429240967