linux – Custom VCL防止清漆启动

linux – Custom VCL防止清漆启动,第1张

概述 *** 作系统:CentOS 6(x86_64) 我已经安装并配置了varnish但是它现在无法启动. # service varnish restartStopping Varnish Cache: [FAILED]Starting Varnish Cache: *** 作系统:CentOS 6(x86_64)

我已经安装并配置了varnish但是它现在无法启动.

# service varnish restartStopPing Varnish Cache:                                    [Failed]Starting Varnish Cache:                                    [Failed]

我已将此错误缩小到在/etc/varnish/default.vcl中包含另一个VCL文件.

我像这样包括VCL:

include "/etc/varnish/domains/playwithbits.vcl";

如果我清空playwithbits.vcl的内容,那么varnish就可以启动了,但是一旦添加内容就会失败.

我的playwithbits.vcl的内容是:

backend playwithbits {     .host = "localhost";     .port = "8080";}acl purge {     if (req.http.Host ~ "playwithbits.com") {          "localhost";     }}sub vcl_recv {     if (req.http.Host ~ "playwithbits.com") {          set req.backend = playwithbits;           if (req.request == "PURGE") {               if (!clIEnt.ip ~ purge) {                    error 405 "Not allowed.";               }               return(lookup);          }          if (req.url ~ "^/$") {               unset req.http.cookie;          }     }}sub vcl_hit {     if (req.http.Host ~ "playwithbits.com") {          if (req.request == "PURGE") {               set obj.ttl = 0s;                    error 200 "Purged.";          }     }}sub vcl_miss {     if (req.http.Host ~ "playwithbits.com") {          if (req.request == "PURGE") {               error 404 "Not in cache.";          }           if (!(req.url ~ "wp-(login|admin)")) {               unset req.http.cookie;          }          if (req.url ~ "^/[^?]+.(jpeg|jpg|png|gif|ico|Js|CSS|txt|gz|zip|lzma|bz2|tgz|tbz|HTML|htm)(\?.|)$") {               unset req.http.cookie;               set req.url = regsub(req.url,"\?.$","");          }          if (req.url ~ "^/$") {               unset req.http.cookie;          }     }}sub vcl_fetch {     if (req.http.Host ~ "playwithbits.com") {          if (req.url ~ "^/$") {               unset beresp.http.set-cookie;          }          if (!(req.url ~ "wp-(login|admin)")) {               unset beresp.http.set-cookie;          }     }}

这是#strace -e trace =文件服务清漆启动的输出

execve("/sbin/service",["service","varnish","start"],[/* 20 vars */]) = 0access("/etc/ld.so.preload",R_OK)      = 0open("/etc/ld.so.preload",O_RDONLY)    = 3open("/etc/ld.so.cache",O_RDONLY)      = 3open("/lib64/libtinfo.so.5",O_RDONLY)  = 3open("/lib64/libdl.so.2",O_RDONLY)     = 3open("/lib64/libc.so.6",O_RDONLY)      = 3open("/dev/tty",O_RDWR|O_NONBLOCK)     = 3open("/usr/lib/locale/locale-archive",O_RDONLY) = 3open("/proc/meminfo",O_RDONLY)         = 3stat("/etc/varnish",{st_mode=S_IFDIR|0755,st_size=4096,...}) = 0stat(".",...}) = 0open("/usr/lib64/gconv/gconv-modules.cache",O_RDONLY) = 3open("/sbin/service",O_RDONLY)         = 3open("/etc/init.d/functions",O_RDONLY) = 3--- SIGCHLD (Child exited) @ 0 (0) ---stat("/etc/sysconfig/i18n",{st_mode=S_IFREG|0644,st_size=47,...}) = 0open("/dev/null",O_WRONLY|O_CREAT|O_Trunc,0666) = 3open("/etc/profile.d/lang.sh",O_RDONLY) = 3stat("/root/.i18n",0x7fff831f79e0)     = -1 ENOENT (No such file or directory)stat("/etc/sysconfig/init",st_size=1153,...}) = 0open("/etc/sysconfig/init",O_RDONLY)   = 3open("/usr/share/locale/locale.alias",O_RDONLY) = 3open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/initscripts.mo",O_RDONLY) = -1 ENOENT (No such file or directory)open("/usr/share/locale/en_US.utf8/LC_MESSAGES/initscripts.mo",O_RDONLY) = -1 ENOENT (No such file or directory)open("/usr/share/locale/en_US/LC_MESSAGES/initscripts.mo",O_RDONLY) = -1 ENOENT (No such file or directory)open("/usr/share/locale/en.UTF-8/LC_MESSAGES/initscripts.mo",O_RDONLY) = -1 ENOENT (No such file or directory)open("/usr/share/locale/en.utf8/LC_MESSAGES/initscripts.mo",O_RDONLY) = -1 ENOENT (No such file or directory)open("/usr/share/locale/en/LC_MESSAGES/initscripts.mo",O_RDONLY) = -1 ENOENT (No such file or directory)--- SIGCHLD (Child exited) @ 0 (0) ------ SIGCHLD (Child exited) @ 0 (0) ---chdir("/")                              = 0stat("/etc/init.d/varnish",{st_mode=S_IFREG|0755,st_size=2837,...}) = 0stat("/sbin/env",0x7fff831f8960)       = -1 ENOENT (No such file or directory)stat("/usr/sbin/env",0x7fff831f8960)   = -1 ENOENT (No such file or directory)stat("/bin/env",st_size=23832,...}) = 0stat("/bin/env",...}) = 0access("/bin/env",X_OK)                = 0stat("/bin/env",R_OK)                = 0stat("/bin/env",R_OK)                = 0Starting Varnish Cache:                                    [Failed]--- SIGCHLD (Child exited) @ 0 (0) ---

有谁知道这个问题是什么?

解:

问题在于以下块:

acl purge {         if (req.http.Host ~ "playwithbits.com") {              "localhost";         }    }

acl purge只能将字符串作为值,因此如果无效.替换为:

acl purge {        "localhost";        }

它就像一个魅力.

解决方法 使用良好的配置启动清漆(default.vcl?),然后尝试在加载VCL之前对其进行语法检查.在清漆v2.1中(假设在3.x中类似):
$varnishadm -T 127.0.0.1:6082 vcl.load error <path_to_your_vcl>
总结

以上是内存溢出为你收集整理的linux – Custom VCL防止清漆启动全部内容,希望文章能够帮你解决linux – Custom VCL防止清漆启动所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/1035965.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存