keepalived.conf file.
garp parameters have been configured. Because Keepalived relies on ARP messages to update the IP address, these configurations ensure that the primary device always sends ARP messages for the communication.garp_master_delay 1garp_master_refresh 5
vrrp_garp_master_repeat 1 in the “global_defs” section of the Keepalived configuration file.adver_int parameter properly to balance anti-network jitter and disaster recovery speed. If the advert_int parameter is set too small, frequent switchover and temporary active-active (split brain) may occur in case of network jitter. If the advert_int parameter is set too large, it takes a long time for primary-secondary switching to take place after the primary server fails, which cause long service interruption. Please fully assess the impact of the active-active (split brain) status on your businesses.interval parameter in the specific execution item of track_script script (such as checkhaproxy) to a larger value, avoiding the FAULT status caused by script execution timeout.10.0.0.0/24, the entered private IP address should be within 10.0.0.2 - 10.0.0.254.

yum list keepalived
yum command.yum install -y keepalived
tar zxvf keepalived-1.2.24.tar.gzcd keepalived-1.2.24./configure --prefix=/make; make installchmod +x /etc/init.d/keepalived // Prevent occurrence of env: /etc/init.d/keepalived: Permission denied
vim /etc/keepalived/keepalived.conf to modify its configurations.! Configuration File for keepalivedglobal_defs {notification_email {acassen@firewall.locfailover@firewall.locsysadmin@firewall.loc}notification_email_from Alexandre.Cassen@firewall.locsmtp_server 192.168.200.1smtp_connect_timeout 30router_id LVS_DEVELvrrp_skip_check_adv_addrvrrp_garp_interval 0vrrp_gna_interval 0}vrrp_script checkhaproxy{script "/etc/keepalived/do_sth.sh" # Check whether the service process runs normally. Replace “do_sth.sh” with your actual script name. Run it as needed.interval 5}vrrp_instance VI_1 {# Select proper parameters for the primary and secondary CVMs.state BACKUP # Set the initial status to `Backup`interface eth0 # The ENI such as `eth0` used to bind a VIPvirtual_router_id 51 # The`virtual_router_id` value for the clusternopreempt # Non-preempt mode# preempt_delay 10 # Effective only when `state` is `MASTER`priority 100 # Configure the same weight for the two devicesadvert_int 5authentication {auth_type PASSauth_pass 1111}unicast_src_ip 172.16.16.5 # Private IP address of the local deviceunicast_peer {172.16.16.6 # IP address of the peer device}virtual_ipaddress {172.16.16.12 # HAVIP}notify_master "/etc/keepalived/notify_action.sh MASTER"notify_backup "/etc/keepalived/notify_action.sh BACKUP"notify_fault "/etc/keepalived/notify_action.sh FAULT"notify_stop "/etc/keepalived/notify_action.sh STOP"garp_master_delay 1 # How long it will take before the ARP cache can be updated after the CVM switches to the primary statusgarp_master_refresh 5 # Time interval between which the primary node sends ARP messagestrack_interface {eth0 # ENI that bound with VIP, such as `eth0`}track_script {checkhaproxy}}
vim /etc/keepalived/keepalived.conf to modify its configurations.! Configuration File for keepalivedglobal_defs {notification_email {acassen@firewall.locfailover@firewall.locsysadmin@firewall.loc}notification_email_from Alexandre.Cassen@firewall.locsmtp_server 192.168.200.1smtp_connect_timeout 30router_id LVS_DEVELvrrp_skip_check_adv_addrvrrp_garp_interval 0vrrp_gna_interval 0}vrrp_script checkhaproxy{script "/etc/keepalived/do_sth.sh"interval 5}vrrp_instance VI_1 {# Select proper parameters for the primary and secondary CVMs.state BACKUP #Set the initial status to `Backup`interface eth0 # The ENI such as `eth0` used to bind a VIPvirtual_router_id 51 # The`virtual_router_id` value for the clusternopreempt #Non-preempt mode# preempt_delay 10 # Effective only when `state` is `MASTER`priority 100 # Configure the same weight for the two devicesadvert_int 5authentication {auth_type PASSauth_pass 1111}unicast_src_ip 172.16.16.6 #Private IP of the local deviceunicast_peer {172.16.16.5 #IP address of the peer device}virtual_ipaddress {172.16.16.12 # HAVIP}notify_master "/etc/keepalived/notify_action.sh MASTER"notify_backup "/etc/keepalived/notify_action.sh BACKUP"notify_fault "/etc/keepalived/notify_action.sh FAULT"notify_stop "/etc/keepalived/notify_action.sh STOP"garp_master_delay 1 # How long it will take before the ARP cache can be updated after the CVM switches to the primary statusgarp_master_refresh 5 #Time interval between which the primary node sends ARP messagestrack_interface {eth0 # ENI that bound with VIP, such as `eth0`}track_script {checkhaproxy}}
systemctl start keepalived



vim /etc/keepalived/notify_action.sh command to add the following “notify_action.sh” script.#!/bin/bash#/etc/keepalived/notify_action.shlog_file=/var/log/keepalived.loglog_write(){echo "[`date '+%Y-%m-%d %T'`] $1" >> $log_file}[ ! -d /var/keepalived/ ] && mkdir -p /var/keepalived/case "$1" in"MASTER" )echo -n "$1" > /var/keepalived/statelog_write " notify_master"echo -n "0" /var/keepalived/vip_check_failed_count;;"BACKUP" )echo -n "$1" > /var/keepalived/statelog_write " notify_backup";;"FAULT" )echo -n "$1" > /var/keepalived/statelog_write " notify_fault";;"STOP" )echo -n "$1" > /var/keepalived/statelog_write " notify_stop";;*)log_write "notify_action.sh: STATE ERROR!!!";;esac
chmod a+x /etc/keepalived/notify_action.sh command to modify the script permission.ip addr show command to check whether the HAVIP is bound to the primary ENI.Feedback