DR模式下的mysql (abb读写分离)
?
客戶端: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
?
添加?fu??????? fuzhilei????????? 22
?
1 record added
?
點select U values 出現信息
?
fu zhilei?? ?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
?
?
02-付志磊
轉載于:https://blog.51cto.com/fuzhilei/1078813
總結
以上是生活随笔為你收集整理的DR模式下的mysql (abb读写分离)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 什么是基准测试?
- 下一篇: http超文本传输协议的http头部分析