我刚刚安装了全新安装的 Ubuntu 16.04,但无法让 Varnish 使用自定义配置文件,就像使用 Ubuntu 14.04 一样。
I have read更改为 /etc/default/varnish
没有效果,因为它使用 systemd 而不是 init.d。
于是流程变成了编辑/lib/systemd/system/varnish.service
:
[Unit]
Description=Varnish HTTP accelerator
Documentation=https://www.varnish-cache.org/docs/4.1/ man:varnishd
[Service]
Type=simple
LimitNOFILE=131072
LimitMEMLOCK=82000
ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
ExecReload=/usr/share/varnish/reload-vcl
ProtectSystem=full
ProtectHome=true
PrivateTmp=true
PrivateDevices=true
[Install]
WantedBy=multi-user.target
现在我想用一个自定义的 vcl(在我正在处理的 git 存储库中)交换 default.vcl。所以我将 ExecStart 中的行更改为
-f /home/bozdoz/path/to/default.vcl
,并且在重新加载守护程序并重新启动服务后出现以下错误:>> sudo systemctl status varnish.service
● varnish.service - Varnish HTTP accelerator
Loaded: loaded (/lib/systemd/system/varnish.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2016-09-07 14:29:58 ADT; 5s ago
Docs: https://www.varnish-cache.org/docs/4.1/
man:varnishd
Process: 7588 ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f /home/bozdoz/path/to/default.vcl
Main PID: 7588 (code=exited, status=2)
Sep 07 14:29:58 bozdoz-dell systemd[1]: Started Varnish HTTP accelerator.
Sep 07 14:29:58 bozdoz-dell varnishd[7588]: Error: Cannot read -f file (/home/bozdoz/path/to/default.vcl)
我尝试将自定义文件的权限更改为由 varnish 或 vcache 拥有,但都没有成功。我曾尝试打开 777 的权限(仅用于测试目的),但仍然失败。
另请注意,如果我将自定义文件复制到
/etc/varnish/default.vcl
, Varnish 工作得非常好。 ;问题是我希望文件位于 git 存储库中,但 Varnish 服务似乎无法访问自定义文件。如何使用 systemd 在另一个目录中使用自定义文件?
最佳答案
我怀疑 /home/bozdoz
上的权限或 /home/bozdoz
之间的中间目录之一和 default.vcl
是什么给了你这个权限被拒绝的错误。
如果我可以提出更一般的建议,那么修改 /lib/systemd/system
中的服务文件是不好的做法。 .如果 Varnish 包被更新,它可能会覆盖您的更改。相反,您有两个选择:
/lib/systemd/system/varnish.service
至/etc/systemd/system/varnish.service
并在那里进行更改/etc/systemd/system/varnish.service.d/override.conf
并在那里应用增量 override.conf
看起来像这样:ExecStart=
ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f /home/bozdoz/path/to/default.vcl -S /etc/varnish/secret -s malloc,256m
第一条语句清除现有的 ExecStart 指令,第二条语句设置一个新指令。
关于ubuntu - Ubuntu 16 上的 Varnish 无法读取 -f 文件自定义 default.vcl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39376483/