创建mysql服务器的分发器的脚本
#!/bin/bash
vip=192.168.1.99
rs1=192.168.1.91
rs2=192.168.1.92
gw=192.168.1.1
$port=3306
#set virttual ip address
/sbin/ifconfig eth1:0 $vip broadcast $vip netmask 255.255.255.255 up
/sbin/route add -host $vip dev eth1:0
#clear ipvs tables
/sbin/ipvsadm -C
#set LVS Server
/sbin/ipvsadm -A -t $vip:$port -s rr
/sbin/ipvsadm -a -t $vip:$port -r $rs1:$port -g
/sbin/ipvsadm -a -t $vip:$port -r $rs2:$port -g
#run lvs
/etc/init.d/ipvsadm restart
配置mysql分发B1服务器
#!/bin/bash
vip=192.168.1.99
/sbin/ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
/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
配置mysql分发B2服务器
#!/bin/bash
vip=192.168.1.99
/sbin/ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
/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
配置mysql的A服务器
server-id=1
log-bin=D:/APMXE5/mysql50/logs/master
binlog-do-db=test
配置mysql的B1服务器
server-id=2
master-host=192.168.1.91
master-user=webserver
master-password=123456
配置mysql的B2服务器
server-id=3
master-host=192.168.1.92
master-user=webserver
master-password=123456
配置Apache的PHP网页
写mysql_connect地址连接到192.168.1.91
读mysql_connect地址连接到192.168.1.99