This document is very simple and does not require any technology to completely follow the situation of more than three machines.
Virtual ip192.168.200.16
keepalived Main 192.168.98.11
keepalived Preparation 192.168.98.98
Realserver a 192.168.99.131
Realserver two 192.168.98.11 or 192.168.98.98 (when 11 survived, that is 11 when RS, died 98 when RS)
1, keepalived main 192.168.98.11 for the following installation configuration.
Yum install-y wget ipvsadm vim
wget http://www.keepalived.org/software/keepalived-1.2.24.tar.gz
Tar XF keepalived-1.2.24.tar.gz
CD keepalived-1.2.24
./configure--prefix=/usr/local/keepalived
Make && make install
cp/usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/
cp/usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/
Mkdir/etc/keepalived
cd/usr/local/keepalived/etc/keepalived/
Ln-s/usr/local/keepalived/sbin/keepalived/usr/sbin/
Chkconfig--add keepalived
Chkconfig keepalived on
vim/etc/keepalived/keepalived.conf paste the following.
Vrrp_instance Ha44 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 100
#advert_int广播间隔, this value affects how long master hangs switch to backup, I measured the settings 2 or 3 words switch interval is short
Advert_int 2
Authentication {
Auth_type PASS
Auth_pass 1234
}
virtual_ipaddress {
192.168.200.16
#可以自定义掩码, broadcast.
# 192.168.200.16/16 BRD 192.168.255.255 Dev eth0
}
#可以自定义网关, but I didn't use it that way.
# virtual_routes {
# 192.168.200.0/16 via 192.168.98.1 Dev eth0
# }
}
#如果想用lvs的功能, add the following, Keepalived automatically calls the Ipvsadm feature.
Virtual_server 192.168.200.16 80 {
Delay_loop 3
Lb_algo RR
Lb_kind DR
Persistence_timeout 50
Protocol TCP
Real_server 192.168.98.11 80 {
Weight 20
Tcp_check
{
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
Real_server 192.168.99.131 80 {
Weight 100
Tcp_check
{
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}
Save exit
/etc/init.d/keepalived start
2, keepalived preparation 192.168.98.98 The following installation configuration.
Yum install-y wget ipvsadm vim
wget http://www.keepalived.org/software/keepalived-1.2.24.tar.gz
Tar XF keepalived-1.2.24.tar.gz
CD keepalived-1.2.24
./configure--prefix=/usr/local/keepalived
Make && make install
cp/usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/rc.d/init.d/
cp/usr/local/keepalived/etc/sysconfig/keepalived/etc/sysconfig/
Mkdir/etc/keepalived
cd/usr/local/keepalived/etc/keepalived/
Ln-s/usr/local/keepalived/sbin/keepalived/usr/sbin/
Chkconfig--add keepalived
vim/etc/keepalived/keepalived.conf paste the following.
Vrrp_instance Ha44 {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 20
#advert_int广播间隔, this value affects how long master hangs switch to backup, I measured the settings 2 or 3 words switch interval is short
Advert_int 2
Authentication {
Auth_type PASS
Auth_pass 1234
}
virtual_ipaddress {
192.168.200.16
#可以自定义掩码, broadcast.
# 192.168.200.16/16 BRD 192.168.255.255 Dev eth0
}
#可以自定义网关, but I didn't use it that way.
# virtual_routes {
# 192.168.200.0/16 via 192.168.98.1 Dev eth0
# }
}
#如果想用lvs的功能, add the following, Keepalived automatically calls the Ipvsadm feature.
Virtual_server 192.168.200.16 80 {
Delay_loop 3
Lb_algo RR
Lb_kind DR
Persistence_timeout 50
Protocol TCP
Real_server 192.168.98.98 80 {
Weight 20
Tcp_check
{
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
Real_server 192.168.99.131 80 {
Weight 100
Tcp_check
{
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
}
}
}
Save exit
Service keepalived Start
3, Realserver a 192.168.99.131 configuration.
Yum install-y vim
Vim/etc/init.d/lvsrs paste the following content.
#!/bin/sh
#chkconfig: 345 61 61
#description: Lvsrs
vip=192.168.200.16
Usage ()
{
echo "Usage: ' basename ' (start|stop)"
Exit 1
}
If [$#-ne 1];then
Usage
Fi
Case $ in
Start
echo "Configuring VIP for Real Server"
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/eth0/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/eth0/arp_announce
/sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 up
/sbin/route add-host $VIP Dev lo:0
If [$?-eq 0]
Then
Sleep 5
echo "Real Server started."
Else
echo "Error occurred!"
Fi
;;
Stop
/sbin/ifconfig lo:0 Down
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/eth0/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/eth0/arp_announce
If [$?-eq 0]
Then
Sleep 2
echo "Real Server has stopped."
Else
Echo ' Error occurred occurred! Maybe "lo:0" has stopped already. '
Fi
;;
*)
Usage
Esac
Save exit
chmod +x/etc/init.d/lvsrs
Chkconfig--add Lvsrs
Service Lvsrs Start
4. Realserver two 192.168.98.11 or 192.168.98.98, these two because has been configured keepalived, by the keepalived service escrow ipvsadm, so they do not need to configure what has naturally become realserver.
Note:
1, the above configuration for these three machines are provided HTTP service situation.
2, if more than one keepalived server needs to provide more services, copy to add more Virtual_server and modify the port. If you do not configure the Virtual_server section, keepalived will not escrow LVS, then only one machine work at the same time, this problem, VIP will float to the next stage. VIP in which, which is the work, so generally, LVS and keepalived is used in conjunction with the need to configure the Virtual_server section.
3, if the configuration of multiple vrrp_instance, each instance need to have a unique virtual_router_id, and other instance the same is not. When multiple machines start the keepalived service, they are paired with the value of virtual_router_id.
4, keepalived configuration files in the priority of the setting of a lot of mystery! Set the unscientific will backfire! It is recommended to check the relevant information before setting again. There's an article on the poke here!
CentOS build Keepalived+ipvsadm for high-availability LVS distribution