MyCat配置运行
昨天把mycat的环境搭建差不多了,今天直接上配置文件:
主要需要修改三个配置文件:
rule.xml
schema.xml
server.xml
rule.xml配置如图:
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- - - Licensed under the Apache License, Version 2.0 (the "License");
- - you may not use this file except in compliance with the License. - You
- may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0
- - - Unless required by applicable law or agreed to in writing, software -
- distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the
- License for the specific language governing permissions and - limitations
- under the License. -->
- <!DOCTYPE mycat:rule SYSTEM "rule.dtd">
- <mycat:rule xmlns:mycat="http://io.mycat/">
- <tableRule name="rule1">
- <rule>
- <columns>id</columns>
- <algorithm>func1</algorithm>
- </rule>
- </tableRule>
- <tableRule name="rule2">
- <rule>
- <columns>user_id</columns>
- <algorithm>func1</algorithm>
- </rule>
- </tableRule>
- <tableRule name="sharding-by-intfile">
- <rule>
- <columns>sharding_id</columns>
- <algorithm>hash-int</algorithm>
- </rule>
- </tableRule>
- <tableRule name="auto-sharding-long">
- <rule>
- <columns>id</columns>
- <algorithm>rang-long</algorithm>
- </rule>
- </tableRule>
- <tableRule name="mod-long">
- <rule>
- <columns>id</columns>
- <algorithm>mod-long</algorithm>
- </rule>
- </tableRule>
- <tableRule name="sharding-by-murmur">
- <rule>
- <columns>id</columns>
- <algorithm>murmur</algorithm>
- </rule>
- </tableRule>
- <tableRule name="crc32slot">
- <rule>
- <columns>id</columns>
- <algorithm>crc32slot</algorithm>
- </rule>
- </tableRule>
- <tableRule name="sharding-by-month">
- <rule>
- <columns>create_time</columns>
- <algorithm>partbymonth</algorithm>
- </rule>
- </tableRule>
- <tableRule name="latest-month-calldate">
- <rule>
- <columns>calldate</columns>
- <algorithm>latestMonth</algorithm>
- </rule>
- </tableRule>
- <tableRule name="auto-sharding-rang-mod">
- <rule>
- <columns>id</columns>
- <algorithm>rang-mod</algorithm>
- </rule>
- </tableRule>
- <tableRule name="jch">
- <rule>
- <columns>id</columns>
- <algorithm>jump-consistent-hash</algorithm>
- </rule>
- </tableRule>
- <function name="murmur"
- class="io.mycat.route.function.PartitionByMurmurHash">
- <property name="seed">0</property><!-- 默认是0 -->
- <property name="count">2</property><!-- 要分片的数据库节点数量,必须指定,否则没法分片 -->
- <property name="virtualBucketTimes">160</property><!-- 一个实际的数据库节点被映射为这么多虚拟节点,默认是160倍,也就是虚拟节点数是物理节点数的160倍 -->
- <!-- <property name="weightMapFile">weightMapFile</property> 节点的权重,没有指定权重的节点默认是1。以properties文件的格式填写,以从0开始到count-1的整数值也就是节点索引为key,以节点权重值为值。所有权重值必须是正整数,否则以1代替 -->
- <!-- <property name="bucketMapPath">/etc/mycat/bucketMapPath</property>
- 用于测试时观察各物理节点与虚拟节点的分布情况,如果指定了这个属性,会把虚拟节点的murmur hash值与物理节点的映射按行输出到这个文件,没有默认值,如果不指定,就不会输出任何东西 -->
- </function>
- <function name="crc32slot"
- class="io.mycat.route.function.PartitionByCRC32PreSlot">
- <property name="count">2</property><!-- 要分片的数据库节点数量,必须指定,否则没法分片 -->
- </function>
- <function name="hash-int"
- class="io.mycat.route.function.PartitionByFileMap">
- <property name="mapFile">partition-hash-int.txt</property>
- </function>
- <function name="rang-long"
- class="io.mycat.route.function.AutoPartitionByLong">
- <property name="mapFile">autopartition-long.txt</property>
- </function>
- <function name="mod-long" class="io.mycat.route.function.PartitionByMod">
- <!-- how many data nodes -->
- <property name="count">3</property>
- </function>
- <function name="func1" class="io.mycat.route.function.PartitionByLong">
- <property name="partitionCount">8</property>
- <property name="partitionLength">128</property>
- </function>
- <function name="latestMonth"
- class="io.mycat.route.function.LatestMonthPartion">
- <property name="splitOneDay">24</property>
- </function>
- <function name="partbymonth"
- class="io.mycat.route.function.PartitionByMonth">
- <property name="dateFormat">yyyy-MM-dd</property>
- <property name="sBeginDate">2015-01-01</property>
- </function>
- <function name="rang-mod" class="io.mycat.route.function.PartitionByRangeMod">
- <property name="mapFile">partition-range-mod.txt</property>
- </function>
- <function name="jump-consistent-hash" class="io.mycat.route.function.PartitionByJumpConsistentHash">
- <property name="totalBuckets">3</property>
- </function>
- </mycat:rule>
其中最重要的两段:列举使用id分片,分多少片:


schema.xml:数据库关系配置,分库分表配置
- <?xml version="1.0"?>
- <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
- <mycat:schema xmlns:mycat="http://io.mycat/">
- <schema name="cuijiale" checkSQLschema="false" sqlMaxLimit="100">
- <!-- auto sharding by id (long) -->
- <table name="tb_user" dataNode="dn1,dn2" rule="sharding-by-murmur">
- </table>
- <!-- <table name="oc_call" primaryKey="ID" dataNode="dn1$0-743" rule="latest-month-calldate"
- /> -->
- </schema>
- <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743"
- /> -->
- <dataNode name="dn1" dataHost="192.168.30.134" database="cuijiale" />
- <dataNode name="dn2" dataHost="192.168.30.135" database="cuijiale" />
- <!-- <dataNode name="dn3" dataHost="localhost1" database="db3" /> -->
- <!--<dataNode name="dn4" dataHost="sequoiadb1" database="SAMPLE" />
- <dataNode name="jdbc_dn1" dataHost="jdbchost" database="db1" />
- <dataNode name="jdbc_dn2" dataHost="jdbchost" database="db2" />
- <dataNode name="jdbc_dn3" dataHost="jdbchost" database="db3" /> -->
- <dataHost name="192.168.30.134" maxCon="1000" minCon="10" balance="0"
- writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
- <heartbeat>select user()</heartbeat>
- <!-- can have multi write hosts -->
- <writeHost host="192.168.30.134" url="192.168.30.134:3306" user="cuijiale" password="2153577">
- </writeHost>
- <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
- </dataHost>
- <dataHost name="192.168.30.135" maxCon="1000" minCon="10" balance="0"
- writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
- <heartbeat>select user()</heartbeat>
- <!-- can have multi write hosts -->
- <writeHost host="192.168.30.135" url="192.168.30.135:3306" user="cuijiale" password="2153577">
- </writeHost>
- <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
- </dataHost>
- </mycat:schema>
我这里准备了两台写库虚拟机,只为验证分库分表是否成功与否;
server.xml:配置用户信息
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- - - Licensed under the Apache License, Version 2.0 (the "License");
- - you may not use this file except in compliance with the License. - You
- may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0
- - - Unless required by applicable law or agreed to in writing, software -
- distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT
- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the
- License for the specific language governing permissions and - limitations
- under the License. -->
- <!DOCTYPE mycat:server SYSTEM "server.dtd">
- <mycat:server xmlns:mycat="http://io.mycat/">
- <system>
- <property name="useSqlStat">0</property> <!-- 1为开启实时统计、0为关闭 -->
- <property name="useGlobleTableCheck">0</property> <!-- 1为开启全加班一致性检测、0为关闭 -->
- <property name="sequnceHandlerType">2</property>
- <!-- <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->
- <!-- <property name="fakeMySQLVersion">5.6.20</property>--> <!--设置模拟的MySQL版本号-->
- <!-- <property name="processorBufferChunk">40960</property> -->
- <!--
- <property name="processors">1</property>
- <property name="processorExecutor">32</property>
- -->
- <!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena-->
- <property name="processorBufferPoolType">0</property>
- <!--默认是65535 64K 用于sql解析时最大文本长度 -->
- <!--<property name="maxStringLiteralLength">65535</property>-->
- <!--<property name="sequnceHandlerType">0</property>-->
- <!--<property name="backSocketNoDelay">1</property>-->
- <!--<property name="frontSocketNoDelay">1</property>-->
- <!--<property name="processorExecutor">16</property>-->
- <!--
- <property name="serverPort">8066</property> <property name="managerPort">9066</property>
- <property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property>
- <property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> -->
- <!--分布式事务开关,0为不过滤分布式事务,1为过滤分布式事务(如果分布式事务内只涉及全局表,则不过滤),2为不过滤分布式事务,但是记录分布式事务日志-->
- <property name="handleDistributedTransactions">0</property>
- <!--
- off heap for merge/order/group/limit 1开启 0关闭
- -->
- <property name="useOffHeapForMerge">1</property>
- <!--
- 单位为m
- -->
- <property name="memoryPageSize">1m</property>
- <!--
- 单位为k
- -->
- <property name="spillsFileBufferSize">1k</property>
- <property name="useStreamOutput">0</property>
- <!--
- 单位为m
- -->
- <property name="systemReserveMemorySize">384m</property>
- <!--是否采用zookeeper协调切换 -->
- <property name="useZKSwitch">true</property>
- </system>
- <!-- 全局SQL防火墙设置 -->
- <!--
- <firewall>
- <whitehost>
- <host host="127.0.0.1" user="mycat"/>
- <host host="127.0.0.2" user="mycat"/>
- </whitehost>
- <blacklist check="false">
- </blacklist>
- </firewall>
- -->
- <user name="cuijiale">
- <property name="password">2153577</property>
- <property name="schemas">cuijiale</property>
- <!-- 表级 DML 权限设置 -->
- <!--
- <privileges check="false">
- <schema name="TESTDB" dml="0110" >
- <table name="tb01" dml="0000"></table>
- <table name="tb02" dml="1111"></table>
- </schema>
- </privileges>
- -->
- </user>
- <!-- <user name="user">
- <property name="password">user</property>
- <property name="schemas">TESTDB</property>
- <property name="readOnly">true</property>
- </user> -->
- </mycat:server>
替换mycat服务配置文件后,启动服务:
在mycat安装目录bin文件夹下输入如下命令:

有时linux虚拟机访问mysql会失败,一般情况会有防火墙,关掉防火墙在访问即可;
全部启动好后,两个库分别新建表tb_user:
CREATE TABLE `tb_user` ( `id` int(10) NOT NULL , `name` varchar(255) NULL , `sex` varchar(255) NULL , PRIMARY KEY (`id`) );
我是靠id分片的,这里要注意下:
全部搞定后,可以insert几条数据验证下:
MyCat配置运行的更多相关文章
- MyCat 入门:漫谈 MyCat 配置系统
文章首发于[博客园-陈树义],点击跳转到原文<MyCat 入门:漫谈 MyCat 配置系统> 上篇文章<MyCat 启蒙:分布式系统的数据库架构演变>中,我们通过一个项目从零到 ...
- MyCat配置详解
MyCAT 配置解析 server.xml Mycat的配置文件,设置账号.参数等schema.xml Mycat对应的物理数据库和数据库表的配置rule.xml Mycat分片(分库分表)规则 一 ...
- Mysql系列五:数据库分库分表中间件mycat的安装和mycat配置详解
一.mycat的安装 环境准备:准备一台虚拟机192.168.152.128 1. 下载mycat cd /softwarewget http:-linux.tar.gz 2. 解压mycat tar ...
- Mycat 配置及优化【转】
前言 Mycat 是一个数据库分库分表中间件 MyCAT 是作为通用代理设计的,后端是以 Mysql协议 和 JDBC 的方式连接数据库,可以支持 Oracle.DB2.SQL Server . mo ...
- 漫谈 MyCat 配置系统
上篇文章<MyCat 启蒙:分布式系统的数据库架构演变>中,我们通过一个项目从零到百万级访问的变化,展示了这个过程中的数据层架构变化.其中说到了数据层架构变化所带来的三个问题: 读写数据源 ...
- IntelliJ IDEA 配置运行程序
IntelliJ IDEA 对于Javaer开发来说还是很nice的,就是第一次用可能配置项有点生疏,这里就记录一下IntelliJ IDEA 配置运行程序. 1. 点击Edit Config... ...
- pycharm配置运行django项目步骤
1:在django项目的跟目录下执行:这是直接在Linux系统中直接运行 python manage.py runserver 0:8000 然后在浏览器中输入IP端口即可访问 pycharm配置运行 ...
- mycat配置实现mysql读写分离
需要先把mysql的主从复制配置好,然后才可以开始mycat的配置 m ysql主从复制配置:https://www.cnblogs.com/renjianjun/p/9093062.html myc ...
- 【Mac + Android】之Android Studio 环境搭建,AVD模拟器运行(包括:命令行运行AVD,并且Genymotion模拟器插件配置运行)
目录: 前提.Mac环境下手动配置Android SDK 一. Android Studio下载及配置 二.AVD模拟器配置运行 扩展:命令行运行AVD模拟器 三.在Android Studio 中配 ...
随机推荐
- C# WMI通过网络连接名称获取IP掩码网关
/// <summary> /// 读取IP,掩码,网关地址 /// </summary> /// <param name="netConnectorName& ...
- P2774 方格取数问题(网络流)
P2774 方格取数问题 emm........仔细一看,这不是最大权闭合子图的题吗! 取一个点$(x,y)$,限制条件是同时取$(x,y+1),(x,y-1),(x+1,y),(x-1,y)$,只不 ...
- JSP等模板引擎已死,大前端为趋势
我们先来看一下tomcat版本数据: 我们可以看到,从tomcat8之后JSP就再没有新的支持了,tomcat8大概是2013年发布的,也就是说,从2013年开始jsp技术已经实质上不被官方继续维护了 ...
- 【题解】Luogu P4198 楼房重建
原题传送门 根据斜率来建线段树,线段树维护区间最大斜率以及区间内能看见的楼房的数量(不考虑其他地方的原因,两个节点合并时再考虑) 细节见程序 #include <bits/stdc++.h> ...
- java截取2个指定字符之间的字符串
/** * 截取字符串str中指定字符 strStart.strEnd之间的字符串 * * @param string * @param str1 * @param str2 * @return */ ...
- Spring之bean的生命周期
这篇博文是spring生命周期的详解,目前限于作者自身的水平对于一些内容可能只知其然不知其所以然,所以博文中如果出现错误欢迎各位指出,同时我也会逐步提升自己的水平,争取能够多发布一些能让大家获益的博文 ...
- Redis 错误:Failed with result 'start-limit-hit'
Redis 错误:Failed with result 'start-limit-hit' 背景 Redis 版本为 5.0.4: 文件 /etc/systemd/system/redis.servi ...
- SpringMVC成员变量并发状态下使用测试
1.SpringMVC默认是单例的,使用成员变量在并发状态下该成员变量的值是被共享的 测试平台 我们目前正在开发的电商项目 (架构组成SpringCloud + SpringBoot + Sprin ...
- SAP FI中配置“特别总帐标志” SGL
SAP FI中配置“特别总帐标志” SGL 创建时间:2018年10月6日(星期六) 下午3:42 | 分类:未分类 | 字数:396 | SAP FI中配置“特别总帐标志” SGL 2013年 ...
- 找出 Xcode 编译C/C++过程文件及生成文件
在使用 Xcode 编写C/C++时,会发现在项目的目录位置是没有编译过程的那些 .o .exe 文件,只有一个 C/C++ 源代码 .c 文件.如下图(在Mac OS的finder中右键窗口标题名称 ...