Varnish 忽略 /etc/default/varnish 中的设置

Varnish ignores settings in /etc/default/varnish

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.

默认情况下 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+

这显然是上游 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 你需要把你的配置放在两个 地方。

在 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

卷曲本地主机