现在的位置: 首页 > 综合 > 正文

haproxy + varnish cache配置

2014年02月19日 ⁄ 综合 ⁄ 共 1843字 ⁄ 字号 评论关闭

varnish配置

vi /etc/varnish/vcl.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

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
2
3
4
5
6
7
8
9
10
11

#!/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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

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
2

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 次评分)

抱歉!评论已关闭.