varnish配置
vi /etc/varnish/vcl.conf
1 | backend default { set backend.host = "192.168.1.118" ; set backend.port = "80" ; } sub vcl_recv { # pass mode can't handle POST (yet) if (req.request == "POST" ) { pipe; } # force lookup even when cookies are present #if (req.request == "GET" && req.http.cookie) { # lookup; #} #静态文件CACHE if (req.request == "GET" && req.url ~ "/.(gif|jpg|swf|css|js)$" ) { lookup; } } sub vcl_fetch { # force minimum ttl of 180 seconds if (obj.ttl < 180s) { set obj.ttl = 180s; } } |
haproxy 配置
1 | defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen webfarm 0.0.0.0:80
mode http
stats uri /haproxy-stats
stats realm Haproxy/ statistics
stats auth another:another
balance roundrobin
cookie SERVERID insert indirect
option httpchk HEAD /ha_check.html HTTP/1.0
server webA 127.0.0.1:8080 cookie A check
|
启动varnish.sh:
1 | #!/bin/sh # file: start.sh date -u varnishd / -a 127.0.0.1:8080 / -s file,/var/cache/varnish/V,1024m / -f /etc/varnish/vcl.conf / -p thread_pool_max=1500 / -p thread_pools=5 / -p listen_depth=512 / -p client_http11=on / |
附varnish多站点配置
1 | backend www { set backend.host = "www.chinajavaworld.com" ; set backend.port = "80" ; } backend blog { set backend.host = "blog.chinajavaworld.com" ; set backend.port = "80" ; } backend image { set backend.host = "image.chinajavaworld.com" ; set backend.port = "80" ; } sub vcl_recv { if (req.http.host ~ "^(www.)?chinajavaworld.com$" ) { set req.http.host = "www.chinajavaworld.com" ; set req.backend = www; } elsif (req.http.host ~ "^blog.chinajavaworld.com$" ) { set req.backend = blog; } elsif (req.http.host ~ "^image.chinajavaworld.com$" ) { set req.backend = image; } else { error 404 "Unknown host" ; } |
附varnish in OpenSuse安装
1 | rpm -ivh libvarnish0-1.1-3.2.i586.rpm rpm -ivh varnish-1.1-3.2.i586.rpm |
Get rpm from
http://download.opensuse.org/repositories/server:/http/openSUSE_10.3/i586
平均得分
(0 次评分)
本文详细介绍了Varnish缓存服务器及HAProxy负载均衡器的具体配置方法,包括如何设置后端服务器、处理不同类型的请求以及启动Varnish的服务脚本。此外,还提供了多站点配置Varnish的例子及在OpenSuse下的安装指导。
1632

被折叠的 条评论
为什么被折叠?



