Etiqueta: web

Web de alta disponibilidad con GlusterFS

En posts anteriores creamos un servidor web de alta disponibilidad usando Pacemaker y un servidor de archivos distribuidos con GlusterFS. En está ocasión uniremos un ambos proyectos para que tengan un mayor sentido.

En cada uno de los servidores involucrados usamos el siguiente archivo /etc/hosts:

192.168.100.117 www1.cluster www1
192.168.100.114 www2.cluster www2
192.168.100.122 nodo1.cluster nodo1
192.168.100.127 nodo2.cluster nodo2

Para hacerlos funcionar, instalamos el cliente glusterfs en los servidores web. Recordemos que estos servidores están funcionando en una distribución Rocky Linux por lo que hay que crear el repo /etc/yum.repos.d/CentOS-Gluster-9.repo.

[centos-gluster9]
name=CentOS-$releasever - Gluster 9
baseurl=https://dl.rockylinux.org/vault/centos/8.5.2111/storage/x86_64/gluster-9/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Storage

Para posteriormente instalar los paquetes que nos permitirán montar el servidor de archivos.

sudo yum install glusterfs glusterfs-libs glusterfs-client-xlators

En ambos servidores web montamos el sistema

~]$ sudo mount -t glusterfs nodo1.cluster:/volume_mirror /var/www/
[tusysadmin@www1 ~]$ df -h
S.ficheros                   Tamaño Usados  Disp Uso% Montado en
devtmpfs                       388M      0  388M   0% /dev
tmpfs                          405M    47M  358M  12% /dev/shm
tmpfs                          405M   5.7M  399M   2% /run
tmpfs                          405M      0  405M   0% /sys/fs/cgroup
/dev/mapper/rl-root            4.3G   2.2G  1.9G  54% /
/dev/vda2                      976M   274M  636M  31% /boot
tmpfs                           81M      0   81M   0% /run/user/0
nodo1.cluster:/volume_mirror    20G   238M   20G   2% /var/www

Para montar el sistema de archivos de forma automática al iniciar el servidor.

sudo echo "nodo1.cluster:/volume_mirror /var/www glusterfs defaults,_netdev 1 2" >> /etc/fstab

De esta forma contamos con alta disponibilidad a nivel sistema de archivos y servicios web ya que hemos se han integrado ambos proyectos.

Instalar servidor web con alta disponibilidad

Contar con un sitio web con un alto porcentaje de disponibilidad es alcanzable cuando el sitio no se encuentra en un solo servidor. Al evitar un único punto de falla el sitio puede permanecer visible para los usuarios.

En este post aprenderemos como implementar Pacemaker en Rocky Linux con un servidor web Apache. Estos son los servidores que usaremos en nuestro ambiente.

192.168.100.117 www1.cluster www1
192.168.100.114 www2.cluster www2

Comenzamos la instalación de paquetes en ambos servidores y habilitamos el servicio.

~]$ sudo yum install -y pacemaker pcs resource-agents
~]$ sudo systemctl enable pcsd.service
~]$ sudo systemctl start pcsd.service

Habilitamos la aplicación en el firewall.

]$ sudo firewall-cmd --permanent --add-service=high-availability
]$ sudo firewall-cmd --reload

Con la instalación de los paquetes se creó el usuario hacluster, es necesario establecer la contraseña a este usuario ya que la necesitaremos para crear la conexión entre los servidores.

~]$ sudo passwd hacluster

Con todo lo anterior terminado ya podemos crear el cluster.

[tusysadmin@www1 ~]$ sudo pcs host auth www1 www2 -u hacluster
Password: 
www2: Authorized
www1: Authorized
[tusysadmin@www1 ~]$ sudo pcs cluster setup web www1 www2
No addresses specified for host 'www1', using 'www1'
No addresses specified for host 'www2', using 'www2'
Destroying cluster on hosts: 'www1', 'www2'...
www1: Successfully destroyed cluster
www2: Successfully destroyed cluster
Requesting remove 'pcsd settings' from 'www1', 'www2'
www1: successful removal of the file 'pcsd settings'
www2: successful removal of the file 'pcsd settings'
Sending 'corosync authkey', 'pacemaker authkey' to 'www1', 'www2'
www1: successful distribution of the file 'corosync authkey'
www1: successful distribution of the file 'pacemaker authkey'
www2: successful distribution of the file 'corosync authkey'
www2: successful distribution of the file 'pacemaker authkey'
Sending 'corosync.conf' to 'www1', 'www2'
www1: successful distribution of the file 'corosync.conf'
www2: successful distribution of the file 'corosync.conf'
Cluster has been successfully set up

Habilitamos e iniciamos el cluster.

[tusysadmin@www1 ~]$ sudo pcs cluster start --all
www2: Starting Cluster...
www1: Starting Cluster...
[tusysadmin@www1 ~]$ sudo pcs cluster enable --all
www1: Cluster Enabled
www2: Cluster Enabled
[tusysadmin@www1 ~]$ sudo pcs cluster status
Cluster Status:
 Cluster Summary:
   * Stack: corosync
   * Current DC: www2 (version 2.1.0-8.el8-7c3f660707) - partition with quorum
   * Last updated: Wed Jan 26 21:01:54 2022
   * Last change:  Wed Jan 26 16:44:48 2022 by hacluster via crmd on www2
   * 2 nodes configured
   * 0 resource instances configured
 Node List:
   * Online: [ www1 www2 ]

PCSD Status:
  www1: Online
  www2: Online

El cluster cuenta con dos nodos pero lo correcto sería que contara con 3 para poder tener Quorum y «tomar decisiones» con respecto a la disponibilidad del cluster. Si se tienen 3 nodos y uno no se encuentra disponible se conservan la mayoría de los nodos. Como no contamos con un tercer nodo no es necesario tener habilitado el STONITH (Shoot The Other Node In The Head).

[tusysadmin@www1 ~]$ sudo pcs property set no-quorum-policy=ignore
[tusysadmin@www1 ~]$ sudo pcs property set stonith-enabled=false

La disponibilidad del servicio web se hace a través de una IP flotante; esta IP estará asignada a uno de los nodos pero cuando éste no se encuentre disponible la IP pasará (flotará) al otro nodo. Al no afectar la visibilidad del sitio esta falla pasa desapercibida por los usuarios.

sudo pcs resource create virtual_ip ocf:heartbeat:IPaddr2 ip=192.168.100.110 cidr_netmask=24 op monitor interval=30s

La IP 192.168.100.110 es el recurso asignado en nuestro cluster y de momento se encuentra en el servidor www1, al detenerse el servicio o estar fuera de linea este servidor dicha IP cambiara a www2.

www1 con la IP

Image 1 De 3

En ambos servidores instalamos, habilitamos y permitimos el tráfico en el firewall.

~]$ sudo yum install httpd -y
~]$ sudo systemctl enable --now httpd
~]$ sudo firewall-cmd --permanent --add-service http
~]$ sudo firewall-cmd --reload

Editamos el Logrotate para denegar el uso de systemd en el cluster

/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
#        /bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true

    /usr/sbin/httpd -f /etc/httpd/conf/httpd.conf -c "PidFile /var/run/httpd/httpd.pid" -k graceful > /dev/null 2>/dev/null || true

    endscript
}

Al archivo de configuración de Apache agregamos la ruta del identificador del proceso.

PidFile /var/run/httpd/httpd.pid

Agregamos un nuevo recurso llamado webserver

~]$ sudo pcs resource create webserver apache configfile="/etc/httpd/conf/httpd.conf" 

[tusysadmin@www1 ~]$ sudo pcs resource status
  * Resource Group: apache:
    * virtual_ip	(ocf::heartbeat:IPaddr2):	 Started www1
  * webserver	(ocf::heartbeat:apache):	 Started www2

La IP virtual se encuentra en el nodo www1 pero el servicio web estará respondiendo en el nodo www2

[tusysadmin@www2 ~]$ netstat -ant | grep :80
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 ::1:54942               ::1:80                  TIME_WAIT  
tcp6       0      0 ::1:54940               ::1:80                  TIME_WAIT  
tcp6       0      0 ::1:54946               ::1:80                  TIME_WAIT  
tcp6       0      0 ::1:54938               ::1:80                  TIME_WAIT  
tcp6       0      0 ::1:54936               ::1:80                  TIME_WAIT  
tcp6       0      0 ::1:54944               ::1:80                  TIME_WAIT 

Si detenemos el nodo www2 el tráfico http pasará al nodo www1.

[tusysadmin@www1 ~]$ sudo pcs node standby www2

[tusysadmin@www1 ~]$ sudo pcs resource status
[sudo] password for tusysadmin: 
  * Resource Group: apache:
    * virtual_ip	(ocf::heartbeat:IPaddr2):	 Started www1
  * webserver	(ocf::heartbeat:apache):	 Started www1

[tusysadmin@www1 ~]$ netstat -ant | grep :80
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 ::1:39616               ::1:80                  TIME_WAIT  
tcp6       0      0 ::1:39626               ::1:80                  TIME_WAIT  
tcp6       0      0 ::1:39624               ::1:80                  TIME_WAIT  
tcp6       0      0 ::1:39618               ::1:80                  TIME_WAIT  
tcp6       0      0 ::1:39620               ::1:80                  TIME_WAIT  
tcp6       0      0 ::1:39622               ::1:80                  TIME_WAIT 

Él ultimo detalle que faltaría a nuestro cluster sería el de integrar un sistema de archivos para que los archivos de nuestro sitio web fueran los mismos, para esto se pudiera usar GlusterFS, NFS o iSCSI.

© 2025

Tema por Anders NorenArriba ↑