环境:
CentOS6.4 64bit
ipvsadm-1.24.tar.gz
keepalived-1.1.19.tar.gz
IP部署:
VIP:172.16.100.5
DIP1:172.16.100.1
DIP2:172.16.100.2
RIP1:172.16.100.3
RIP2:172.16.100.4
说明:VIP在防火墙上做映射
安装:
ln -s /usr/src/kernels/2.6.32-358.el6.x86_64/ /usr/src/linux
tar zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
make && make install
tar zxvf keepalived-1.1.19.tar.gz
yum install openssl-devel popt-devel
cd keepalived-1.1.19
./configure
make
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
service keepalived start
安装完成。
配置RealServer:
#!/bin/bash
VIP=172.16.100.5
. /etc/init.d/functions
case "$1" in
start)
/sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP
/sbin/route add -host $VIP dev lo:0
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
sysctl -p > /dev/null 2>&1
echo "RealServer Start OK"
;;
stop)
ifconfig lo:0 down
/sbin/route del $VIP > /dev/null 2>&1
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 "RealServer Stop OK"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
配置完成。
配置负载均衡器: