LVS +Keepalived+ Ldirector负载均衡
LVS + Ldirector负载均衡
1、DR安装配置:
(1)安装IPVSADM
yum -y install ipvsadm
cat /etc/init.d/lvsDR
#dscription: Start LVS of Director server
VIP=192.168.1.50
RIP1=192.168.1.60
RIP2=192.168.1.61
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo "Start LVS of Director Server"
# set the Virtual IP Address and sysctl parameter
/sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up
echo "1" >/proc/sys/net/ipv4/ip_forward
#Clear IPVS table
/sbin/ipvsadm -C
#set LVS
/sbin/ipvsadm -A -t $VIP:3306 -s rr -p 600
/sbin/ipvsadm -a -t $VIP:3306 -r $RIP1:3306 -g
/sbin/ipvsadm -a -t $VIP:3306 -r $RIP2:3306 -g
#Run LVS
/sbin/ipvsadm
;;
stop)
echo "Close LVS Directorserver"
echo "0" >/proc/sys/net/ipv4/ip_forward
/sbin/ipvsadm -C
/sbin/ifconfig eth0:0 down
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
2、安装ldirectord
需要安装四个软件包:
heartbeat-1.2.4-1.i386.rpm heartbeat-pils-1.2.4-1.i386.rpm
heartbeat-ldirectord-1.2.4-1.i386.rpm heartbeat-stonith-1.2.4-1.i386.rpm
rpm -ivh *.rpm --nodeps --force
修改配置文件:
cat /etc/ha.d/ldirectord.cf
#Global Directives
checktimeout=20
checkinterval=10
fallback=127.0.0.1:3306
autoreload=yes
logfile="/var/log/ldirectord.log"
quiescent=no
# Sample for an mysql virtual service
virtual=192.168.1.50:3306
real=192.168.1.60:3306 gate
real=192.168.1.61:3306 gate
fallback=127.0.0.1:3306 gate
service=mysql
checktype=negotiate
login="root"
passwd="mysql"
request="show status"
scheduler=rr
3、real server配置: 在三个节点均这样操作:
增加/etc/init.d/lvsrs 脚本:
cat /etc/init.d/lvsrs
#!/bin/bash
#description : Start Real Server
VIP=192.168.1.50
. /etc/rc.d/init.d/functions
case "$1" in
start)
echo "Start LVS of Real Server"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 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
;;
stop)
/sbin/ifconfig lo:0 down
echo "Close LVS Director server"
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 "Usage: $0 {start|stop}"
exit 1
esac