vim schema.xml
47 <writeHost host="hostM1" url="server33.lalala.com:3306" user="mycat"
48 password="Mycat+007">
49 <!-- can have multi read hosts -->
50 </writeHost>
51 <writeHosthost="hostS1" url="server44.lalala.com:3306" user="mycat"
52 password="Mycat+007">
53 </writeHost>
server33,server44:
vim /etc/my.cnf
22 lower_case_table_names = 1
mysql>CREATE USER mycat identified by 'Mycat+007';
mysql>grant all privileges on *.* to mycat@'%';
配置成功,启动~
mycat start ,查看日志 wrapper.log
检验
mycat的登陆:
mysql -umycat -pMycat+007 -P8066 -h127.0.0.1
查看server44,和server33的mycat数据是否同步~
建表:
create table employee (id int not null primary key,name varchar(100),sharding_id int not null);
插入数据:
insert into employee(id,name,sharding_id) values(1,'leader us',10000);
insert into employee(id,name,sharding_id) values(2, 'me',10010);
insert into employee(id,name,sharding_id) values(3, 'mycat',10000);
insert into employee(id,name,sharding_id) values(4, 'mydog',10010);
在两台mycat上,都能看到相同的数据,即为成功
并且在server33和server44上的db1数据库中,也能看见刚刚创建的数据
heartbeat+drbd+mycat实现高可用分布式存储
存储:drbd
vim /etc/drbd.d/lalalala.res
resource lalalala {
meta-disk internal;
device /dev/drbd8;
syncer {
verify-alg sha1;
}
on server33.lalala.com {
disk /dev/vdc;
address 172.25.88.33:7789;
}
on server44.lalala.com {
disk /dev/vdb;
address 172.25.88.44:7789;
}
}
高可用
vim ha.cf
initdead 60 资源初始化时间,如果设置过大,接管时间可能很长,不用担心,只需要耐心等待~
vim haresources
server33.lalala.com IPaddr::172.25.88.100/24/eth0 drbddisk::lalalala Filesystem::/dev/drbd8::/home/mycat/app/mycat/lib::ext4 mycatd
其他配置照旧~
需要指出的是,因为mycat不属于LSB,所以要自己编写脚本启动文件,我写的太粗糙了,不要学我.....
vim /etc/init.d/mycatd 注意启动脚本的位置
3 path=/home/mycat/app/mycat/bin/mycat #路径为执行mycat的环境,可以用which查看
4 function usage(){
5 echo "$0 {start|stop|restart}"
6 exit 1
7 }
8 [ $# -ne 1 ] && usage #如果没有输入参数,就显示本脚本用法
9
10
11 case $1 in
12 start)
13 $path/mycat start # &>/dev/null &
16 ;;
17 stop)
18 $path/mycat stop &>/dev/null &
21 ;;
22 restart)
23 $path/mycat start &>/dev/null &
24 $path/mycat stop &>/dev/null &
27 ;;
28 *)
29 printf "Usage:$0 {start|stop|restart}\n"
30 esac
启动server33的heartbeat!
可以看到IP,存储,服务全都启动拉!
查看挂载点和IP
高可用的接管,take over