Keepalived is a highly available Web service solution based on the VRRP protocol, which improves the high availability of your Web site.
When a Web server has at least two or more servers running keepalived, and the primary server is down, the backup server takes over the virtual IP and does not stop service because the primary server is down.
Here is the keepalived Heartbeat monitoring implementation (HTTP port test):
First prepare two servers:
192.168.1.110 (Main)
192.168.1.209 (prepared)
1. Download keepalived (two downloads)
# yum Install keepalived
2, modify the configuration file (main)
# IP Addr
# vim/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
Failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout
router_id lvs_devel
}
vrrp_script Chk_ Http_port {
Script "</dev/tcp/127.0.0.1/81" # Connects and exits
interval 1 # Check every
second Weight-2 # Default Prio:-2 If connect fails
}
vrrp_instance vi_1 {State
MASTER
Interface Eno1 6777736 #如上图所示
virtual_router_id Wuyi
priority #大于配置文件
Advert_int 1
authentication {
Auth _type Pass
auth_pass 1111# security Validation
}
virtual_ipaddress {
192.168.1.190 #虚拟ip
}
Track_ Script {
chk_http_port
}
}
3, modify the configuration file (from)
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
Failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout
router_id lvs_devel
}
vrrp_script Chk_ Http_port {
Script "</dev/tcp/127.0.0.1/81" # Connects and exits
interval 1 # Check every
second Weight-2 # Default Prio:-2 If connect fails
}
vrrp_instance vi_1 {State
BACKUP #区分
interface E no16777736 #如上图所示
virtual_router_id
priority #需要比主小
Advert_int 1
Authentication {
Auth_type Pass
auth_pass 1111 #安全验证
}
virtual_ipaddress {
192.168.1.190 #虚拟ip
}
track_script {
chk_http_port
}
}
Two servers are subject to change, other than individual locations
4, after the modification of the two configuration files need to reboot
# systemctl Restart keepalived
5, at this time the virtual IP in the primary server display
# IP Addr
If the HTTP service in the primary server suddenly hangs up, the virtual IP will be displayed on the backup server, which means that keepalived detects the 81 port stop, and then transfers the service from the primary server to the backup to continue running.