Ubuntu

清漆守護程序未在配置的埠上偵聽

  • November 18, 2020

我正在嘗試在 ubuntu 16.04 上安裝清漆,

我讀了幾篇文章都沒有工作。根據我的閱讀,從 ubuntu 15.04 開始,配置 varnish 的方式發生了變化(因為 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.vcl,那麼start,一切正常……直到我退出 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文件中,我發現的其他線上資源讓我覺得它在其他地方,所以要小心線上(過時的)教程!

您還需要更改 systemd 服務定義中的清漆啟動參數。ExecStart您可以在服務定義文件中編輯以開頭的行:

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

然而,修改這個文件的缺點是它不會在以後的包更新中被更新。或者,正如評論中所建議的,您可以在 file 中創建一個 systemd drop,這是將設置添加到 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。

引用自:https://serverfault.com/questions/824389