我是新的清漆。 每当我试图通过清漆访问我们的后端,我得到下面的错误:
<!DOCTYPE html> <html> <head> <title>503 Backend fetch failed</title> </head> <body> <h1>Error 503 Backend fetch failed</h1> <p>Backend fetch failed</p> <h3>Guru Meditation:</h3> <p>XID: 3</p> <hr> <p>Varnish cache server</p> </body> </html>
我的varnish.vcl如下所示: –
vcl 4.0; backend default { .host = "146.88.25.40"; .port = "8080"; }
我也试过设置first_byte_timeout = 60s .connect_timeout = 60s , first_byte_timeout = 60s和.between_bytes_timeout = 60s但是没有运气。
我的/etc/default/varnish : –
START=yes NFILES=131072 MEMLOCK=82000 DAEMON_OPTS="-a 0.0.0.0:6081 \ -T localhost:6082 \ -f /etc/varnish/varnish.vcl \ -S /etc/varnish/secret \ -s malloc,1G"
varnishlog内容: –
* << BeReq >> 3 - Begin bereq 2 fetch - Timestamp Start: 1451466805.152313 0.000000 0.000000 - BereqMethod GET - BereqURL /rde_server/res/feea8d0b3d50/recomm/home/sid/jb55653bbd980baaf37484ef70bcfcef9b84d7c680ad1b487aed1fb21ac6779025?home_tsFilter=&cat_tsFilter=%28conc.item.brand+not+in+%2836%2C4187%2C4201%2C3721%2C4103%2C4101%2C4199%2C4075%29%29%28conc.item.param1+in+%28+a - BereqProtocol HTTP/1.1 - BereqHeader User-Agent: curl/7.38.0 - BereqHeader Host: localhost:6081 - BereqHeader Accept: */* - BereqHeader X-Forwarded-For: ::1 - BereqHeader Accept-Encoding: gzip - BereqHeader X-Varnish: 3 - VCL_call BACKEND_FETCH - VCL_return fetch - FetchError no backend connection - Timestamp Beresp: 1451466805.152502 0.000189 0.000189 - Timestamp Error: 1451466805.152511 0.000198 0.000009 - BerespProtocol HTTP/1.1 - BerespStatus 503 - BerespReason Service Unavailable - BerespReason Backend fetch failed - BerespHeader Date: Wed, 30 Dec 2015 09:13:25 GMT - BerespHeader Server: Varnish - VCL_call BACKEND_ERROR - BerespHeader Content-Type: text/html; charset=utf-8 - BerespHeader Retry-After: 5 - VCL_return deliver - Storage malloc Transient - ObjProtocol HTTP/1.1 - ObjStatus 503 - ObjReason Backend fetch failed - ObjHeader Date: Wed, 30 Dec 2015 09:13:25 GMT - ObjHeader Server: Varnish - ObjHeader Content-Type: text/html; charset=utf-8 - ObjHeader Retry-After: 5 - Length 278 - BereqAcct 0 0 0 0 0 0 - End * << Request >> 2 - Begin req 1 rxreq - Timestamp Start: 1451466805.152189 0.000000 0.000000 - Timestamp Req: 1451466805.152189 0.000000 0.000000 - ReqStart ::1 44193 - ReqMethod GET - ReqURL /rde_server/res/feea8d0b3d50/recomm/home/sid/jb55653bbd980baaf37484ef70bcfcef9b84d7c680ad1b487aed1fb21ac6779025?home_tsFilter=&cat_tsFilter=%28conc.item.brand+not+in+%2836%2C4187%2C4201%2C3721%2C4103%2C4101%2C4199%2C4075%29%29%28conc.item.param1+in+%28+a - ReqProtocol HTTP/1.1 - ReqHeader User-Agent: curl/7.38.0 - ReqHeader Host: localhost:6081 - ReqHeader Accept: */* - ReqHeader X-Forwarded-For: ::1 - VCL_call RECV - VCL_return hash - VCL_call HASH - VCL_return lookup - VCL_call MISS - VCL_return fetch - Link bereq 3 fetch - Timestamp Fetch: 1451466805.152650 0.000461 0.000461 - RespProtocol HTTP/1.1 - RespStatus 503 - RespReason Backend fetch failed - RespHeader Date: Wed, 30 Dec 2015 09:13:25 GMT - RespHeader Server: Varnish - RespHeader Content-Type: text/html; charset=utf-8 - RespHeader Retry-After: 5 - RespHeader X-Varnish: 2 - RespHeader Age: 0 - RespHeader Via: 1.1 varnish-v4 - VCL_call DELIVER - VCL_return deliver - Timestamp Process: 1451466805.152718 0.000529 0.000068 - RespHeader Content-Length: 278 - Debug "RES_MODE 2" - RespHeader Connection: keep-alive - Timestamp Resp: 1451466805.152773 0.000584 0.000055 - ReqAcct 386 0 386 235 278 513 - End * << Session >> 1 - Begin sess 0 HTTP/1 - SessOpen ::1 44193 :6081 ::1 6081 1451466805.152117 14 - Link req 2 rxreq - SessClose REM_CLOSE 0.001 - End
如果我开始清漆如下,那么也一切工作正常。 只有当我通过sudo service varnish start清漆时,我才面临问题
sudo varnishd -n foo -f /etc/varnish/prudsys.vcl -s malloc,1G -T localhost:6082 -a 0.0.0.0:6081
一切工作正常,如果我在/etc/varnish/default.vcl添加我的backend信息。 这似乎不知道清漆是不是从/etc/default/varnishselect更新后的守护进程configuration
我的/etc/init.d/varnish如下所示: –
#! /bin/sh ### BEGIN INIT INFO # Provides: varnish # Required-Start: $local_fs $remote_fs $network # Required-Stop: $local_fs $remote_fs $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start HTTP accelerator # Description: This script provides a server-side cache # to be run in front of a httpd and should # listen on port 80 on a properly configured # system ### END INIT INFO # Source function library . /lib/lsb/init-functions NAME=varnishd DESC="HTTP accelerator" PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/varnishd PIDFILE=/run/$NAME.pid test -x $DAEMON || exit 0 # Include varnish defaults if available if [ -f /etc/default/varnish ] ; then . /etc/default/varnish fi # Open files (usually 1024, which is way too small for varnish) ulimit -n ${NFILES:-131072} # Maxiumum locked memory size for shared memory log ulimit -l ${MEMLOCK:-82000} # If $DAEMON_OPTS is not set at all in /etc/default/varnish, use minimal useful # defaults (Backend at localhost:8080, a common place to put a locally # installed application server.) DAEMON_OPTS=${DAEMON_OPTS:--b localhost} # Ensure we have a PATH export PATH="${PATH:+$PATH:}/usr/sbin:/usr/bin:/sbin:/bin" start_varnishd() { log_daemon_msg "Starting $DESC" "$NAME" output=$(/bin/tempfile -s.varnish) if start-stop-daemon \ --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- \ -P ${PIDFILE} ${DAEMON_OPTS} > ${output} 2>&1; then log_end_msg 0 else log_end_msg 1 cat $output exit 1 fi rm $output } disabled_varnishd() { log_daemon_msg "Not starting $DESC" "$NAME" log_progress_msg "disabled in /etc/default/varnish" log_end_msg 0 } stop_varnishd() { log_daemon_msg "Stopping $DESC" "$NAME" if start-stop-daemon \ --stop --quiet --pidfile $PIDFILE --retry 10 \ --exec $DAEMON; then log_end_msg 0 else log_end_msg 1 fi if test -r $PIDFILE; then read -r PID < $PIDFILE if test ! -d /proc/$PID ; then # stale pidfile unset PID rm -f $PIDFILE fi fi } reload_varnishd() { log_daemon_msg "Reloading $DESC" "$NAME" if /usr/share/varnish/reload-vcl -q; then log_end_msg 0 else log_end_msg 1 fi } status_varnishd() { start-stop-daemon \ --status --quiet --pidfile $PIDFILE \ --exec $DAEMON exit $? } configtest() { $DAEMON ${DAEMON_OPTS} -C -n /tmp 2>/dev/null if [ "$?" != 0 ]; then $DAEMON ${DAEMON_OPTS} -C -n /tmp return $? fi } case "$1" in start) case "${START:-}" in [Yy]es|[Yy]|1|[Tt]|[Tt]rue) start_varnishd ;; *) disabled_varnishd ;; esac ;; stop) stop_varnishd ;; reload) reload_varnishd ;; status) status_varnishd ;; restart|force-reload) if status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}" 1>/dev/null; then if ! configtest; then log_failure_msg "Syntax check failed, not restarting" exit 1 fi fi $0 stop $0 start ;; configtest) configtest && log_success_msg "Syntax ok" ;; *) log_success_msg "Usage: $0 {start|stop|restart|reload|force-reload|configtest}" exit 1 ;; esac
有人能告诉我发生了什么事吗? 我在Debian 8上使用了清漆4.1。
这是Debian 8和Varnish的问题。 按照本博客中提到的步骤,我能够解决问题。
覆盖varnish的systemd初始化脚本
# cp /lib/systemd/system/varnish.service /etc/systemd/system/ # vim /etc/systemd/system/varnish.service
直接编辑/etc/systemd/system/varnish.service ,如下所示:
[Unit] Description=Varnish Cache, a high-performance HTTP accelerator [Service] Type=forking LimitNOFILE=131072 LimitMEMLOCK=82000 ExecStartPre=/usr/sbin/varnishd -C -f /etc/varnish/prudsys.vcl ExecStart=/usr/sbin/varnishd -a :6081 -T localhost:6082 -f /etc/varnish/prudsys.vcl -S /etc/varnish/secret -s malloc,1G ExecReload=/usr/share/varnish/reload-vcl [Install] WantedBy=multi-user.target
重新启动服务:
systemctl daemon-reload systemctl restart varnish.service
请记住在所有三个地方做出改变:
/etc/default/varnish /lib/systemd/system/varnish.service /etc/systemd/system/varnish.service