daemon - Varnish DAEMON_OPTS 选项错误

标签 daemon varnish

当使用内联 C 和 Varnish 时,我无法获取/etc/varnish/default
在启动时感到高兴。

我已经用 varnish 测试了内联 C 的两件事:GeoIP 检测和反站点抓取功能。

即使我遵循其他看起来的内容,DAEMON_OPTS 总是提示
表明工作正常。

我的问题是这个命令行启动有效:

varnishd -f /etc/varnish/varnish-default.conf -s file,/var/lib/varnish/varnish_storage.bin,512M -T 127.0.0.1:2000 -a 0.0.0.0:8080 -p 'cc_command=exec cc -fpic -shared -Wl,-x -L/usr/include/libmemcached/memcached.h -lmemcached -o %o %s'

但是尝试从默认启动脚本启动时出错:

/etc/default/varnish 中有这样的内容:

DAEMON_OPTS="-a :8080 \
             -T localhost:2000 \
             -f /etc/varnish/varnish-default.conf \
             -s file,/var/lib/varnish/varnish_storage.bin,512M \
             -p 'cc_command=exec cc -fpic -shared -Wl,-x -L/usr/include/libmemcached/memcached.h -lmemcached -o %o %s'"

错误是:

# /etc/init.d/varnish start
Starting HTTP accelerator: varnishd failed!
storage_file: filename: /var/lib/varnish/vbox.local/varnish_storage.bin size 512 MB.
Error:
Unknown parameter "'cc_command".

如果我尝试将最后一行更改为:

-p cc_command='exec cc -fpic -shared -Wl,-x -L/usr/include/libmemcached/memcached.h -lmemcached -o %o %s'"

现在的错误是:

# /etc/init.d/varnish start
Starting HTTP accelerator: varnishd failed!
storage_file: filename: /var/lib/varnish/vbox.local/varnish_storage.bin size 512 MB.
Error: Unknown storage method "hared"

它试图将“-shared”解释为 -s hared,而“hared”不是存储类型。

对于 GeoIP 和 Anti-Site-Scrape,我已经使用了推荐的确切守护进程选项
plus 尝试了各种变体,例如添加 ' 和 '' 但没有任何乐趣。

这是我遵循的说明的链接,除了 DAEMON_OPTS 部分之外,该说明工作正常。
http://drcarter.info/2010/04/how-fighting-against-scraping-using-varnish-vcl-inline-c-memcached/

我正在使用 Debian 和说明中所述的确切 DAEMON_OPTS。

任何人都可以帮忙指出这里出了什么问题吗?

最佳答案

即使雅各布可能永远不会读到这篇文章,来自 future 的访客可能会欣赏我将要写的内容。

我相信我知道出了什么问题,而且它看起来像是 Debian 特有的问题,至少在 Ubuntu 11.04 和 Debian Squeeze 上得到了验证。

我跟踪了从包含 $DAEMON_OPTS/etc/default/varnish 到 init 脚本的执行情况。 在初始化脚本/etc/init.d/varnish中,start_varnishd()函数为:

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
}

所以我修改了它以打印完整的 start-stop-daemon 命令行,例如:

 start_varnishd() {
    log_daemon_msg "Starting $DESC" "$NAME"
    output=$(/bin/tempfile -s.varnish)
+   echo "start-stop-daemon --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- -P ${PIDFILE} ${DAEMON_OPTS} > ${output} 2>&1"
    if start-stop-daemon \
        --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- \
        -P ${PIDFILE} ${DAEMON_OPTS} > ${output} 2>&1; then
        log_end_msg 0

所以我在 STDOUT 上得到了一条命令行回显,并将其复制粘贴到我的 shell 中。而且,惊喜!有效。 什么鬼?

再次重复以确定。是的,它有效。嗯。这可能是另一个 bash/dash 极端情况吗? 让我们尝试将 start-stop-daemon 命令行输入到 bash,看看它的 react 如何:

start_varnishd() {
    log_daemon_msg "Starting $DESC" "$NAME"
    output=$(/bin/tempfile -s.varnish)
    if bash -c "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
}

是的,它工作得很好,至少对于我来说是这样。 这是我的 /etc/default/varnish 的相关部分:

...
## Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# one content server selected by the vcl file, based on the request.  Use a 1GB
# fixed-size cache file.
#
DAEMON_OPTS="-a :6081 \
             -T localhost:6082 \
             -f /etc/varnish/geoip-example.vcl \
             -S /etc/varnish/secret \
             -s malloc,100M \
             -p 'cc_command=exec cc -fpic -shared -Wl,-x -L/usr/include/GeoIP.h -lGeoIP -o %o %s'"
...

我见过有人试图通过将编译命令移动到单独的 shell 脚本中来解决这个问题的帖子。不幸的是,这并没有改变 start-stop-daemon 将通过 dash 传递 $DAEMON_OPTS var 的事实,这将导致在损坏的选项中。

大概是这样的:

-p 'cc_command=exec /etc/varnish/compile.sh %o %s'"

然后 compile.sh 脚本如下:

#!/bin/sh
cc -fpic -shared -Wl,-x -L/usr/include/GeoIP.h -lGeoIP -o $@

但它不起作用,所以只需修补你的初始化脚本,然后就可以开始了! 希望您会发现此信息有用。

关于daemon - Varnish DAEMON_OPTS 选项错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5906603/

相关文章:

Nginx 和 runit ......什么是最佳实践

java - 管理守护线程池

php - 频繁使用网站的缓存策略

caching - 缓存控制无法在chrome和 Varnish 中运行,也未遵守缓存控制

varnish - 通过varnishadm禁用 Varnish 健康检查

php - 我可以启动一个脚本,使其独立于 Linux 上的父进程吗?

Perl 守护进程不使用 Sleep()

macos - 如何在 FreeBSD(和 macOS)中守护 shell 脚本

linux - Varnish +nginx+ISPConfig

caching - 如何在 Varnish 中操作 ESI URL 以包含用户特定的上下文?