gpt4 book ai didi

Varnish 不会作为守护进程启动

转载 作者:行者123 更新时间:2023-12-03 17:44:50 24 4
gpt4 key购买 nike

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 上。有什么想法吗?

更新(版本、syslog 和 systemd):

版本:

# varnishd -V
varnishd (varnish-4.1.1 revision 66bb824)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2015 Varnish Software AS

这是系统日志:

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

最佳答案

我遇到了完全相同的问题,将我的生产环境转移到一个不那么...古老的 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 特权 jail (更多信息请参见:https://www.varnish-cache.org/docs/4.1/reference/varnishd.html?highlight=jail#jail)。

关于Varnish 不会作为守护进程启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40867749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com