Jac*_*cob 5 daemon options varnish
当使用带有Varnish的内联C时,我无法让/ etc/varnish/default
在启动时感到满意.
我已经测试了带有清漆的内联C两件事:GeoIP检测和Anti-Site-Scraping功能.
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'
Run Code Online (Sandbox Code Playgroud)
但它尝试从默认启动脚本启动时出错:
/ 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'"
Run Code Online (Sandbox Code Playgroud)
错误是:
# /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".
Run Code Online (Sandbox Code Playgroud)
如果我尝试将最后一行更改为:
-p cc_command='exec cc -fpic -shared -Wl,-x -L/usr/include/libmemcached/memcached.h -lmemcached -o %o %s'"
Run Code Online (Sandbox Code Playgroud)
这是错误现在:
# /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"
Run Code Online (Sandbox Code Playgroud)
它试图将'-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.
任何人都可以帮助指出这里出了什么问题吗?
非常感谢!
Cos*_*imo 10
即使雅各布可能永远不会读到这个,未来的访客也会欣赏我要写的东西.
我相信我知道什么是错的,它看起来像Debian特定的问题,至少在Ubuntu 11.04和Debian Squeeze上验证过.
我跟踪了/etc/default/varnish包含$DAEMON_OPTSinit脚本的执行.在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中.而且,惊喜!有效.WTF?
再次重复以确定.是的,它有效.MMH.它可能是那些bash/dash角落案件中的另一个吗?让我们尝试将start-stop-daemon命令行提供给bash,并看看它是如何反应的:
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传递$DAEMON_OPTSvar 的事实,dash这将导致错位的选项.
会是这样的:
-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 $@
但它不起作用,所以只需修补你的init脚本,你就可以了!希望您能发现此信息有用.
显然,解释 DAEMON_OPTS 的启动脚本没有准备好空格(即使在单引号内)。在我的 Fedora (15) 安装中,建议的解决方案工作正常;参数得到正确解释,因为"$*"bash 参数是在 /etc/init.d/varnish 和 /etc/init.d/functions 中传递的daemon()。
您是从包中获取启动脚本还是制作了自定义脚本?