一、负载均衡器端
1.安装(MASTER、BACKUP)
A、wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -O /etc/yum.repos.d/CentOS-Base.repo
B、yum makecache
C、yum -y update
D、yum -y install ipvsadm modcluster piranha system-config-cluster php54 php54-cli php54-common
2.撰写配置文件
vi /etc/sysconfig/ha/lvs.cf
serial_no = 28
primary = 10.10.10.100
primary_private = 172.28.29.100
service = lvs
backup_active = 1
backup = 10.10.10.200
backup_private = 172.28.29.200
heartbeat = 1
heartbeat_port = 539
keepalive = 6
deadtime = 18
network = direct
debug_level = NONE
monitor_links = 0
syncdaemon = 0
virtual web_http {
active = 1
address = 10.10.10.250 eth0:1
vip_nmask = 255.255.255.0
port = 80
send = "GET / HTTP/1.0\r\n\r\n"
expect = "HTTP"
use_regex = 0
load_monitor = none
scheduler = wrr
protocol = tcp
timeout = 6
reentry = 15
quiesce_server = 0
server web_realserver1 {
address = 10.10.10.101
active = 1
port = 80
weight = 1
}
server web_realserver2 {
address = 10.10.10.102
active = 1
port = 80
weight = 1
}
server web_realserver3 {
address = 10.10.10.103
active = 1
port = 80
weight = 1
}
server web_realserver4 {
address = 10.10.10.104
active = 1
port = 80
weight = 1
}
}
virtual bbs_http {
active = 1
address = 172.28.29.250 eth1:1
vip_nmask = 255.255.255.0
port = 80
send = "GET / HTTP/1.0\r\n\r\n"
expect = "HTTP"
use_regex = 0
load_monitor = none
scheduler = wrr
protocol = tcp
timeout = 6
reentry = 15
quiesce_server = 0
server bbs_realserver1 {
address = 172.28.29.101
active = 1
port = 80
weight = 1
}
server bbs_realserver2 {
address = 172.28.29.102
active = 1
port = 80
weight = 1
}
server bbs_realserver3 {
address = 172.28.29.103
active = 1
port = 80
weight = 1
}
server bbs_realserver4 {
address = 172.28.29.104
active = 1
port = 80
weight = 1
}
}
3.启动LVS集群(先master后backup)
/etc/init.d/pulse start
二、后端的realserver端
1.撰写脚本
vi /etc/init.d/lvs_realserver
#!/bin/bash
#description: LVS realsever
. /etc/rc.d/init.d/functions
WEB_VIP="10.10.10.250 172.28.29.250"
start(){
num=0
echo -ne 'Start LVS of RealServer'
for loop in $WEB_VIP
do
ifconfig lo:$num $loop netmask 255.255.255.255 up
# /sbin/route add -host $loop dev lo:$num
num=$[num+1]
done
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 " OK"
}
stop(){
echo -ne 'Stop LVS of RealServer'
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
num=0
for loop in $WEB_VIP
do
/sbin/ifconfig lo:$num down
# /sbin/route del -host $loop
num=$[num+1]
done
echo " OK"
}
restart(){
stop
start
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
/sbin/ip add
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
转载于:https://blog.51cto.com/liang3391/1246192