加入收藏 | 设为首页 | 会员中心 | 我要投稿 佛山站长网 (https://www.0757zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

详解CentOS 5.8下varnish-2.1.5的安装配置

发布时间:2016-10-29 03:35:26 所属栏目:Linux 来源:网络整理
导读:Varnish是一款强大的反向代理加速软件,关于其工作原理可以参考上图,其具体流程及VCL语法我这里就不做说明,网上资料多,大家还可以对照参考其官方网站和《Var

五、启动varnish的命令很长,如下所示:

/usr/local/varnish/sbin/varnishd -n /data/varnish/cache -f /usr/local/varnish/etc/varnish/better.vcl -a 0.0.0.0:80 -s

file,/data/varnish/varnish_cache.data,8G  -p user=varnish -p group=varnish -p default_ttl=14400 -p thread_pool_max=8000 -p send_timeout=20 -w

5,51200,30 -T 127.0.0.1:3500  -P /usr/local/varnish/var/varnish.pid

验证其是否生效可以用curl –I命令,如下所示:

[root@localhost cache]# curl -I http://www.yuhongchun027.net/

以下结果显示varnish缓存已经起作用了:

HTTP/1.1 200 OK

Server: Apache/2.2.3 (CentOS)

Last-Modified: Wed, 28 Aug 2013 16:27:33 GMT

ETag: "10d242-e-776b6740"

Content-Type: text/html; charset=UTF-8

Content-Length: 14

Date: Wed, 21 Aug 2013 17:47:48 GMT

X-Varnish: 1584727079 1584726982

Age: 10101

Via: 1.1 varnish

Connection: keep-alive

X-Cache: HIT  FROM www.yuhongchun027.net

六、如果vcl配置文件发生改动,想要不重启而直接reload,可以用如下操作,可以在本机上进行telnet操作,连接3500管理端口:

telnet 127.0.0.1 3500

vcl.load newconfig /usr/local/varnish/etc/varnish/better.vcl

200 13

VCL compiled.

vcl.use newconfig

200 0

如果显示有200字样,则表示已经正常reload了,newconfig这个名字是自己定义的,熟悉varnish操作的朋友应该也清楚,通过telnet连接本机还可以进行清理缓存。

七、用varnishadm命令来清理缓存,例子如下所示:

清除所有缓存

/usr/local/varnish/bin/varnishadm -T 192.168.1.103:3500 url.purge *$

清除image目录下所有缓存

/usr/local/varnish/bin/varnishadm -T 192.168.1.103:3500 url.purge /image/

查看最近清除的详细url列表,可执行如下命令:

/usr/local/varnish/bin/varnishadm –T 192.168.1.103:3500 purge.list

另外,缓存命中率的高低直接说明了varnish的运行状态和效果,如果缓存率命中率过低,我们应该对varnish配置进行检查调整来进行提高,查看其命中率命令如下所示:

/usr/local/varnish/bin/varnishstat -n /data/varnish/cache

八、内核优化如下所示:

编辑/etc/sysctl.conf,添加如下选项:

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.ip_local_port_range = 1024 65000

net.ipv4.tcp_max_syn_backlog = 8192

net.ipv4.tcp_max_tw_buckets = 5000

net.ipv4.tcp_max_syn_backlog = 65536

net.core.netdev_max_backlog =  32768

net.core.somaxconn = 32768

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000

net.ipv4.tcp_max_orphans = 3276800

执行如下命令,让改动配置立即生效:

/sbin/sysctl –p

注意:老生常谈的ulimit的问题,这个话题说得太多了,这里实在不想再提了,记得将在/etc/rc.local添加如下内容:

ulimit –SHn 65535

(编辑:佛山站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读