varnish之ubuntu(+nginx)部署

参考官方文档:
https://www.varnish-cache.org/installation/ubuntu
apt-get install apt-transport-https
...
apt-get update
apt-get install varnish
------------------------------------------------------------------------
......
Processing triggers for man-db ...
Processing triggers for ureadahead ...
Setting up libvarnishapi1 (3.0.2-1ubuntu0.1) ...
Setting up varnish (3.0.2-1ubuntu0.1) ...
* Starting HTTP accelerator varnishd                 [ OK ]
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
--------------------------------------------------------------------------
安装成功!

设置Varnish开机启动,执行:
chkconfig varnish on和chkconfig varnishncsa on

启动Varnish的命令:
service varnish start和service varnishncsa start

如果报:
The program 'chkconfig' is currently not installed.  You can install it by typing:
则安装:
apt-get install chkconfig

设置Varnish缓存规则:
    默认目录 /etc/varnish/default.vcl

vim /etc/varnish/default.vcl

修改
backend default {
    .host = "127.0.0.1";
    .port = "81";
}
端口81为当前server的预加cache的端口.


直接启动:
/usr/sbin/varnishd -f /etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:801 -a 0.0.0.0:6082

查看varnish进程:
ps -ef | grep varnish

root     19794     1  0 16:50 ?        00:00:00 /usr/sbin/varnishd -f /etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:801 -a 0.0.0.0:6082
nobody   19795 19794  0 16:50 ?        00:00:00 /usr/sbin/varnishd -f /etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:801 -a 0.0.0.0:6082
root     19815 15172  0 16:51 pts/0    00:00:00 grep --color=auto varnishd
root@ubuntu:~# ps -ef | grep varnish

GET访问:
GET -Used http://127.0.0.1:6082/test.html

GET http://127.0.0.1:6082/test.html
User-Agent: lwp-request/6.03 libwww-perl/6.03

200 OK
Cache-Control: max-age=86400
Connection: close
Date: Tue, 10 Mar 2015 08:59:08 GMT
Via: 1.1 varnish
Accept-Ranges: bytes
Age: 0
ETag: "54fea584-11"
Server: UCS/1.0.0
Content-Length: 17
Content-Type: text/html; charset=utf-8
Last-Modified: Tue, 10 Mar 2015 08:04:20 GMT
Client-Date: Tue, 10 Mar 2015 08:59:08 GMT
Client-Peer: 127.0.0.1:6082
Client-Response-Num: 1
X-Varnish: 1366749418

通过6082端口访问
http://{IP}:6082/

http://{IP}:81/
是同一server.

猜你喜欢

转载自lesorb.iteye.com/blog/2191050