147 lines
7.3 KiB
Plaintext
147 lines
7.3 KiB
Plaintext
|
|
Configuración de un cluster (Corosync y Pacemaker) en un servidor Ubuntu 20.04
|
|
|
|
La instalación funciona con Pacemaker 2.0.3, pcs en la versión 0.10.4 y Corosync crm 4.0.0
|
|
Con la versión 0.9.x de PCS y anteriores, la sintaxis es diferente en algunos lugares. Aquí recomiendo las siguientes instrucciones
|
|
Estoy en una red local (Fritzbox) y tengo las Ips 192.168.188.110 y 192.168.188.111 para los nodos. 192.168.188.112 se utilizó para la IP flotante utilizada posteriormente. Uso dos VMs bajo VMWare Workstation 16 y Remmina como terminal para un mejor acceso. Mi propio ordenador tiene la IP 192.168.188.81. Todos los comandos se ejecutan en ambos nodos (VMs) al principio.
|
|
|
|
En ambas VM (nodos) haga las siguientes entradas en /etc/hosts
|
|
192.168.188.110 node1.example.com
|
|
192.168.188.111 node2.example.com
|
|
Los archivos se ven así para mí
|
|
cat /etc/hosts
|
|
Output
|
|
127.0.0.1 localhost
|
|
127.0.1.1 ubuntu-server
|
|
192.168.188.110 node1.example.com
|
|
192.168.188.111 node2.example.com
|
|
# The following lines are desirable for IPv6 capable hosts
|
|
::1 ip6-localhost ip6-loopback
|
|
fe00::0 ip6-localnet
|
|
ff00::0 ip6-mcastprefix
|
|
ff02::1 ip6-allnodes
|
|
ff02::2 ip6-allrouters
|
|
|
|
Instalar Nginx como servidor web, Corosync y Pacemaker
|
|
apt install nginx
|
|
apt install corosync pacemaker pcs
|
|
|
|
Activar e iniciar Nginx
|
|
systemctl enable nginx;
|
|
systemctl start nginx;
|
|
|
|
Cambia la página Nginx por defecto en cada nodo para que puedas ver dónde estás.
|
|
en el nodo1
|
|
echo "This is the default page for node1.example.com" | sudo tee /var/www/html/index.nginx-debian.html
|
|
y en el nodo2
|
|
echo "This is the default page for node2.example.com" | sudo tee /var/www/html/index.nginx-debian.html
|
|
|
|
como estamos en un servidor Ubuntu, el firewall ufw está habilitado allí y necesitamos crear recursos compartidos en ambos nodos.
|
|
ufw allow from 192.168.188.81 to any
|
|
ufw allow from 192.168.188.111 to any (only node 1)
|
|
ufw allow from 192.168.188.110 to any (only node 2)
|
|
|
|
Activar y poner en marcha el marcapasos
|
|
systemctl enable pcsd
|
|
systemctl start pcsd
|
|
|
|
Con la instalación, se creó un usuario "hacluster", que sigue necesitando una contraseña.
|
|
passwd hacluster
|
|
New password: dasPasswort
|
|
Retype new password: dasPasswort
|
|
|
|
Hasta ahora, todos los comandos se ejecutaban en ambos nodos. Ahora sólo en el nodo1
|
|
pcs cluster auth
|
|
Output
|
|
Warning: Unable to read the known-hosts file: No such file or directory: '/var/lib/pcsd/known-hosts'
|
|
node1: Not authorized
|
|
Nodes to authorize: node1
|
|
Username: hacluster
|
|
Password: dasPasswort
|
|
node1: Authorized
|
|
|
|
ahora autenticar los nodos
|
|
pcs host auth node1.example.com node2.example.com
|
|
Output
|
|
Username: hacluster
|
|
Password: dasPasswort
|
|
node1.example.com: Authorized
|
|
node2.example.com: Authorized
|
|
pcs cluster setup cluster1 node1.example.com node2.example.com --force
|
|
Output
|
|
No addresses specified for host 'node1.example.com', using 'node1.example.com'
|
|
No addresses specified for host 'node2.example.com', using 'node2.example.com'
|
|
Warning: node1.example.com: Running cluster services: 'corosync', 'pacemaker', the host seems to be in a cluster already
|
|
Warning: node1.example.com: Cluster configuration files found, the host seems to be in a cluster already
|
|
Warning: node2.example.com: Running cluster services: 'corosync', 'pacemaker', the host seems to be in a cluster already
|
|
Warning: node2.example.com: Cluster configuration files found, the host seems to be in a cluster already
|
|
Destroying cluster on hosts: 'node1.example.com', 'node2.example.com'...
|
|
node2.example.com: Successfully destroyed cluster
|
|
node1.example.com: Successfully destroyed cluster
|
|
Requesting remove 'pcsd settings' from 'node1.example.com', 'node2.example.com'
|
|
node2.example.com: successful removal of the file 'pcsd settings'
|
|
node1.example.com: successful removal of the file 'pcsd settings'
|
|
Sending 'corosync authkey', 'pacemaker authkey' to 'node1.example.com', 'node2.example.com'
|
|
node1.example.com: successful distribution of the file 'corosync authkey'
|
|
node1.example.com: successful distribution of the file 'pacemaker authkey'
|
|
node2.example.com: successful distribution of the file 'corosync authkey'
|
|
node2.example.com: successful distribution of the file 'pacemaker authkey'
|
|
Sending 'corosync.conf' to 'node1.example.com', 'node2.example.com'
|
|
node1.example.com: successful distribution of the file 'corosync.conf'
|
|
node2.example.com: successful distribution of the file 'corosync.conf'
|
|
Cluster has been successfully set up.
|
|
pcs cluster enable --all
|
|
Output
|
|
node1.example.com: Cluster Enabled
|
|
node2.example.com: Cluster Enabled
|
|
pcs cluster start --all
|
|
Output
|
|
node1.example.com: Starting Cluster...
|
|
node2.example.com: Starting Cluster...
|
|
|
|
Desactivar las segundas propiedades
|
|
pcs property set stonith-enabled=false
|
|
pcs property set no-quorum-policy=ignore
|
|
|
|
Especifique la IP flotante indicada anteriormente bajo la cual se podrá acceder al clúster más adelante
|
|
pcs resource create floating_ip ocf:heartbeat:IPaddr2 ip=192.168.188.112 cidr_netmask=24 op monitor interval=60s
|
|
|
|
Hay que comprobar qué nodo está activo y, si es necesario, hay que desplazarlo
|
|
pcs resource create http_server ocf:heartbeat:nginx configfile="/etc/nginx/nginx.conf" op monitor timeout="20s" interval="60s"
|
|
|
|
Tenemos la salida de estado
|
|
pcs status resources
|
|
Output
|
|
root@ubuntu-server:/home/bernd# pcs status resources
|
|
* Resource Group: cluster1:
|
|
* floating_ip (ocf::heartbeat:IPaddr2): Started node1.example.com
|
|
* http_server (ocf::heartbeat:nginx): Started node2.example.com
|
|
|
|
Aquí puedes ver que todo está funcionando, pero desafortunadamente en diferentes nodos. Tenemos que agrupar todo
|
|
crm configure group cluster1 floating_ip http_server
|
|
|
|
Aparece un mensaje de error (para mí), pero lo ignoro.
|
|
Output
|
|
ERROR: (unpack_config) warning: Blind faith: not fencing unseen nodes
|
|
|
|
Vuelvo a tener el estado mostrado y veo
|
|
pcs status resources
|
|
Output
|
|
root@ubuntu-server:/home/bernd# pcs status resources
|
|
* Resource Group: cluster1:
|
|
* floating_ip (ocf::heartbeat:IPaddr2): Started node1.example.com
|
|
* http_server (ocf::heartbeat:nginx): Started node1.example.com
|
|
|
|
Todo se ejecuta en el nodo1 como se desea. Ahora llamo a la interfaz web para seguir trabajando allí. Esto debe hacerse con https, incluso si no se almacena ningún certificado. Por lo tanto, aparece una advertencia en el navegador, que acepto.
|
|
https://192.168.188.112:2224/manage
|
|
|
|
Iniciar sesión con hacluster y la contraseña +Añadir salida en el campo que aparece, introduzca "nodo1.ejemplo.com" sin "" y luego el botón "Añadir salida". Luego hay que esperar un poco hasta que se cargue todo. En el sitio de la izquierda puede hacer clic en "cluster1". Entonces, espera un poco más. Ahora puedes ver ambos nodos.
|
|
https://cdn3.adminscout.net/configuration/bff4bd9f896293d5f838a5c178288a3e.png
|
|
|
|
En el navegador, al introducir http://192.168.188.112/, aparece lo siguiente
|
|
https://cdn3.adminscout.net/configuration/58d5f7de45fbce7b2eacad6a5124b0ec.png
|
|
|
|
Si ahora cambias el nodo1 a standby en la interfaz del Web Admin, puedes ver que cambia al nodo2, como puedes ver en las siguientes imágenes
|
|
https://cdn3.adminscout.net/configuration/9d18c9145f1a8cc7dd958c9db8d9dd73.png
|
|
https://cdn3.adminscout.net/configuration/d2ecba400b47aa21c38d11756c65b0fd.png
|