MySQL-分布式架构-MyCAT( 三 )

1.2 Mycat的安装
MySQL分布式架构介绍:
 

MySQL-分布式架构-MyCAT

文章插图
 
 
1.2.1 安装JAVA环境
yum install -y java1.2.2 上传到/application 并解压
略官网:http://www.mycat.io/
1.2.3 配置文件介绍
conf:schema.xml 主配置文件(读写分离、高可用、分布式策略定制、节点控制) server.xml mycat软件本身相关的配置 rule.xml 分片规则配置文件,记录分片规则列表、使用方法等xxxx.txt 分片参数功能有关logs目录:wrapper.log ---->mycat启动日志 mycat.log ---->mycat详细工作日志1.2.4 启动mycat
[root@db02 ~]# vim /etc/profile export PATH=/application/mycat/bin:$PATH [root@db02 ~]# source /etc/profile [root@db02 ~]# mycat start [root@db02 ~]# mysql -uroot -p123456 -h 10.0.0.52 -P8066 1.3 测试数据准备
## db01:mysql -S /data/3307/mysql.sock grant all on *.* to root@'10.0.0.%' identified by '123';source /root/world.sqlmysql -S /data/3308/mysql.sock grant all on *.* to root@'10.0.0.%' identified by '123';source /root/world.sql1.4 核心配置文件使用介绍(schema.xml)
(1)逻辑库定义<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="sh1"> </schema> (2)数据节点定义 <dataNode name="sh1" dataHost="oldguo1" database= "world" /> (3)数据主机定义 <dataHost name="oldguo1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1"><heartbeat>select user()</heartbeat><writeHost host="db1" url="10.0.0.51:3307" user="root" password="123"><readHost host="db2" url="10.0.0.51:3309" user="root" password="123" /></writeHost></dataHost> 1.5 Mycat实现读写分离功能
(1)配置conf文件--schema.xml
[root@db02 /application/mycat/conf]# cat schema.xml <?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="sh1"> </schema> <dataNode name="sh1" dataHost="oldguo1" database= "world" /> <dataHost name="oldguo1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1"> <heartbeat>select user()</heartbeat> <writeHost host="db1" url="10.0.0.51:3307" user="root" password="123"> <readHost host="db2" url="10.0.0.51:3309" user="root" password="123" /> </writeHost> </dataHost> </mycat:schema> (2)Mycat重启生效:
mycat restart(3)模拟测试
[root@db02 /application/mycat/conf]# mysql -uroot -p123456 -h 10.0.0.52 -P8066mysql> select @@server_id; ----模拟查询mysql> begin; select @@server_id;commit; ---模拟写入1.6 读写分离+高可用功能
[root@db01 conf]# mv schema.xml schema.xml.rw [root@db01 conf]# vim schema.xml <?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="sh1"> </schema> <dataNode name="sh1" dataHost="oldguo1" database= "world" /> <dataHost name="oldguo1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1"> <heartbeat>select user()</heartbeat> <writeHost host="db1" url="10.0.0.51:3307" user="root" password="123"> <readHost host="db2" url="10.0.0.51:3309" user="root" password="123" /> </writeHost> <writeHost host="db3" url="10.0.0.52:3307" user="root" password="123"> <readHost host="db4" url="10.0.0.52:3309" user="root" password="123" /> </writeHost> </dataHost> </mycat:schema> 真正的 writehost:负责写操作的writehost standby writeHost :和readhost一样,只提供读服务 当写节点宕机后,后面跟的readhost也不提供服务,这时候standby的writehost就提供写服务,后面跟的readhost提供读服务。测试: mysql -uroot -p123456 -h 127.0.0.1 -P 8066 show variables like 'server_id'; 读写分离测试 mysql -uroot -p -h 127.0.0.1 -P8066 show variables like 'server_id'; show variables like 'server_id'; show variables like 'server_id'; begin; show variables like 'server_id'; 对db01 3307节点进行关闭和启动,测试读写操作


推荐阅读