1

我正在time_firstbyte尝试handling通过varnishncsa.

我的/etc/init.d/varnishncsa样子如下:-

. /lib/lsb/init-functions

NAME=varnishncsa
DESC="HTTP accelerator log deamon"
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/$NAME
PIDFILE=/run/$NAME/$NAME.pid
LOGFILE=/var/log/varnish/varnishncsa.log
USER=root
LOG_FORMAT="%t %r %s %b %{Varnish:time_firstbyte}x %{Varnish:handling}x"
#VARNISHNCSA_ENABLED=1
DAEMON_OPTS="-a -w ${LOGFILE} -D -P ${PIDFILE} -F '${LOG_FORMAT}'"

# Include defaults if available
if [ -f /etc/default/$NAME ] ; then
        . /etc/default/$NAME
fi

# If unset, or set to "0" or "no", exit
if [ -z "${VARNISHNCSA_ENABLED}" ] || \
   [ "${VARNISHNCSA_ENABLED}" = "0" ] || \
   [ "${VARNISHNCSA_ENABLED}" = "no" ]; then
  exit 0;
fi

test -x $DAEMON || exit 0

start_varnishncsa() {
    output=$(/bin/tempfile -s.varnish)
    log_daemon_msg "Starting $DESC" "$NAME"
    create_pid_directory
    if start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
        --chuid $USER --exec ${DAEMON} -- ${DAEMON_OPTS} \
        > ${output} 2>&1; then
        log_end_msg 0
    else
        log_end_msg 1
        cat $output
exit 1
    fi
    rm $output
}

stop_varnishncsa(){
    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
}

reload_varnishncsa(){
    log_daemon_msg "Reloading $DESC" "$NAME"
    if kill -HUP $(cat $PIDFILE) >/dev/null 2>&1; then
        log_end_msg 0
    else
        log_end_msg 1
        exit 1
    fi
}

status_varnishncsa(){
    status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}"
    exit $?
}

create_pid_directory() {
    install -o $USER -g $USER -d $(dirname $PIDFILE)
}

case "$1" in
    start)
        start_varnishncsa
        ;;
    stop)
        stop_varnishncsa
        ;;
    reload)
        reload_varnishncsa
        ;;
    status)
        status_varnishncsa
        ;;
    restart|force-reload)
        $0 stop
        $0 start
        ;;
    *)
        log_success_msg "Usage: $0 {start|stop|restart|force-reload|reload}"
        exit 1
        ;;
esac

我的/etc/default/varnishncsa样子如下:-

 VARNISHNCSA_ENABLED=1

但是在尝试重新启动varnishncsa时它失败了。

我在 ubuntu 12.04 和 varnish 4.1 上。

4

2 回答 2

0

根据这个链接更新我/etc/init.d/varnishncsa的如下解决了这个问题: -

LOG_FORMAT="%h|%u|%{%Y-%m-%d}t|%{%H:%M:%S}t|%{%z}t|%m|%{Host}i|%U|%q|%s|%b|%{Referer}i|%{User-agent}i|%{Varnish:time_firstbyte}x|%T|%D|%{Varnish:handling}x|%{X-FE-Varnish-Obj-TTL}o|%{X-FE-Varnish-Backend}o|%{X-FE-Varnish-Obj-Stat}o"
DAEMON_OPTS="-a -w ${LOGFILE} -D -P ${PIDFILE} -F '${LOG_FORMAT}'"
于 2016-01-06T05:51:16.823 回答
0

如果您还使用 ntp,则 %T 格式说明符可能会很棘手。因为响应时间可能非常短 - 如果时钟偏差在请求中间发生变化,您的日志文件中可能会出现负值。如果您正在对 varnishncsa 日志进行后处理,您最终可能会得到意想不到的结果。

于 2016-04-27T19:29:48.897 回答