我一直在关注如何使用haproxy安装varnish haproxy博客的教程。 ( 链接 )这部分的haproxyconfiguration设置有问题:
frontend ft_web_static bind 10.0.1.3:80 monitor-uri /haproxycheck # Tells Varnish to stop asking for static content when servers are dead # Varnish would deliver staled content monitor fail if nbsrv(bk_appsrv_static) eq 0 default_backend bk_appsrv_static
当我重新启动haproxy,它给了我这个错误:
[root@ch]# service haproxy restart [ALERT] 348/004936 (28582) : parsing [/etc/haproxy/haproxy.cfg:282] : error detected while parsing a 'monitor fail' condition : no such ACL : 'nbsrv(apache2_static)'.
我想有一些错误的nbsrv(bk_appsrv_static) eq 0 。 有人在文章后的评论部分也提出了这个问题,但没有人有解决办法。 任何人都可以找出在设置中是否有错字或错误?
这是完整的configuration:
# On Aloha, the global section is already setup for you # and the haproxy stats socket is available at /var/run/haproxy.stats global stats socket ./haproxy.stats level admin log 10.0.1.10 local3 # default options defaults option http-server-close mode http log global option httplog timeout connect 5s timeout client 20s timeout server 15s timeout check 1s timeout http-keep-alive 1s timeout http-request 10s # slowloris protection default-server inter 3s fall 2 rise 2 slowstart 60s # HAProxy's stats listen stats bind 10.0.1.3:8880 stats enable stats hide-version stats uri / stats realm HAProxy Statistics stats auth admin:admin # main frontend dedicated to end users frontend ft_web bind 10.0.0.3:80 acl static_content path_end .jpg .gif .png .css .js .htm .html acl pseudo_static path_end .php ! path_beg /dynamic/ acl image_php path_beg /images.php acl varnish_available nbsrv(bk_varnish_uri) ge 1 # Caches health detection + routing decision use_backend bk_varnish_uri if varnish_available static_content use_backend bk_varnish_uri if varnish_available pseudo_static use_backend bk_varnish_url_param if varnish_available image_php # dynamic content or all caches are unavailable default_backend bk_appsrv # appsrv backend for dynamic content backend bk_appsrv balance roundrobin # app servers must say if everything is fine on their side # and they can process requests option httpchk option httpchk GET /appcheck http-check expect rstring [oO][kK] cookie SERVERID insert indirect nocache # Transparent proxying using the client IP from the TCP connection source 10.0.1.1 usesrc clientip server s1 10.0.1.101:80 cookie s1 check maxconn 250 server s2 10.0.1.102:80 cookie s2 check maxconn 250 # static backend with balance based on the uri, including the query string # to avoid caching an object on several caches backend bk_varnish_uri balance uri # in latest HAProxy version, one can add 'whole' keyword # Varnish must tell it's ready to accept traffic option httpchk HEAD /varnishcheck http-check expect status 200 # client IP information option forwardfor # avoid request redistribution when the number of caches changes (crash or start up) hash-type consistent server varnish1 10.0.1.201:80 check maxconn 1000 server varnish2 10.0.1.202:80 check maxconn 1000 # cache backend with balance based on the value of the URL parameter called "id" # to avoid caching an object on several caches backend bk_varnish_url_param balance url_param id # client IP information option forwardfor # avoid request redistribution when the number of caches changes (crash or start up) hash-type consistent server varnish1 10.0.1.201:80 maxconn 1000 track bk_varnish_uri/varnish1 server varnish2 10.0.1.202:80 maxconn 1000 track bk_varnish_uri/varnish2 # frontend used by Varnish servers when updating their cache frontend ft_web_static bind 10.0.1.3:80 monitor-uri /haproxycheck # Tells Varnish to stop asking for static content when servers are dead # Varnish would deliver staled content monitor fail if nbsrv(bk_appsrv_static) eq 0 default_backend bk_appsrv_static # appsrv backend used by Varnish to update their cache backend bk_appsrv_static balance roundrobin # anything different than a status code 200 on the URL /staticcheck.txt # must be considered as an error option httpchk option httpchk HEAD /staticcheck.txt http-check expect status 200 # Transparent proxying using the client IP provided by X-Forwarded-For header source 10.0.1.1 usesrc hdr_ip(X-Forwarded-For) server s1 10.0.1.101:80 check maxconn 50 slowstart 10s server s2 10.0.1.102:80 check maxconn 50 slowstart 10s
那篇文章已经超过3年了,从那以后,HAProxy已经有了两个稳定版本,所以我怀疑这就是为什么它不能够逐字地运行。
如果我不得不猜测你确切的问题,我会说这与monitor fail语句的语法有关,它在if之后期望ACL名称。
你必须select解决这个问题。
将ACL更改为“匿名”ACL,如HAProxy文档的第7.2节所述。 我已经链接了v1.6,但v1.5也是一样的。
您的monitor将如下所示:
monitor fail if { nbsrv(bk_appsrv_static) eq 0 }
为bk_appsvr_static后端的整体状态创build一个命名ACL,并将其传递给monitor fail行。
这看起来像:
acl bk_app_static_noservers nbsrv(bk_appsrv_static) eq 0 monitor fail if bk_app_static_noservers
在这种情况下,如果bk_appsvr_static没有可用的服务器,则ACL将为FALSE并且将应用monitor fail 。