GNU/Linux >> Linux Esercitazione >  >> Debian

Installare Varnish Cache 5.1 davanti ad Apache su Debian 9 / Ubuntu 16.04

Varnish Cache — di solito chiamato semplicemente Varnish — è un acceleratore HTTP open source ad alte prestazioni. Si colloca davanti al server web come livello di cache e serve le pagine ai visitatori molto più in fretta di quanto farebbe il server di origine da solo.

I contenuti vengono mantenuti in memoria virtuale, quindi le pagine richieste di frequente tornano quasi all'istante. Varnish offre anche un bilanciamento del carico di base, con pesatura per backend e controllo di salute dei back end.

Questa guida installa Varnish Cache 5 davanti ad Apache su Debian 9 e Ubuntu 16.04.

Requisiti

Servono una macchina Debian o Ubuntu con server Apache già in funzione.

LEGGI: Come installare Apache2 su Ubuntu 16.04
LEGGI: Come installare Apache2 su Debian 9

su -

OPPURE

sudo su -

Installare Varnish Cache

Entrambe le distribuzioni includono Varnish nei propri repository, ma spesso in una build datata. Per la linea 5.x corrente serve il repository ufficiale.

Configurare il repository

curl -L https://packagecloud.io/varnishcache/varnish5/gpgkey | sudo apt-key add -

Le macchine Debian richiedono anche il keyring degli archivi.

apt-get install -y debian-archive-keyring

E il supporto HTTPS per APT.

apt-get install -y apt-transport-https
### Debian 9 ###  echo "deb https://packagecloud.io/varnishcache/varnish5/debian/ stretch main" | sudo tee -a /etc/apt/sources.list.d/varnishcache5.list ### Ubuntu 16.04 ### echo "deb https://packagecloud.io/varnishcache/varnish5/ubuntu/ xenial main" | sudo tee -a /etc/apt/sources.list.d/varnishcache5.list

Installazione

apt-get update apt-get install -y varnish
varnishd -V

Output:

varnishd (varnish-5.1.3 revision 05c5ac6b9) Copyright (c) 2006 Verdens Gang AS Copyright (c) 2006-2015 Varnish Software AS

Configurare Varnish

A installazione completata, la prima modifica consiste nello spostare Varnish sulla porta 80, così da intercettare il traffico web. Modifica l'unità systemd.

nano /lib/systemd/system/varnish.service

Da:

ExecStart=/usr/sbin/varnishd -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m

A:

ExecStart=/usr/sbin/varnishd -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
systemctl daemon-reload

Ora Varnish deve sapere dove si trova il suo backend.

nano /etc/varnish/default.vcl

Dato che Apache sarà spostato sulla porta 8080, indica il backend di conseguenza. Se scegli una porta diversa, è questa la riga da cambiare.

backend default { .host = "127.0.0.1"; .port = "8080"; }

Spostare Apache sulla porta 8080

nano /etc/apache2/ports.conf
Listen 8080
nano /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:8080>
systemctl restart apache2 systemctl restart varnish

Verificare la configurazione

curl -I https://localhost

Output:

HTTP/1.1 200 OK Date: Thu, 31 Aug 2017 02:14:08 GMT Server: Apache/2.4.25 (Debian) Last-Modified: Thu, 31 Aug 2017 01:53:24 GMT Vary: Accept-Encoding Content-Type: text/html X-Varnish: 2 Age: 0 Via: 1.1 varnish (Varnish/5.1) ETag: W/"29cd-55776180d07a7-gzip" Accept-Ranges: bytes Connection: keep-alive

L'header Via è la prova: le richieste ora passano attraverso Varnish prima di raggiungere Apache.

Per le statistiche in tempo reale, esegui:

varnishstat

Output:

Installare Varnish Cache 5.1 davanti ad Apache su Debian 9 / Ubuntu 16.04

Fatto. Per approfondire Varnish, visita https://varnish-cache.org/index.html


Debian
  1. Installare Apache Maven su Debian 10 e testarlo con un progetto di esempio

  2. Come installare Apache Hadoop su CentOS 7, Ubuntu 18.04 e Debian 9

  3. Come installare Apache Cassandra su Ubuntu 18.04, Ubuntu 16.04 e Debian 9

  4. Come installare Varnish Cache su Ubuntu 18.04 LTS

  5. Installare Apache Cassandra su Debian 7: guida passo-passo

Installare Varnish Cache con Apache su CentOS 7

Come installare Apache Maven su Ubuntu 18.04 / Ubuntu 16.04 e Debian 9

Installare Apache Subversion (SVN) su Debian 9 / Ubuntu 16.04

Installare e configurare Varnish Cache con Apache su Ubuntu 20.04

Configurare Varnish Cache davanti ad Apache su CentOS 8

Come installare Varnish Cache per Apache su CentOS/RHEL 8