MySQL分布式架构介绍
1. schema拆分及业务分库 2. 垂直拆分-分库分表 3. 水平拆分-分片 企业代表产品 360 Atlas-Sharding Alibaba cobar Mycat TDDL Heisenberg Oceanus Vitess OneProxy DRDS
MyCAT分布式架构部署
下载解压文件
Mycat-server-xxxxx.linux.tar.gz http://dl.mycat.io/ [root@db01 data]# tar xf Mycat-server-1.6.5-release-20180117003034-linux.tar.gz
软件目录结构
[root@db01 data]# ll mycat/ total 12 drwxr-xr-x 2 root root 190 Oct 26 00:54 bin drwxrwxrwx 2 root root 6 Mar 1 2016 catlet drwxrwxrwx 4 root root 4096 Oct 26 00:54 conf drwxr-xr-x 2 root root 4096 Oct 26 00:54 lib drwxrwxrwx 2 root root 6 Jan 17 2018 logs -rwxrwxrwx 1 root root 219 Jan 17 2018 version.txt
配置环境变量
vim /etc/profile export PATH=/data/mycat/bin:$PATH source /etc/profile
预先安装Java运行环境
yum install -y java
启动和连接
启动 mycat start [root@db01 data]# netstat -lnp|grep 8066 tcp6 0 0 :::8066 :::* LISTEN 4673/java [root@db01 data]# netstat -lnp|grep 9066 tcp6 0 0 :::9066 :::* LISTEN 4673/java [root@db01 data]# free -h(运行java环境要有足够内存) total used free shared buff/cache available Mem: 3.0G 823M 2.1G 2.4M 90M 2.1G 连接mycat: mysql -uroot -p123456 -h 127.0.0.1 -P8066
配置文件介绍
logs目录: wrapper.log ---->mycat启动日志 mycat.log ---->mycat详细工作日志 conf目录: schema.xml 主配置文件(读写分离、高可用、分布式策略定制、节点控制) server.xml mycat软件本身相关的配置 rule.xml 分片规则配置文件,记录分片规则列表、使用方法等
测试数据库导入
db01: mysql -S /data/3307/mysql.sock source /root/world.sql mysql -S /data/3308/mysql.sock source /root/world.sql
配置文件处理
cd /data/mycat/conf mv schema.xml schema.xml.bak 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="dn1"> </schema> <dataNode name="dn1" dataHost="localhost1" database= "world" /> <dataHost name="localhost1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mys ql" dbDriver="native" switchType="1"> <heartbeat>select user()</heartbeat> <writeHost host="db1" url="10.0.0.200:3307" user="root" password="123"> <readHost host="db2" url="10.0.0.200:3309" user="root" password="123" /> </writeHost> </dataHost> </mycat:schema>