07--张浩淼
一:
客户端:192.168.19.1
添加默认网关:192.168.19.2
二:
路由器:
192.168.18.2
192.168.19.2
开启路由转发功能
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
三 分发器
ipvsadm-1.24-10.i386.rpm安装这个包
ifconfig eth0:0 192.168.18.250/32 broadcast 192.168.18.250 up
[root@localhost Cluster]# route add -host 192.168.18.250 dev eth0:0
[root@localhost Cluster]# ipvsadm -A -t 192.168.18.250:3306 -s rr
[root@localhost Cluster]# ipvsadm -a -t 192.168.18.250:3306 -r 192.168.18.5 -g
[root@localhost Cluster]# ipvsadm -a -t 192.168.18.250:3306 -r 192.168.18.6 -g
[root@localhost Cluster]# ipvsadm-ln
-bash: ipvsadm-ln: command not found
[root@localhost Cluster]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.18.250:3306 rr
-> 192.168.18.6:3306 Route 1 0 0
-> 192.168.18.5:3306 Route 1 0 0
四 安装apache php php-mysql
将index.html insert.php mysql-c.php mysql-i.html mysql-r.php 拷贝到/var/www/html这个目录下
vim mysql-c.php
$con = mysql_connect("192.168.18.4","zhu","123456");
vim insert.php
$con = mysql_connect("192.168.18.4","zhu","123456");
vim mysql-r.php
$con = mysql_connect("192.168.18.250","fu","123456");
因为主的是写 辅的是读得 所以分别添加对应的mysql AB的地址
注意辅助的地址因为有两个BB 还要做分发 所以那里的地址为虚拟的vip
创建步骤看后面
重启 apache 注意一定要安装php
五 mysql A B B
192.168.18.4
192.168.18.5
192.168.18.6
安装步骤请看以前blog
A
创建两个用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'fu'@'%' identified by '123456';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'zhu'@'%' identified by '123456';
mysql> flush privileges;
与前面apache上得 对应了
B1:
vip:ifconfig lo:0 192.168.18.250/32 broadcast 192.168.2.250 up
主机路由:route add –host 192.168.18.250 dev lo:0
默认路由:route add default gw 192.168.18.2
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
mysql重启
B2:
vip:ifconfig lo:0 192.168.18.250/32 broadcast 192.168.2.250 up
主机路由:route add –host 192.168.18.250 dev lo:0
默认路由:route add default gw 192.168.18.2
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
mysql重启
客户端测试 访问apache
点create table
Database created
return index.html创建成功
在mysql A 上
有my_db这个库
点insert values
添加 zhang haomiao 22
1 record added
点select U values 出现信息
zhang haomiao 22
查看分发的效果
不断地的点select U values
[root@localhost html]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.18.250:3306 rr
-> 192.168.18.6:3306 Route 1 0 0
-> 192.168.18.5:3306 Route 1 0 0
[root@localhost html]# ipvsadm -lnc
IPVS connection entries
pro expire state source virtual destination
[root@localhost html]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.18.250:3306 rr
-> 192.168.18.6:3306 Route 1 0 0
-> 192.168.18.5:3306 Route 1 0 0
[root@localhost html]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.18.250:3306 rr
-> 192.168.18.6:3306 Route 1 0 1
-> 192.168.18.5:3306 Route 1 0 1
[root@localhost html]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.18.250:3306 rr
-> 192.168.18.6:3306 Route 1 0 2
-> 192.168.18.5:3306 Route 1 0 1
[root@localhost html]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.18.250:3306 rr
-> 192.168.18.6:3306 Route 1 0 2
-> 192.168.18.5:3306 Route 1 0 2
交替的增长 表示成功...