I. Introduction of KeepAlive
keepalived is a powerful auxiliary tool specifically designed for LVS to provide failover and health check functions, such as determining the availability of the LVS load Scheduler, node servers, and timely isolation and replacement of new servers. When the failed host resumes, rejoin the cluster. keepalived can also be used as a hot standby software when used in a non-LVS clustered Environment .
keepalived) hot backup protocol to implement Linux in a software way server's multi-machine hot standby function. vrrp is a backup solution for routers ----- address to provide services externally; At the same time in each hot standby group, only one primary server is available, and the other servers are in a redundant state. If the current online server fails, the other servers will automatically take over (priority decision succession order) virtual ip address to continue to provide services.
each server within a hot standby group can be the primary server, and the virtual IP Address (VIP) can be transferred between servers in the hot standby group, so also known as drift IP address, when using keepalived , drift address implementation does not need to manually establish a virtual interface configuration file (such as eth0:0), but is automatically managed by keepalived according to the configuration file.
Second, the principle of keepalive
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/7E/B0/wKioL1cHYwuCxbAQAAC3Ecrye0M010.jpg "title=" K.jpg " alt= "Wkiol1chywucxbaqaac3ecrye0m010.jpg"/>
keepalived will have three processes after startup
Parent Process: memory management, child process management, etc.
subprocess: VRRP child process
subprocess: Healthchecker child process
It is shown that two sub-processes are supervised by the system watchdog, two sub-processes are themselves complex, healthchecker the child process to check the health of the respective servers, such as HTTP,LVS, etc., if the healthchecker child process if the service on master is not available, it will notify the sibling VRRP child process on the machine, let him delete the advertisement, and remove the virtual IP, and convert it to the backup state.
III. Deployment of keepalived Services
Environment: centos6.5-x64 bit system
ip:172.16.16.15 (Master), 172.16.16.16 (Backup)
vip:172.16.16.100
Close Iptables,selinux
Just demonstrate the common configuration of keepalive, so yum installation, if necessary, please Baidu source code installation.
[email protected] ~]# Yum install keepalived-y
KeepAlive master configuration file under/etc/keepalived/,
1. Achieve a simple VIP drift
Master configuration file:
! Configuration File for Keepalived
Global_defs {
Notification_email {
[email protected] ######### #收件人邮箱, one recipient per line
}
Notification_email_from [email protected] ######## #发件人邮箱, can not exist
Smtp_server 127.0.0.1 ########## #邮件服务器地址
Smtp_connect_timeout ####### #邮件服务器连接超时时间
router_id Lvs_devel ######## #服务器的标识
}
Vrrp_instance vi_1 {####### #热备实例
State MASTER ####### #热备状态
Interface eth0 ######## #监控心跳, forwarding announcement
virtual_router_id Wuyi ######## #虚拟路由id, the master must be consistent
Priority ######## #定义优先级, the greater the value the higher the precedence
Advert_int 1 ######## #主备宣告的时间间隔,
Authentication {######## #设置验证
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
172.16.16.100 ##### #定义vip, note that this machine only a piece of network card, the default addition to eth0, if more than one network card, or the child card, can be set to 172.16.16.100 Dev Eth1[label eth0:0] and other designated devices
}
}
Backup configuration file:
! Configuration File for Keepalived
Global_defs {
Notification_email {
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
router_id Lvs_devel
}
Vrrp_instance Vi_1 {
State BACKUP # # #修改此节点为备
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority ####### #优先级要比主低
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
172.16.16.100
}
}
Start with two points of keepalived
Master
[Email protected] keepalived]# IP addr
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0C:29:C2:CC:FF BRD FF:FF:FF:FF:FF:FF
inet 172.16.16.15/16 BRD 172.16.255.255 scope global eth0
inet 172.16.16.100/32 Scope global eth0
Inet6 FE80::20C:29FF:FEC2:CCFF/64 Scope link
Valid_lft Forever Preferred_lft Forever
Backup
[[Email protected] keepalived]# IP addr Show
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0c:29:5c:ef:24 BRD FF:FF:FF:FF:FF:FF
inet 172.16.16.16/16 BRD 172.16.255.255 scope global eth0
Inet6 FE80::20C:29FF:FE5C:EF24/64 Scope link
Valid_lft Forever Preferred_lft Forever
Close Master's keepalive,
Master
[[Email protected] keepalived]# IP addr
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0C:29:C2:CC:FF BRD FF:FF:FF:FF:FF:FF
inet 172.16.16.15/16 BRD 172.16.255.255 scope global eth0
Inet6 FE80::20C:29FF:FEC2:CCFF/64 Scope link
Valid_lft Forever Preferred_lft Forever
Backup
[[Email protected] keepalived]# IP addr
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0c:29:5c:ef:24 BRD FF:FF:FF:FF:FF:FF
inet 172.16.16.16/16 BRD 172.16.255.255 Scope Global eth0
inet 172.16.16.100/32 Scope global eth0 ###### #vip漂移到backup
Inet6 FE80::20C:29FF:FE5C:EF24/64 Scope link
Valid_lft Forever Preferred_lft Forever
2. Define simple script commands
Under the/etc/keepalived/directory, the down file is detected, VIP drift
Master/backup
Global_defs {
Notification_email {
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 127.0.0.1
! Configuration File for Keepalived
Global_defs {
Notification_email {
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
router_id Lvs_devel
}
Vrrp_script chk_maintainace {###### #定义检测脚本参数vrrp_script, Chk_maintainace Custom
Script "[[[-f/etc/keepalived/down]] && Exit 1 | | Exit 0 "# #可以为脚本, or command
Interval 1 ##### #检测down文件的时间间隔为1秒
Weight-2 ####### #检测到down文件, Priority-2 (i.e. 100-2)
}
Vrrp_instance Vi_1 {
State Master/backup
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 100/99
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
172.16.16.100
}
Track_script {
Chk_maintainace ########### #追踪脚本
}
}
[[Email protected] keepalived]# IP addr Show eth0
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0C:29:C2:CC:FF BRD FF:FF:FF:FF:FF:FF
inet 172.16.16.15/16 BRD 172.16.255.255 Scope Global eth0
inet 172.16.16.100/32 Scope global eth0
Inet6 FE80::20C:29FF:FEC2:CCFF/64 Scope link
Valid_lft Forever Preferred_lft Forever
[[email protected] keepalived]# touch Down
[[Email protected] keepalived]# IP addr Show eth0
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0C:29:C2:CC:FF BRD FF:FF:FF:FF:FF:FF
inet 172.16.16.15/16 BRD 172.16.255.255 Scope Global eth0
Inet6 fe80::20c:29ff:fec2:ccff/64 scope link ##### #vip漂移
Valid_lft Forever Preferred_lft Forever
[[Email protected] keepalived]# IP addr Show eth0
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0c:29:5c:ef:24 BRD FF:FF:FF:FF:FF:FF
inet 172.16.16.16/16 BRD 172.16.255.255 scope global eth0
inet 172.16.16.100/32 Scope global eth0 ##### #vip漂移到backup
Inet6 FE80::20C:29FF:FE5C:EF24/64 Scope link
Valid_lft Forever Preferred_lft Forever
[[email protected] keepalived]# rm-rf down main delete down
[[Email protected] keepalived]# IP addr Show eth0
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0C:29:C2:CC:FF BRD FF:FF:FF:FF:FF:FF
inet 172.16.16.15/16 BRD 172.16.255.255 Scope Global eth0
inet 172.16.16.100/32 Scope global eth0 ##### #vip漂移回master
Inet6 FE80::20C:29FF:FEC2:CCFF/64 Scope link
Valid_lft Forever Preferred_lft Forever
Linux keepalived detailed