Skip to main content

Keepalived

image.png

Keepalived es un software que brinda alta disponibilidad asignando a dos o más nodos una IP virtual (VIP) y monitoreando esos nodos, y conmutando por error cuando uno falla.

Enlaces

https://www.keepalived.org/

https://www.server-world.info/en/note?os=Ubuntu_22.04&p=keepalived&f=1

Diagrama

  +-----------------------------------------------------+
  |                Keepalived Cluster                   |
  |                                                     |
  |    +----------------+        +----------------+     |
  |    |  nodo1 MASTER  |        |  nodo2 BACKUP  |     |
  |    |  (Prioridad100)|        |  (Prioridad50) |     |
  |    |                |        |                |     |
  |    |  +-----------+ |        |  +-----------+ |     |
  |    |  | keepalived| |        |  | keepalived| |     |
  |    |  |  (MASTER) | |        |  | (BACKUP)  | |     |
  |    |  +-----------+ |        |  +-----------+ |     |
  |    |        |       |        |        |       |     |
  |   [eth0: 192.168.1.201]    [eth0: 192.168.1.202]    |
  |    |      VIP: 192.168.1.200 (flotante)       |     |
  |    +--------|----------------|----------------+     |
  |             |                |                      |
  +-------------|----------------|----------------------+
                |                |
                |                |
  +-------------v----------------v----------------------+
  |              Red (LAN/VLAN)                         |
  |                                                     |
  |    Clientes acceden al VIP: 192.168.1.200           |
  |                                                     |
  +-----------------------------------------------------+

Instalar 

En todos los nodos

sudo apt -y install keepalived

Configuración

El fichero de configuración está en "/etc/keepalived/keepalived.conf". Modifícalo en cada nodo

Nodo Master

global_defs {
    # set hostname
    router_id node01
}

vrrp_instance VRRP1 {
    # on primary node, specify [MASTER]
    # on backup node, specify [BACKUP]
    # if specified [BACKUP] + [nopreempt] on all nodes, automatic failback is disabled
    state MASTER # ifBACKUP youen likeel disableotro automaticnodo
    failback,priority set this value with [BACKUP]100 # nopreemptPrioridad #inferior networken nodo BACKUP
    interface that virtual IP address is assigned
    interface enp1s0
    # set unique ID on each VRRP interface
    # on the a VRRP interface, set the same ID on all nodeseth0
    virtual_router_id 101
    # set priority : [Master] > [BACKUP]
    priority 200
    # VRRP advertisement interval (sec)
    advert_int 1
    # virtual IP address
    virtual_ipaddress {
        10.0.0.30/24
    }
}

Nodo Backup

global_defs {
    router_id node02
}

vrrp_instance VRRP1 {
    state BACKUP
    # nopreempt
    interface enp1s0
    virtual_router_id 101
    priority 100
    advert_int 1
    virtual_ipaddress {
        10.0.0.30/192.168.1.200/24
    }
}

Comandos