Ubuntu Keepalived Configuration

VIP must be in the same network segment as the current machine IP.

Complete VIP configuration with Keepalived

Install Keepalived

apt-get -y install libssl-dev
apt-get -y install openssl
apt-get -y install libpopt-dev
apt-get -y install keepalived

Edit configuration file

Note! The content of the current health monitoring script is in the comment state. The reason is that you need to make sure that the VIP already exists before installing Kato; you need to cancel the comment after the Kato installation is complete to achieve health monitoring and ensure the high availability of the gateway.

Master node

$ vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   router_id LVS_DEVEL
}
#vrrp_script check_gateway {
# Detection script
#   script "/etc/keepalived/check_gateway_status.sh"
# Execution interval
#   interval 5
#}
vrrp_instance VI_1 {
    				
    #Because of the use of non-preemptive mode, here are backup
    state BACKUP 
    #Network card device name, determined by the ifconfig command 
    interface ens6f0 
    virtual_router_id 51
    #Priority, the primary node is greater than the standby node 
    priority 100	
    advert_int 1
    #Non-preemptive mode
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        <VIP>				
     }
#     track_script {
#    check_gateway
#   }
}

Slave node

$ vi /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   router_id LVS_DEVEL
}
#vrrp_script check_gateway {
# Detection script
#  script "/etc/keepalived/check_gateway_status.sh"
# Execution interval
#  interval 5
#  }	
    vrrp_instance VI_1 {
    #Because of the use of non-preemptive mode, here are backup
    state BACKUP 
    #Network card device name, determined by the ifconfig command 
    interface ens6f0
    virtual_router_id 51
    #Priority, the primary node is greater than the standby node 
    priority 50
    advert_int 1
    #Non-preemptive mode
    nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        <VIP>			
    }
#     track_script {
#    check_gateway
#   }
}

Health monitoring script

Extend the script for the health check of the gateway node. The function of the script is to close the Keepalived of the machine and switch the VIP when the rbd-gateway component stops serving. (Master and slave need to operate)

$ vi /etc/keepalived/check_gateway_status.sh 

#!/bin/bash                                                                                             
/usr/bin/curl -I http://localhost:10254/healthz 

if [ $? -ne 0 ];then
                                                                   
     cat /var/run/keepalived.pid | xargs kill

be

Add execute permission

$ chmod +x /etc/keepalived/check_gateway_status.sh

Change the Keepalived systemd configuration file and add two configurations

Add two parameters

$ vi /lib/systemd/system/keepalived.service

# /lib/systemd/system/keepalived.service
[Unit]
Description=Keepalive Daemon (LVS and VRRP)
After=network-online.target
Wants=network-online.target
# Only start if there is a configuration file
ConditionFileNotEmpty=/etc/keepalived/keepalived.conf
[Service]
Type=forking
KillMode=process
PIDFile=/var/run/keepalived.pid
# Read configuration variable file if it is present
EnvironmentFile=-/etc/default/keepalived
ExecStart=/usr/sbin/keepalived $DAEMON_ARGS
ExecReload=/bin/kill -HUP $MAINPID
# Always restart the service
Restart=always
# Restart interval time
RestartSec=10

[Install]
WantedBy=multi-user.target

Start service

Start the service and set the boot to start automatically

systemctl start keepalived
systemctl enable keepalived
systemctl status keepalived

Check if VIP is activated

ip a |grep <VIP>

Before proceeding to the next step, please ensure that the VIP already exists. If the VIP does not exist, please review the operations in this section; after the installation of Kato, please cancel the comment in the configuration file and restart the Keepalived service to achieve health monitoring to ensure The gateway is highly available.