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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值