Keepalived configuration, you can refer to: http://www.keepalived.org/documentation.html
Environmental Preparedness
The LINUX version required for the system is: the keepalived version required by 2.6.9‐5.ELSMP is: 1.1.20
? Check Linux version
[Root@test01 etc]# Uname-r
2.6.9-5.elsmp
? Check the keepalived version
[Root@test01 keepalived]# pwd
/root/disk/keepalived
[Root@test01 keepalived]# Cat VERSION
1.1.20 2 Target
Two servers, one master standby. provides two virtual IP.
Server a:10.10.0.41 (primary server)
Server b:10.10.0.118 (standby server)
Virtual IP:10.10.0.44/45
Normal condition, the primary server provides the service, the primary server fails, the standby server takes over. 3 Installation KeepAlive
[root@test01 keepalived]#./configure
......
[Root@test01 keepalived]# make
......
[root@test01 keepalived]# make install
......
# cp/usr/local/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/
# cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig/
# mkdir/etc/keepalived
# cp/usr/local/etc/keepalived/keepalived.conf/etc/keepalived/
# cp/usr/local/sbin/keepalived/usr/sbin/
Make system start service convenient management.
# vi/etc/rc.local
/etc/init.d/keepalived start
Add the above line. 4 configuration keepalived (Master/slave mode) 4.1 Primary Server
# vi/etc/keepalived/keepalived.conf
Configured as follows:
! 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 30
router_id Lvs_devel
}
Vrrp_instance Vi_1 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 51 # Keep The primary standby server consistent
Priority 100 # Priority (primary server should be higher than backup server)
Advert_int 1 # Heartbeat Broadcast time interval (sec)
Authentication {
Auth_type Pass
Auth_pass 1111
}
virtual_ipaddress {
10.10.0.44 # Virtual IP address, can be multiple.
10.10.0.45
} 4.2 standby server
# vi/etc/keepalived/keepalived.conf
Configured as follows:
! 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 30
router_id Lvs_devel
}
Vrrp_instance Vi_1 {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 51 # Keep The primary standby server consistent
Priority 90 # Priority (primary server should be higher than backup server) Advert_int 1 # Heartbeat Broadcast time interval (sec)
Authentication {
Auth_type Pass
Auth_pass 1111
}
virtual_ipaddress {
10.10.0.44 # Virtual IP address, can be multiple.
10.10.0.45
}
} 5 Start the primary server keepalived
# service Keepalived Start
# IP A
1:LO:MTU 16436 Qdisc Noqueue
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:MTU 1500 Qdisc pfifo_fast Qlen
1000
Link/ether 00:10:5C:C8:1C:F2 BRD FF:FF:FF:FF:FF:FF
inet 10.10.0.41/16 BRD 10.10.255.255 Scope Global eth0
inet 10.10.0.44/32 Scope Global eth0 inet 10.10.0.45/32 scope Global eth0
Inet6 FE80::210:5CFF:FEC8:1CF2/64 Scope link
Valid_lft Forever Preferred_lft Forever
3:SIT0:MTU 1480 Qdisc NoOp
Link/sit 0.0.0.0 BRD 0.0.0.0
As you can see, the 10.10.0.44/45 two virtual IP has been hooked up to the NIC Eth0. 6 boot standby server keepalived
# service Keepalived Start
# IP A
1:LO:MTU 16436 Qdisc Noqueue
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 BRD 127.255.255.255 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:ETH0:MTU 1500 Qdisc pfifo_fast Qlen
1000
Link/ether 00:14:2A:03:33:CA BRD FF:FF:FF:FF:FF:FF
inet 10.10.0.118/16 BRD 10.10.255.255 Scope Global eth0
Inet6 FE80::214:2AFF:FE03:33CA/64 Scope link
Valid_lft Forever Preferred_lft Forever
3:SIT0:MTU 1480 Qdisc NoOp
Link/sit 0.0.0.0 BRD 0.0.0.0
As you can see, the 10.10.0.44/45 two virtual IP is not hooked up on the NIC Eth0. 7 Verification Test 7.1 Validation Preparation
Test Service: Start the Apache service separately on both servers and modify the default index.html file.
Displays the current server IP for identification.
# Curl http://10.10.0.118
It works! 10.10.0.118
# Curl http://10.10.0.41
It works! 10.10.0.41
You can see that the HTTPD service for two servers is normal. 7.2 Check the working status of the virtual IP
# Curl http://10.10.0.44
It works! 10.10.0.41
# Curl http://10.10.0.45
It works! 10.10.0.41 7.3 Stop the primary server keepalived
# Service Keepalived Stop
# IP A
[root@test01 ~]# IP A
1:LO:MTU 16436 Qdisc Noqueue
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:MTU 1500 Qdisc Pfifo_fast
Qlen 1000
Link/ether 00:10:5C:C8:1C:F2 BRD FF:FF:FF:FF:FF:FF
inet 10.10.0.41/16 BRD 10.10.255.255 Scope Global eth0
Inet6 FE80::210:5CFF:FEC8:1CF2/64 Scope link
Valid_lft Forever Preferred_lft Forever
3:SIT0:MTU 1480 Qdisc NoOp
Link/sit 0.0.0.0 BRD 0.0.0.0
As you can see, the 10.10.0.44/45 two virtual IP is not hooked up on the NIC Eth0. 7.4 Verify standby server keepalived status
[Root@localhost ~]# Curl http://10.10.0.44
It works! 10.10.0.118
[Root@localhost ~]# Curl http://10.10.0.45
It works! 10.10.0.118 7.5 Reboot The primary server keepalived State
# service Keepalived Start
# IP A
1:LO:MTU 16436 Qdisc Noqueue
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:MTU 1500 Qdisc pfifo_fast Qlen
1000
Link/ether 00:10:5C:C8:1C:F2 BRD FF:FF:FF:FF:FF:FF
inet 10.10.0.41/16 BRD 10.10.255.255 Scope Global eth0
inet 10.10.0.44/32 Scope Global eth0
inet 10.10.0.45/32 Scope Global eth0
Inet6 FE80::210:5CFF:FEC8:1CF2/64 Scope link
Valid_lft Forever Preferred_lft Forever
3:SIT0:MTU 1480 Qdisc NoOp
Link/sit 0.0.0.0 BRD 0.0.0.0 7.6 Verifying primary server keepalived status
[Root@localhost ~]# Curl http://10.10.0.44
It works! 10.10.0.41
[Root@localhost ~]# Curl http://10.10.0.45
It works! 10.10.0.41 8 Attachment: Master/master configuration mode
The backup server (server B) in the Master/slave scenario is usually a device, a bit wasteful. We can be used to run other services, so that two hosts to form mutual hot standby.
Server a:192.168.1.10, Virtual ip:192.168.1.100
Server b:192.168.1.20, Virtual ip:192.168.1.200
Modify configuration file: Server A Host:
Global_defs {
router_id Lvs_devel
}
Vrrp_instance Vi_1 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 100
Advert_int 1
Authentication {
Auth_type Pass
Auth_pass 1111
}
virtual_ipaddress {
192.168.1.100
}
}
Vrrp_instance Vi_2 {
State BACKUP Interface Eth0
VIRTUAL_ROUTER_ID 52
Priority 99
Advert_int 1
Authentication {
Auth_type Pass
Auth_pass 1111
}
virtual_ipaddress {
192.168.1.200
}
}
Server B Host:
Global_defs {
router_id Lvs_devel
}
Vrrp_instance Vi_1 {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID Wuyi Priority 99
Advert_int 1
Authentication {
Auth_type Pass
Auth_pass 1111
}
virtual_ipaddress {
192.168.1.100
}
}
Vrrp_instance Vi_2 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 52
Priority 100
Advert_int 1
Authentication {
Auth_type Pass
Auth_pass 1111
}
virtual_ipaddress {
192.168.1.200
}
}
In fact very simple, we added a new configuration vi_2 (note virtual_router_id different). However, this is used Server B to host the servers, so that server A, Server B each owns the primary virtual IP, while backing up
Each other's virtual IP. This scenario can be a different service, or a access diversion for the same service (with DNS use).