在Debian上安装Varnish以后,无法运行在80端口,我琢磨了一会才成功,做法:
1,编辑/etc/default/varnish,修改两处,第一个是
DAEMON_OPTS="-a :6081 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,128m"
把6081改为80,第二个是增加一行:
VARNISH_LISTEN_PORT=80
2,首先创建一个目录
mkdir /etc/systemd/system/varnish.service.d
然后编辑一个文件,如果用vi的话需要先创建
nano /etc/systemd/system/varnish.service.d/customexec.conf
内容:
[Service] ExecStart=ExecStart=/usr/sbin/varnishd -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,128m
完成以后重启一下varnish就好了
/etc/init.d/varnish restart
后续补充(2016.08.14):
今天新装了个节点,经上述步骤以后,证实……无法监听80端口……
好吧,最终解决了,下面完整列举一下从安装到修改端口的全部过程:
安装完全用官方的步骤就可以跟上最新版本:
apt-get install apt-transport-https curl https://repo.varnish-cache.org/GPG-key.txt | apt-key add - echo "deb https://repo.varnish-cache.org/debian/ jessie varnish-4.1"\ >> /etc/apt/sources.list.d/varnish-cache.list apt-get update apt-get install varnish
修改端口:
修改 /etc/default/varnish 的内容:
将
DAEMON_OPTS="-a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m"
修改为
DAEMON_OPTS="-a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m"
复制命令:
cp /lib/systemd/system/varnish.service /etc/systemd/system/ nano /etc/systemd/system/varnish.service
将
ExecStart=/usr/sbin/varnishd -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
修改为
ExecStart=/usr/sbin/varnishd -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
最后刷新一下systemd的配置并且重启一下varnish就好了:
systemctl daemon-reload systemctl restart varnish.service