Varnish无法作为守护进程启动。

3

Varnish无法启动,使用以下方法:

service varnish start

没有任何错误,但当我执行时运行良好。
varnishd -f /etc/varnish/user.vcl -s malloc,1G -T localhost:6082  -a 0.0.0.0:6081 -d

这是/etc/default/varnish文件:
START=yes
NFILES=131072
MEMLOCK=82000

DAEMON_OPTS="-a 0.0.0.0:6081 \
         -T localhost:6082 \
         -f /etc/varnish/user.vcl \
         -S /etc/varnish/secret \
         -s malloc,1024m"

我在Ubuntu 16.04上。有什么想法吗?
更新(版本,系统日志和systemd):
版本:
# varnishd -V
varnishd (varnish-4.1.1 revision 66bb824)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2015 Varnish Software AS

这是“系统日志”(syslog):
Nov 30 14:16:46 **** systemd[1]: Started Varnish HTTP accelerator.
Nov 30 14:16:46 **** varnishd[28089]: Error: Cannot open socket: :6081: Address family not supported by protocol
Nov 30 14:16:46 **** systemd[1]: varnish.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Nov 30 14:16:46 **** systemd[1]: varnish.service: Unit entered failed state.
Nov 30 14:16:46 **** systemd[1]: varnish.service: Failed with result 'exit-code'.

/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 > /dev/null
}



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

如果您正在使用sysctl,请问/usr/lib/systemd/system/varnish.service文件的内容是什么?如果您正在使用system.d,请问/etc/init.d/varnish文件的内容是什么?无论哪种方式,/etc/varnish/varnish.params文件的内容是什么? - Benjamin Baumann
谢谢,我更新了我的问题。我没有/etc/varnish/varnish.params文件。 - user3170702
3个回答

3

我在将生产环境迁移到一个较旧的Opsworks/Chef堆栈和Ubuntu时,遇到了完全相同的问题。

事实证明,Varnish网站上的文档对于Ubuntu 16+来说并不是完整的,您需要几个其他命令行开关。这是适用于我工作的内容:

[Service]
ExecStart=
ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m

-F开关将其移入前台,我发现这有助于systemctl服务的运行。

-j开关启用Varnish特权监狱(更多信息请参见:https://www.varnish-cache.org/docs/4.1/reference/varnishd.html?highlight=jail#jail)。


这并没有解决问题,只是增加了更多的“最佳实践”说教。 - Aries

0

-1

似乎不喜欢用 0.0.0.0:6081 地址作为管理部分。

Nov 30 14:16:46 **** varnishd[28089]: Error: Cannot open socket: :6081: Address family not supported by protocol

将您的daemon_opt部分更改为-a :80,位于/etc/default/varnish中。

文件“/etc/default/varnish”在Ubuntu 16.04上不再使用。请参见https://github.com/varnish/Varnish-Cache/pull/92。 - Wouter
我要求请求者提供他正在使用的init.d或systemd脚本。他编辑了他的问题,给出了它的init.d脚本,其中引用了/etc/default/varnish。此外,他似乎没有varnish.param文件,所以我建议他进行更改。 - Benjamin Baumann

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接