Búsqueda de sitios web

Cómo instalar Varnish Cache 4.0 en CentOS 7


Varnish Cache es un acelerador de aplicaciones web también conocido como proxy inverso HTTP de almacenamiento en caché. Lo instala frente a cualquier servidor que hable HTTP y lo configura para almacenar en caché el contenido. Varnish Cache es realmente rápido. Por lo general, acelera la entrega con un factor de 300 a 1000 veces, según su arquitectura. En el vídeo adjunto a esta página web se puede ver una descripción general de alto nivel de lo que hace Varnish.

Pasos para instalar Varnish en CentOS

  • Mi servidor Centos: CentOS Linux versión 7.1.1503 (Núcleo) 
  • IP: 192.168.136.131

1. Ejecute el siguiente comando para barnizar el repositorio de Centos 7

vi /etc/yum.repos.d/varnish.repo
[varnish-4.0]
 name=Varnish 4.0 for Enterprise Linux
 baseurl=https://repo.varnish-cache.org/redhat/varnish-4.0/el7/$basearch
 enabled=1
 gpgcheck=0
 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-VARNISH
 [root@localhost varnish]#

2. Instalar EPEL Repo para CentOS 7 

  • http://www.unixmen.com/install-epel-repository-centos-rhel-7/

3. Luego instale el barniz usando el comando yum

yum update
[root@localhost ~]# yum install varnish
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.denit.net
 * epel: ftp.fau.de
 * extras: centos.mirror.transip.nl
 * updates: mirrors.supportex.net
Resolving Dependencies
--> Running transaction check
---> Package varnish.x86_64 0:4.0.3-3.el7 will be installed
--> Processing Dependency: varnish-libs(x86-64) = 4.0.3-3.el7 for package: varnish-4.0.3-3.el7.x86_64
--> Processing Dependency: libvarnishapi.so.1(LIBVARNISHAPI_1.3)(64bit) for package: varnish-4.0.3-3.el7.x86_64
--> Processing Dependency: libvarnishapi.so.1(LIBVARNISHAPI_1.2)(64bit) for package: varnish-4.0.3-3.el7.x86_64
--> Processing Dependency: libvarnishapi.so.1(LIBVARNISHAPI_1.1)(64bit) for package: varnish-4.0.3-3.el7.x86_64
--> Processing Dependency: libvarnishapi.so.1(LIBVARNISHAPI_1.0)(64bit) for package: varnish-4.0.3-3.el7.x86_64
--> Processing Dependency: jemalloc for package: varnish-4.0.3-3.el7.x86_64
--> Processing Dependency: libvgz.so()(64bit) for package: varnish-4.0.3-3.el7.x86_64
--> Processing Dependency: libvcc.so()(64bit) for package: varnish-4.0.3-3.el7.x86_64
--> Processing Dependency: libvarnishcompat.so()(64bit) for package: varnish-4.0.3-3.el7.x86_64
--> Processing Dependency: libvarnishapi.so.1()(64bit) for package: varnish-4.0.3-3.el7.x86_64
--> Processing Dependency: libvarnish.so()(64bit) for package: varnish-4.0.3-3.el7.x86_64
--> Processing Dependency: libjemalloc.so.1()(64bit) for package: varnish-4.0.3-3.el7.x86_64
--> Running transaction check
---> Package jemalloc.x86_64 0:3.6.0-1.el7 will be installed
---> Package varnish-libs.x86_64 0:4.0.3-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================
 Package                                               Arch                                            Version
=======================================================================================================================
Installing:
 varnish                                               x86_64                                          4.0.3-3.el7
Installing for dependencies:
 jemalloc                                              x86_64                                          3.6.0-1.el7
 varnish-libs                                          x86_64                                          4.0.3-3.el7

Transaction Summary
=======================================================================================================================
Install  1 Package (+2 Dependent packages)

4. Edite la configuración de Varnish en /etc/varnish 

Editar barniz

vi  varnish.params
Default address and port to bind to. Blank address means all IPv4
and IPv6 interfaces, otherwise specify a host name, an IPv4 dotted
quad, or an IPv6 address in brackets.
VARNISH_LISTEN_ADDRESS=192.168.1.5
VARNISH_LISTEN_PORT=80

Admin interface listen address and port
VARNISH_ADMIN_LISTEN_ADDRESS=192.168.136.131
VARNISH_ADMIN_LISTEN_PORT=6082

y editar default.vcl

Default backend definition. Set this to point to your content server.
backend default {
    .host = "192.168.136.131";
    .port = "8080";
}

Edite  la configuración de Apache y cambie el puerto de escucha a 8080

 vi  /etc/httpd/conf/httpd.conf
Listen 8080

5. Edite el firewall para permitir el servicio http

[root@localhost varnish]# systemctl stop firewalld
[root@localhost varnish]# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)
   Active: inactive (dead) since Mon 2015-06-01 15:32:19 PDT; 53min ago
 Main PID: 758 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/firewalld.service

Jun 01 13:38:39 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Jun 01 15:32:18 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...
Jun 01 15:32:19 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost varnish]#

si desea mantener el firewall en funcionamiento:

firewall-cmd --permanent --zone=internal --add-service=http
success
firewall-cmd --reload
success

 6. Habilite e inicie los demonios Varnish y Apache

systemctl enable varnish
systemctl enable httpd
systemctl start varnish
systemctl start httpd

7. comprobar si apache se está ejecutando

http://ip  http://hosnmae

8. Ahora comprueba si tu sistema de almacenamiento en caché funciona  

O verifique desde la línea de comando como se muestra a continuación.

[root@localhost varnish]# curl -I 192.168.136.131
 HTTP/1.1 403 Forbidden
 Date: Mon, 01 Jun 2015 23:03:10 GMT
 Server: Apache/2.4.6 (CentOS) PHP/5.4.16
 Last-Modified: Thu, 16 Oct 2014 13:20:58 GMT
 ETag: "1321-5058a1e728280"
 Accept-Ranges: bytes
 Content-Length: 4897
 Content-Type: text/html; charset=UTF-8
 X-Varnish: 32779
 Age: 0
 Via: 1.1 varnish-v4
 Connection: keep-alive

Eso es todo.