First, download the installation package
wget https://www.keepalived.org/software/keepalived-2.0.16.tar.gz
Install its dependencies
All rpm packages in a directory.
rpm -Uvh --force --nodeps *rpm
Two , unzip and install
tar xf keepalived-2.0.16.tar.gz cd keepalived-2.0.16 ./configure --prefix=/usr/local/keepalived make && make install cp /root/keepalived-2.0.16/keepalived/etc/init.d/keepalived /etc/init.d/ cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ mkdir /etc/keepalived cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
Third, modify the master configuration file
vim /etc/keepalived/keepalived.conf
! Keepalived the Configuration File for global_defs { # e-mail address received notification_email { [email protected] [email protected] [email protected] } # mailing address notification_email_from [email protected] smtp_server 127.0.0.1 smtp_connect_timeout 30 the router_id of the NGINX_MASTER } {check_nginx vrrp_script Script "/usr/local/nginx/sbin/check_nginx.sh" } vrrp_instance VI_1 { State the MASTER interface ens33 51 is routing the VRRP ID # instance virtual_router_id, each instance is unique priority 100 # priority Secondary servers 90 advert_int 1 # Specify VRRP advertisement packet heartbeat interval, the default one second authentication { AUTH_TYPE the PASS AUTH_PASS 1111 } virtual_ipaddress { 192.168.247.188/24 } track_script { check_nginx } }
Fourth, start the service
systemctl start keepalived systemctl enables keepalived
Fifth, check the vip
ip addr