我从 Varnish 4.0 升级到了 4.1,一开始有一个小问题,修复后就可以正常运行了。我需要清除缓存,当我重新启动 Varnish 时,它显示“正在启动”,但检查状态时它显示已停止。系统或配置没有任何变化。Varnish.log 为空,显示消息
系统:CentOS 6.7 Varnish:4.1.0-1
Nov 30 23:30:42 www varnishd[16665]: Child (16667) not responding to CLI, killing it.
Nov 30 23:30:42 www varnishd[16665]: Child (16667) died signal=11 (core dumped)
Nov 30 23:30:42 www varnishd[16665]: Child (16667) Panic message:#012 Assert error in child_sigsegv_handler(), mgt/mgt_child.c line 297:#012 Condition(Segmentation fault by instruction at 0x205970) not true.#012thread = (cache-worker)#012version = varnish-4.1.0 revision 3041728#012ident = Linux,2.6.32-573.8.1.el6.x86_64,x86_64,-junix,-smalloc,-smalloc,-hcritbit,epoll#012Backtrace:#012 0x432483: varnishd() [0x432483]#012 0x450de9: varnishd() [0x450de9]#012 0x34a480f790: libpthread.so.0() [0x34a480f790]#012 0x43c2b9: varnishd(VCL_DefaultDirector+0x19) [0x43c2b9]#012 0x436b9e: varnishd(CNT_Request+0x74e) [0x436b9e]#012 0x44cc3b: varnishd(HTTP1_Session+0x11b) [0x44cc3b]#012 0x439921: varnishd(SES_Proto_Req+0x61) [0x439921]#012 0x447aed: varnishd() [0x447aed]#012 0x447eeb: varnishd() [0x447eeb]#012 0x34a4807a51: libpthread.so.0() [0x34a4807a51]#012req = 0x7fe026896020 {#012 vxid = 2, step = R_STP_RECV,#012 req_body = R_BODY_NONE,#012 restarts = 0, esi_level = 0,#012 sp = 0x7fe02640f420 {#012 fd = 13, vxid = 1,#012 client = 180.76.15.6 56796,#012 step = S_STP_H1PROC,#012 },#012 worker = 0x7fe02d7eebc0 {#012 stack = {0x7fe02d7ef000 -> 0x7fe02d7e3000},#012 ws = 0x7fe02d7eedb8 {#012 id = "wrk",#012 {s,f,r,e} = {0x7fe02d7ee380,0x7fe02d7ee380,(nil),+2040},#012 },#012 VCL::method = none,#012 ws = 0x7fe026896200 {#012 id = "req",#012 {s,f,r,e} = {0x7fe026898000,+216,(nil),+57336},#012 },#012 http_conn = 0x7fe026896128 {#012 fd = 13,#012 doclose = NULL,#012 ws = 0x7fe026896200,#012 {rxbuf_b, rxbuf_e} = {0x7fe026898000, 0x7fe0268980b8},#012 {pipeline_b, pipeline_e} = {(nil), (nil)},#012 content_length = -1,#012 body_status = none,#012 first_byte_timeout = 0.000000,#012 between_bytes_timeout = 0.000000,#012 },#012 http[req] = 0x7fe026896298 {#012 ws[req] = 0x7fe026896200,#012 hdrs {#012 "GET",#012 "/",#012 "HTTP/1.1",#012 "Host: wsww",#012 "Accept-Lang
Nov 30 23:30:42 www varnishd[16665]: child (17228) Started
Nov 30 23:30:43 www varnishd[16665]: Pushing vcls failed:#012Could not load compiled VCL.#012#011dlopen(vcl_boot/vgc.so) = vcl_boot/vgc.so: cannot open shared object file: No such file or directory
Nov 30 23:30:44 www varnishd[16665]: Child (17228) ended
Nov 30 23:30:44 www varnishd[16665]: Child (17228) said Child starts
Nov 30 23:30:44 www varnishd[16665]: Child (17228) said Child dies
Nov 30 23:32:20 www varnishd[16665]: Manager got SIGINT
Nov 30 23:32:24 www varnishd[18670]: Platform: Linux,2.6.32-573.8.1.el6.x86_64,x86_64,-junix,-smalloc,-smalloc,-hcritbit
Nov 30 23:32:24 www varnishd[18670]: child (18672) Started
Nov 30 23:32:24 www varnishd[18670]: Child (18672) said Child starts
Nov 30 23:32:51 www varnishd[18670]: Manager got SIGINT
Nov 30 23:32:52 www varnishd[18670]: Child (18672) ended
Nov 30 23:32:52 www varnishd[18670]: Child (18672) said Child die
我的 default.vcl 在上次重新启动服务之前一直运行良好,并且是安装时附带的 default.vcl:
#
# This is an example VCL file for Varnish.
#
# It does not do anything by default, delegating control to the
# builtin VCL. The builtin VCL is called when there is no explicit
# return statement.
#
# See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/
# and http://varnish-cache.org/trac/wiki/VCLExamples for more examples.
# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you don't need,
# rewriting the request, etc.
}
sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie headers
# and other mistakes your backend does.
}
# Below is a commented-out copy of the default VCL logic. If you
# redefine any of these subroutines, the built-in logic will be
# appended to your code.
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
sub vcl_pipe {
# # Note that only the first request to the backend will have
# # X-Forwarded-For set. If you use X-Forwarded-For and want to
# # have it set for all requests, make sure to have:
set bereq.http.connection = "close";
# # here. It is not set by default as it might break some broken web
# # applications, like IIS with NTLM authentication.
return (pipe);
}
答案1
我在 centos6.5 上使用 varnish4.1 运行你的 vcl 文件(当然是在修正之后)并且可以看到:
[root@node1 ~]# ls /var/lib/varnish/node1/ -R
/var/lib/varnish/node1/:
vcl_boot _.vsm
/var/lib/varnish/node1/vcl_boot:
vgc.so
您没有此文件的原因很简单,您的 vcl 文件未正确编译。更正您的 default.vcl (您应该删除未使用的sub vcl_recv
):
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
} # <- add one more
答案2
Nov 30 23:30:43 www varnishd[16665]: Pushing vcls failed:#012Could not load compiled VCL.#012#011dlopen(vcl_boot/vgc.so) = vcl_boot/vgc.so: cannot open shared object file: No such file or directory
我不太确定这个,你能粘贴你的 .vcl 文件吗?我猜是因为你的自定义插件无法加载。
Nov 30 23:31:53 www named[2444]: error (network unreachable) resolving 'www.amazon.it/A/IN': 2001:502:4612::1#53
这一步,再次检查您的主机是否可以连接到 DNS 服务器,并能够解析 .vcl 文件中的后端名称。Varnish 在重新启动时编译 vcl 文件,并尝试将所有后端从主机名/DNS 解析为 IP,如果不成功,它将中断。