【问题标题】:Varnish DAEMON_OPTS Options ErrorsVarnish DAEMON_OPTS 选项错误
【发布时间】:2011-08-19 21:08:03
【问题描述】:

当使用带有 Varnish 的内联 C 时,我无法获得 /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,我使用了确切推荐的守护程序选项
另外尝试了各种变体,例如添加 \' 和 '' 但没有任何乐趣。

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

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

谁能帮忙指点一下这里出了什么问题?

非常感谢!

【问题讨论】:

    标签: daemon options varnish


    【解决方案1】:

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

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

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

    start_varnishd() { log_daemon_msg "开始 $DESC" "$NAME" 输出=$(/bin/tempfile -s.varnish) 如果启动-停止-守护程序\ --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- \ -P ${PIDFILE} ${DAEMON_OPTS} > ${输出} 2>&1;然后 log_end_msg 0 别的 log_end_msg 1 猫$输出 1号出口 菲 rm $输出 }

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

    start_varnishd() { log_daemon_msg "开始 $DESC" "$NAME" 输出=$(/bin/tempfile -s.varnish) + echo "start-stop-daemon --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- -P ${PIDFILE} ${DAEMON_OPTS} > ${output} 2>&1" 如果启动-停止-守护程序\ --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- \ -P ${PIDFILE} ${DAEMON_OPTS} > ${输出} 2>&1;然后 log_end_msg 0

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

    再次重复以确保。是的,它有效。嗯。会不会是另一种 bash/dash 极端案例? 让我们尝试将 start-stop-daemon 命令行输入到bash,看看它的反应:

    start_varnishd() { log_daemon_msg "开始 $DESC" "$NAME" 输出=$(/bin/tempfile -s.varnish) if bash -c "启动-停止-守护进程\ --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- \ -P ${PIDFILE} ${DAEMON_OPTS} > ${output} 2>&1"; 然后 log_end_msg 0 别的 log_end_msg 1 猫$输出 1号出口 菲 rm $输出 }

    是的,效果很好,至少对我来说是这样。 这是我/etc/default/varnish的相关部分:

    ... ## 备选方案 2,使用 VCL 进行配置 # # 监听 6081 端口,管理 localhost:6082,转发到 # 一个由 vcl 文件根据请求选择的内容服务器。使用 1GB # 固定大小的缓存文件。 # DAEMON_OPTS="-a :6081 \ -T 本地主机:6082 \ -f /etc/varnish/geoip-example.vcl \ -S /etc/清漆/秘密\ -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 $@

    但它不起作用,所以只需修补你的初始化脚本,你就可以开始了! 希望这些信息对您有用。

    【讨论】:

    • 可能有一种特殊的语法或解决方法可以使这个在 dash 上也能工作。不幸的是,我对 dash 了解不多。
    • 我不得不说我不明白故事结尾处提出的解决方案是什么...... :-|
    • 这个答案有效!太感谢了!建议的解决方案是使用 bash 修补 /etc/init.d/varnish
    • 也为我工作。谢谢!
    【解决方案2】:

    您可以尝试使用:- DAEMON_OPTS="-a :8080 \ -T 本地主机:2000 \ -f /etc/varnish/varnish-default.conf \ -s 文件,/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'"

    【讨论】:

      【解决方案3】:

      显然,解释 DAEMON_OPTS 的启动脚本没有准备好空格(即使在单引号内)。在我的 Fedora (15) 安装中,建议的解决方案运行良好;参数得到正确解释,因为 "$*" bash 参数在 /etc/init.d/varnish 和 /etc/init.d/functions 中的 daemon() 中传递。

      您是从包中获取启动脚本还是制作了自定义脚本?

      【讨论】:

        【解决方案4】:

        这与问题没有直接关系,但如果您正在处理Varnish Tutorial - Put Varnish on port 80,您可能会发现自己在这里。

        对于最近在 Debian 系统上安装的 Varnish,varnishd 启动选项的配置可以在 /etc/systemd/system/multi-user.target.wants/varnish.service 中找到。通过/etc/default/varnish 更改端口的记录方法仍然存在,但不再起作用,除非您将系统更改为使用init 脚本而不是systemd

        在您更改/etc/systemd/system/multi-user.target.wants/varnish.service 中的选项后,别忘了运行systemctl daemon-reload,它会编目执行程序的更改。

        【讨论】:

          猜你喜欢
          • 2015-08-17
          • 1970-01-01
          • 2014-04-28
          • 2020-06-03
          • 2013-04-12
          • 2012-06-16
          • 2018-05-01
          • 2013-12-03
          • 1970-01-01
          相关资源
          最近更新 更多