Varnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸 Verdens Gang 使用3台Varnish代替了原来的12台Squid,性能比以前更好。
sudo apt-get install varnish -y
首先,删除/etc/varnish/default.vcl文件并从导出的Varnish配置创建一个符号链接:
sudo rm -rf /etc/varnish/default.vcl
sudo ln -s /var/www/html/magento/var/varnish.vcl /etc/varnish/default.vcl
接下来,您将需要为Varnish创建一个systemd服务文件。 您可以将varnish.service从/ lib / systemd / system /复制到/ etc / systemd / system /目录中:
sudo cp /lib/systemd/system/varnish.service /etc/systemd/system/
复制该文件后,您将需要对varnish.service文件进行一些更改:
sudo nano /etc/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
完成后保存文件,然后使用以下命令重新启动Varnish服务:
sudo systemctl daemon-reload
sudo systemctl reload varnish.service
如果一切正常,那么您应该能够通过在Web浏览器上输入以下URL来登录到Magento后端:
http://192.168.15.189/admin_wczta4
您还可以通过运行以下命令来检查是否启用了Varnish:
curl -I http://192.168.15.189/admin_wczta4
您应该看到Varnish已启用:
Date: Fri, 07 Jul 2017 17:10:01 GMT
Server: Apache/2.4.18 (Ubuntu)
Set-Cookie: store=default; expires=Sat, 07-Jul-2018 17:10:03 GMT; Max-Age=31536000; path=/; HttpOnly
Set-Cookie: phpSESSID=irp2k8cmrhct0dfh18qk7ap0i4; expires=Fri, 07-Jul-2017 18:10:04 GMT; Max-Age=3600; path=/; domain=192.168.15.189; HttpOnly
Expires: Thu, 07 Jul 2016 17:10:04 GMT
Cache-Control: max-age=0, must-revalidate, no-cache, no-store
Pragma: no-cache
Location: http://192.168.15.189/admin_wczta4/?SID=irp2k8cmrhct0dfh18qk7ap0i4
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Content-Length: 0
Content-Type: text/html; charset=UTF-8
X-Varnish: 2
Age: 0
Via: 1.1 varnish-v4
Connection: keep-alive