lunes, 8 de junio de 2020

Instalación de Pacemaker y Corosync en Ubuntu 16.04 LTS

Prerequisitios

Condición: 3 máquinas virtuales
Distribución SO: Ubuntu 16.04.5 LTS
Software: Pacemaker & Corosync
Servidor: 3 con 1GB de RAM, 2 discos de 10GB cada uno y un procesador
pre-instaladas y anotación de los nombres DNS para w1, w2 y w3.

Preparación

Edición del archivo /etc/hosts para todos los nodos (10.1.120.98, 10.1.120.99 y 10.1.120.100). El contenido del archivo será:
127.0.0.1 localhost
10.1.120.98 w1
10.1.120.99 w2
10.1.120.100 w3

Configuración de la dirección IP estática para cada nodo

En el nodo w1
iface enp0s3 inet static
    address 10.1.120.98
    netmask 255.255.255.0
    broadcast 10.1.120.255

En el nodo w2
iface enp0s3 inet static
    address 10.1.120.99
    netmask 255.255.255.0
    broadcast 10.1.120.255

En el nodo w3
iface enp0s3 inet static
    address 10.1.120.100
    netmask 255.255.255.0
    broadcast 10.1.120.255

Refrescar los repositorios

apt-get update

Configurar el idioma

apt-get -y install language-pack-es
dpkg-reconfigure tzdata

Editar el archivo referido y agregar la línea mostrada abajo:

vim /etc/environment

LC_ALL="es_NI.UTF-8"

Guardar el archivo

reboot

Actualizar el sistema

apt-get -y upgrade
apt-get -y dist-upgrade
reboot

Instalación de software (en todos los nodos)

apt-get -y install ntp
apt-get -y install policycoreutils python-sepolgen
apt-get -y install pacemaker
apt-get -y install pcs
apt-get -y install psmisc
apt-get -y install dlm
apt-get -y install fence-agents
apt-get -y install resource-agents
apt-get -y install ocfs2-tools
apt-get -y install drbd*
apt-get -y install haveged

Configuración de cluster

Genere y configure la clave de autenticación para Corosync

corosync-keygen
scp /etc/corosync/authkey isaac@10.1.120.99:/home/isaac
ssh isaac@10.1.120.99
cp ~/authkey /etc/corosync
chown root: /etc/corosync/authkey
exit

scp /etc/corosync/authkey isaac@10.1.120.100:/home/isaac
isaac@192.168.1.9
ssh isaac@10.1.120.100
cp ~/authkey /etc/corosync
chown root: /etc/corosync/authkey
exit

Configure Corosync en cada nodo

mv /etc/corosync/corosync.conf /etc/corosync/corosync.conf.default
vim /etc/corosync/corosync.conf

totem {
    version: 2
    secauth: off
    cluster_name: wwwCluster
    transport: udpu
    interface {
        ringnumber: 0
        bindnetaddr: 10.1.120.101
        broadcast: yes
        mcastport: 5405
    }
}
nodelist {
    node {
        ring0_addr: 10.1.120.98
        nodeid: 1
    }
    node {
        ring0_addr: 10.1.120.99
        nodeid: 2
    }
    node {
        ring0_addr: 10.1.120.100
        nodeid: 3
    }
}
quorum {
    provider: corosync_votequorum
}
logging {
    to_logfile: yes
    logfile: /var/log/corosync/corosync.log
    to_syslog: yes
}

Guarde el archivo

Cree el archivo referido en la configuración

touch /var/log/corosync/corosync.log
chown root:adm /var/log/corosync/corosync.log

Active el inicio de los servicios

mkdir -p /etc/corosync/service.d

Cree el archivo pcmk con el siguiente contenido

vim /etc/corosync/service.d/pcmk

service {
    name: pacemaker
    ver: 2
}

Edite el archivo corosync (vim /etc/default/corosync ) y agregue la línea.

START="yes"

Guarde el archivo

update-rc.d pacemaker defaults 20 01

Configuración del cluster

En todos los nodos

Establezca el parámetro “SELINUX=disabled” en todos los nodos
(vim /etc/selinux/config )
reboot
systemctl start pcsd
passwd hacluster
(Establezca la misma clave en todos los nodos)

En el nodo primario

pcs cluster --name wwwCluster --wait_for_all=1 \
auth 10.1.120.98 10.1.120.99 10.1.120.100 \
-u hacluster -p <clave>

(Use como clave la clave establecida en el paso anterior)

pcs cluster setup --force --name wwwCluster \
10.1.120.98 10.1.120.99 10.1.120.100
pcs cluster start --all
pcs cluster enable --all
pcs property set stonith-enabled=false
pcs property set cluster-recheck-interval=2min
pcs property set start-failure-is-fatal=true
pcs resource defaults resource-stickiness=100
pcs resource op defaults timeout=240s

Verifique que los nodos son miembros del cluster

corosync-cmapctl | grep members

Añadir la dirección IP del cluster

pcs resource create wwwClusterIP ocf:heartbeat:IPaddr2 \
ip=10.1.120.101 \
cidr_netmask=24 \
op monitor interval=30s

Verificar el estado del cluster

pcs status

Realizar prueba:

ping 10.1.120.101

pcs cluster stop w1
pcs cluster stop w2
pcs cluster start w1
pcs cluster stop w3
pcs cluster start w2
pcs cluster start w3
pcs status

(detener ping)


Agregar Apache y PHP (en todos los nodos)

apt-get -y install apache2 wget
apt-get -y install graphviz aspell php7.0-pspell php7.0-curl \
php7.0-gd php7.0-intl php7.0-xmlrpc php7.0-ldap \
php7.0-zip php7.0-mbstring php7.0-soap aspell-es \
ghostscript php7.0-xml unicode unoconv 

apt-get -y install libapache2-mod-php php-mcrypt

Cree el archivo index.php en /var/www/html
<!DOCTYPE html>
<html>
<body>
<p>Hola mundo!</p>
<?php
echo gethostname();
?>
</body>
</html>

pcs resource create wwwSitio ocf:heartbeat:apache \
configfile=/etc/apache2/apache2.conf \
statusurl="http://localhost/server-status" \
op monitor interval=1min
pcs constraint colocation add wwwSitio with wwwClusterIP INFINITY
pcs constraint
pcs constraint order wwwClusterIP then wwwSitio
pcs constraint
pcs constraint location wwwSitio prefers 10.1.120.98=100
pcs cluster cib wwwSitio
pcs cluster cib-push wwwSitio

Visitar http://10.1.120.101/index.php

Añadir el disco secundario al nodo

En todos los nodos

modprobe drbd
mv /etc/drbd.d/global_common.conf \
/etc/drbd.d/global_common.conf.default

Coloque el archivo /etc/drbd.d/global_common.conf en todos los nodos, el

contenido del archivo es:

global {
    usage-count no;
    }
common {
syncer { rate 90M; }
startup {
    #become-primary-on both;
    wfc-timeout 15;
    degr-wfc-timeout 60;
    #outdated-wfc-timeout wait-after-sb
}
options {
    # cpu-mask on-no-data-accessible
}
disk {
    # size on-io-error
    fencing resource-and-stonith;
    #
    # disk-barrier disk-flushes
    # disk-drain md-flushes resync-rate resync-after al-extents
    # c-plan-ahead c-delay-target c-fill-target c-max-rate
    # c-min-rate disk-timeout
}
net {
    # protocol timeout max-epoch-size max-buffers unplug-watermark
    # connect-int ping-int sndbuf-size rcvbuf-size ko-count
    # cram-hmac-alg shared-secret after-sb-0pri
    # after-sb-1pri after-sb-2pri always-asbp rr-conflict
    # ping-timeout data-integrity-alg tcp-cork on-congestion
    # congestion-fill congestion-extents csums-alg verify-alg
    # use-rle
    protocol C;
    cram-hmac-alg sha1;
    shared-secret "Sitio123..";
    allow-two-primaries;
    after-sb-0pri discard-zero-changes;
    after-sb-1pri discard-secondary;
    after-sb-2pri disconnect;
    }
}
systemctl start drbd

En todos los nodos

dpkg-reconfigure ocfs2-tools
update-rc.d -f o2cb defaults
update-rc.d -f ocfs2 defaults

Verificar que está correcto

/etc/init.d/o2cb offline
/etc/init.d/o2cb load
root@w1:~# /etc/init.d/o2cb online

Setting cluster stack "o2cb": OK

Starting O2CB cluster wwwCluster: OK

reboot

o2cb_ctl -C -n wwwCluster -t cluster -a name=wwwCluster

o2cb_ctl -C -n w1 -t node -a number=0 -a ip_address=10.1.120.98 \
-a ip_port=7777 -a cluster=wwwCluster

o2cb_ctl -C -n w2 -t node -a number=1 -a ip_address=10.1.120.99 \
-a ip_port=7777 -a cluster=wwwCluster

o2cb_ctl -C -n w3 -t node -a number=2 -a ip_address=10.1.120.100 \
-a ip_port=7777 -a cluster=wwwCluster

Copie el archivo /etc/ocfs2/cluster.conf a los nodos w2 y w3

Configurar DRBD (Distributed Replicated Block Device)

Cree el archivo del recurso (en todos los nodos)

vim /etc/drbd.d/wwwClusterDisk0.res

resource wwwClusterDisk0 {
    protocol C;
   meta-disk internal;
device /dev/drbd0;
syncer {verify-alg sha1;}
net {
    #allow-two-primaries;
    cram-hmac-alg sha1;
    shared-secret "Sitio123..";
}
on w1 {
    disk /dev/sdb1;
        address 10.1.120.98:7789;
    }
on w2 {
        disk /dev/sdb1;
        address 10.1.120.99:7789;
}
on w3 {
    disk /dev/sdb1;     address 10.1.120.100:7789;
}
}

Guarde el archivo.

En cada nodo

modprobe drbd
systemctl restart drbd
/etc/init.d/o2cb offline
/etc/init.d/o2cb load

root@w1:~# /etc/init.d/o2cb online

Setting cluster stack "o2cb": OK

Starting O2CB cluster wwwCluster: OK

En el nodo primario

drbdadm create-md wwwClusterDisk0

En el nodo w1

drbdadm --force primary wwwClusterDisk0

#drbdadm up wwwClusterDisk0

Si desea ver el progreso de la sincronización, ejecute:

watch -n1 cat /proc/drbd

Formatee el dispositivo

mkfs.ocfs2 -L "wwwClusterDisk0" -N 3 \
-T datafiles --cluster-name=wwwCluster \
--fs-features=unwritten,grpquota,usrquota,\
max-compat /dev/drbd0

Monte el sistema de archivos

mount -t ocfs2 /dev/drbd0 /var/www/html

Cree el archivo index.php en /var/www/html
<!DOCTYPE html>
<html>
<body>
<p>Hola mundo!</p>
<?php
echo gethostname();
?>
</body>
</html>
Visite http://10.1.120.101

Añadir el recurso (sistema de ficheros) al cluster wwwCluster

pcs cluster cib drbd_cfg
pcs -f drbd_cfg resource create WebData ocf:linbit:drbd \
drbd_resource=wwwClusterDisk0 op monitor interval=60s
pcs -f drbd_cfg resource master WebDataClone WebData \
master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 \
notify=true

pcs -f drbd_cfg resource show
pcs cluster cib-push drbd_cfg --config
pcs status
pcs cluster cib fs_cfg
pcs -f fs_cfg resource create WebFS Filesystem \
device="/dev/drbd0" directory="/var/www/html" fstype="ocfs2"

pcs -f fs_cfg constraint colocation add \
WebFS with WebDataClone INFINITY with-rsc-role=Master

pcs -f fs_cfg constraint order \
promote WebDataClone then start WebFS

pcs -f fs_cfg constraint colocation add wwwSitio with WebFS INFINITY
pcs -f fs_cfg constraint order WebFS then wwwSitio
pcs -f fs_cfg constraint
pcs -f fs_cfg resource show
pcs cluster cib-push fs_cfg --config
pcs status

pcs cluster cib dlm_cfg

pcs -f dlm_cfg resource create dlm ocf:pacemaker:controld \
op monitor interval=60s

pcs cluster cib-push dlm_cfg --config

pcs status

Documentación de pruebas

Prueba de falla (ping)

Verificar el estado del cluster

pcs status

Realizar prueba:

ping 10.1.120.101
pcs cluster stop w1
pcs cluster stop w2
pcs cluster start w1
pcs cluster stop w3
pcs cluster start w2
pcs cluster start w3
pcs status

(detener ping)

Prueba de falla (http://192.168.10/)

Verificar el estado del cluster

pcs status

Realizar prueba:

Visitar http://10.1.120.101/

pcs cluster stop w1

Visitar http://10.1.120.101/

pcs cluster stop w2

Visitar http://10.1.120.101/

pcs cluster start w1

Visitar http://10.1.120.101/

pcs cluster stop w3

Visitar http://10.1.120.101/

pcs cluster start w2

Visitar http://10.1.120.101/

pcs cluster start w3

Visitar http://10.1.120.101/

pcs status


No hay comentarios:

Publicar un comentario

El desembarco de Normandía

Disculpas, alguna vez pensé que el Canal de la Mancha estaba vinculado al Quijote. En la esquina superior derecha del mapa puede verse el rí...