--------------------------------------master---------------------------------------
echo "1" > /proc/sys/net/ipv4/ip_forward
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
tar -zxvf ipvsadm-1.26.tar.gz
cd ipvsadm-1.26
make&&make install
查看
ipvsadm -L -n
wget http://www.keepalived.org/software/keepalived-2.0.9.tar.gz
tar zxvf keepalived-2.0.9.tar.gz
cd keepalived-2.0.9
./configure --perfix=/ --mandir=/usr/local/share/man
make &&make install
cp keepalived/etc/init.d/keepalived.rh.init /etc/init.d/keepalived
chmod +x /etc/init.d/keepalived
cp keepalived/etc/init.d/keepalived.sysconfig /etc/sysconfig/keepalived
chkconfig --add keepalived
chkconfig --level 345 keepalived on
编辑
vi /etc/sysconfig/keepalived
global_defs {
notification_email {
finalsd@gmail.com
}
notification_email_from finaxx@gmail.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id haproxy-ha
}
vrrp_sync_group VG1 {
group {
VI1
}
}
vrrp_instance VI1 {
state BACKUP
smtp_alert
notify_fault "/root/script/notify_mail.sh fault"
notify_master "/root/script/notify_mail.sh master"
nopreempt
insterface eth1
track_interface {
eth 0
eth 1
}
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass abc123..
}
virtual_ipaddress {
192.168.1.1/24 dev eth1 scope global
}
}
virtual_server 192.168.1.1 80 {
delay_loop 3
lb_algo wlc #rr wrr
lb_kind DR
persistence_timeout 1200
protocol TCP
ha_suspend
real_server 192.168.1.11 80 {
weight 3
TCP_CHECK {
nb_get_retry 3
delay_before_retry 3
connect_timeout 3
connect_port 80
}
}
real_server 192.168.1.12 80 {
weight 3
TCP_CHECK {
connect_timeout 3
connect_port 80
}
}
}
service keepalived start
------------------------------------------backup-------------------------------------------------
和master一样,priority改为100,nopreempt删掉
---------------------------------------所有real server---------------------------------------------
vi /etc/init.d/realserver
!/bin/sh
VIP=192.168.1.1
. /etc/rc.d/init.d/functions
case "$1" in
禁用本地的ARP请求、绑定本地回环地址
start)
/sbin/ifconfig lo down
/sbin/ifconfig lo up
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
/sbin/sysctl -p >/dev/null 2>&1
/sbin/ifconfig lo:0 VIP dev lo:0
echo "LVS-DR real server starts successfully.\n"
;;
stop)
/sbin/ifconfig lo:0 down
/sbin/route del VIP"isRoOn=
/bin/netstat -rn | grep "isLoON" == "" -a "0 {start|stop|status}"
exit 1
esac
exit 0
chmod +x /etc/init.d/realserver
echo "/etc/init.d/realserver start" >> /etc/rc.d/rc.local
service realserver start