【问题标题】:Varnish ignores settings in /etc/default/varnishVarnish 忽略 /etc/default/varnish 中的设置
【发布时间】:2017-05-23 03:50:36
【问题描述】:

Varnish 4.1.1 完全忽略了 Ubuntu 16.04 LTS 上 /etc/default/varnish 文件中的设置。我正在寻找解决方案。

/bin/systemctl status varnish.service的结果

Warning: Journal has been rotated since unit was started. Log output is incomple
lines 1-14/14 (END)
● varnish.service - Varnish HTTP accelerator
   Loaded: loaded (/lib/systemd/system/varnish.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2017-01-09 01:24:09 UTC; 15h ago
     Docs: https://www.varnish-cache.org/docs/4.1/
           man:varnishd
 Main PID: 9470 (varnishd)
    Tasks: 218
   Memory: 67.5M
      CPU: 45.584s
   CGroup: /system.slice/varnish.service
           ├─9470 /usr/sbin/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret
           └─9483 /usr/sbin/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

【问题讨论】:

  • 你能把/bin/systemctl status varnish.service的输出和/usr/lib/systemd/system/varnish.service的内容贴出来吗?

标签: ubuntu varnish


【解决方案1】:

这显然是上游 Debian 的故意行为:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=749272

/etc/default/varnish 被 /etc/init.d/varnish 专门使用。

"如果你想自己使用/etc/default/varnish,你可以覆盖 /lib/systemd/system/varnish.service 在 /etc/systemd/system/varnish.service 中,但我建议你只在 /etc/systemd/system/varnish.service,而不是读取 /etc/default/varnish"

varnish.service 是 .INI 格式。本教程以 Debian 为例:http://deshack.net/how-to-varnish-listen-port-80-systemd/

Varnish 已在官方文档中添加:

https://www.varnish-cache.org/docs/trunk/tutorial/putting_varnish_on_port_80.html#debian-v8-ubuntu-v15-04

例如我刚刚在 16.04 上设置的 Varnish 上的 varnish.service 有这一行(该框称为 cache1):

ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -s file,/var/lib/varnish/cache1/varnish_storage.bin,85G -n cache1

一旦你改变了这个不要忘记重新加载systemd:

systemctl daemon-reload

然后重启 Varnish。使用 /bin/systemctl status varnish.service 检查您的结果。

tl;dr你需要把你的配置放在两个地方。

【讨论】:

    【解决方案2】:

    在 ubuntu 19.04 上:

    sudo vi /etc/systemd/system/multi-user.target.wants/varnish.service(更改端口)

    sudo systemctl daemon-reload && sudo systemctl restart varnish && sudo systemctl status varnish

    卷曲本地主机

    【讨论】:

      【解决方案3】:

      默认情况下Varnish 将尝试加载位于此路径/etc/varnish/default.vcldefault.vcl,如您在此处看到的:

      CGroup: /system.slice/varnish.service
                 ├─9470 /usr/sbin/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret
                 └─9483 /usr/sbin/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret
      

      如果您想加载另一个位于另一个路径的文件,则需要打开此文件/etc/varnish/varnish.params 并修改此行的值:

      # Main configuration file. You probably want to change it.                       
      VARNISH_VCL_CONF=/etc/varnish/default.vcl
      

      这适用于 Varnish 4+

      【讨论】:

      • 我有与 varnish 5 相同的问题,/etc/varnish 文件夹中没有文件“varnish.params”。我修改了 default.vcl 文件,但我的清漆没有启动
      • 根据 CentOS 上最新版本的 Varnish ,rpm 包含 /etc/varnish/varnish.params 所以它应该存在。并且确定它对于 ubuntu 是一样的,这个命令的输出是什么:varnishd ~d ~f /etc/varnish/default.vcl
      • 感谢您的回答,输出为:错误:来自 VCC 编译器的消息:缺少 VCL 版本声明\n将您的 VCL 更新为版本 4 语法,并添加\n vcl 4.0;\非第一个行 VCL 文件。\n('/etc/varnish/default.vcl' Line 12 Pos 1)\nbackend default {\n#######----------\n运行 VCC-编译器失败,退出 2\nVCL 编译失败但我发现我的错误,项目在 Varnish 3.0.5 上,我有 Varnish 4.1.1
      猜你喜欢
      • 2015-08-17
      • 1970-01-01
      • 2016-11-11
      • 2013-12-29
      • 2014-05-21
      • 2014-12-31
      • 2018-11-14
      • 2013-12-03
      • 2013-01-23
      相关资源
      最近更新 更多