清漆守护程序未在配置的端口上侦听


11

我正在尝试在Ubuntu 16.04上安装清漆,

我读了几篇文章都没有用。从我阅读的内容来看,自ubuntu 15.04起,配置清漆的方式已更改(由于systemd)。

现在,我陷入困境,这是行不通的:


/ etc / default / varnish:

DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"

/etc/varnish/default.vcl(通常指向指向127.0.0和端口8080的主机,但出于调试目的,我将其修改为外部域)vcl 4.0;

# Default backend definition. Set this to point to your content server.
backend default {
    .host = "www.varnish-cache.org"; 
    .port = "80";
}

/etc/apache2/ports.conf

Listen 8080

grep -R 'ExecStart=/usr/sbin/varnishd' /etc/

/etc/systemd/system/varnish.service:ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
/etc/systemd/system/varnish.service.d/customexec.conf:ExecStart=/usr/sbin/varnishd -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
/etc/systemd/system/multi-user.target.wants/varnish.service:ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m

/lib/systemd/system/varnish.service:

  GNU nano 2.5.3                                                Fichier : /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 :80 -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

service --status-all | grep varnish

 [ - ]  varnish
 [ + ]  varnishlog
 [ + ]  varnishncsa

之后

sudo service varnish stop
sudo service varnish start

清漆服务没有监听http://127.0.0.1:80/,在重新启动之前,它已经监听了,http://127.0.0.1:6081/但是它不再起作用了……我不知道该怎么做……




编辑:重新启动后,没有任何效果,

如果我做 : systemctl status varnish

● varnish.service - Varnish HTTP accelerator
   Loaded: loaded (/etc/systemd/system/varnish.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/varnish.service.d
           └─customexec.conf
   Active: inactive (dead) since jeu. 2017-01-05 14:48:09 CET; 1s ago
     Docs: https://www.varnish-cache.org/docs/4.1/
           man:varnishd
  Process: 5077 ExecStart=/usr/sbin/varnishd -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m (code=exited, status=0/SUCCESS)
 Main PID: 5077 (code=exited, status=0/SUCCESS)

janv. 05 14:48:09 xubuntu-16 systemd[1]: Started Varnish HTTP accelerator.

service --status-all | grep varnish

 [ - ]  varnish
 [ - ]  varnishlog
 [ - ]  varnishncsa

如果我sudo:,varnishd -d -f /etc/varnish/default.vclstart一切正常...直到我退出cli


@Gerald Schneider的回复解决了。我发布了必须要做的步骤:

sudo apt remove varnish
sudo apt-get purge varnish
# I manually remove the 3 files in created in /etc/systemd/system/*
sudo apt install varnish
sudo nano /lib/systemd/system/varnish.service # put the rigth conf
sudo nano /etc/varnish/default.vcl #put the rigth conf
sudo systemctl daemon-reload
sudo service varnish restart

一切正常!魔力在/lib/systemd/system/varnish.service文件中,我发现的其他在线资源使我觉得它在其他地方,所以请当心在线(过时的)教程!


可能只需要删除先前的->即可。/etc/systemd/system/varnish.service
Mike Q

Answers:


17

您还需要在systemd服务定义中更改清漆开始参数。您可以ExecStart在服务定义文件中编辑以开头的行:

sudo vi /lib/systemd/system/varnish.service

但是,修改此文件具有以下缺点:在以后的程序包更新中将不会对其进行更新。另外,如注释中所建议,您可以在file中创建systemd放置,这是将设置添加到systemd定义的首选方法。

# create the drop in directory
sudo mkdir /etc/systemd/system/varnish.service.d
# create the drop in file. The name is irrelevant, as long as it ends in .conf
sudo vi /etc/systemd/system/varnish.service.d/mysettings.conf

在这里,您只需要添加要更改的设置,其他所有内容将从默认定义文件中加载。

例:

[Service]
ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m

这是默认行,根据需要更改

然后,告诉systemctl重新加载它的配置文件并重新启动服务

sudo systemctl daemon-reload
sudo service varnish restart

Varnish现在应该在端口80上侦听。


我已经做到了,这个文件包含:[...] [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 :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m ExecReload=/usr/share/varnish/reload-vcl [...]
Bruno

也许您应该恢复apache和varnish的默认配置文件并重新开始。我已经对其进行了测试,并且只需要更改apache配置即可侦听端口8080和varnish.service中的单行。没有其他的。
Gerald Schneider

谢谢,成功了!我在帖子中添加了要卸载的步骤
Bruno

这是错误的方法。/ lib / systemd中的systemd单元文件不应进行编辑,而应使用/ etc / systemd中的嵌入式文件覆盖它们
Stephen

1
systemctl edit varnish.service 自动为您创建单位文件替代插件
HBruijn

5

请注意,该插件应具有一个空的ExecStart =,否则您将在启动服务时收到错误消息(重复的ExecStart)

sudo mkdir /etc/systemd/system/varnish.service.d
sudo nano /etc/systemd/system/varnish.service.d/varnishd.conf

[Service]
ExecStart=
ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T <YOUR WEBSERVER IP>:8081 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.