根据高亮显示的配置 --菜鸟牌子配置
mycat不支持 # 注释复制配置需要注意<!-- 注释格式 -->
mycat 端口
8066: 提供远程链接的虚拟mysqld 服务器,提供mysql的接口
9066: 提供管理mycat 服务器的即使状态检查和服务管理的接口 【该端口解释来自其他地址】
使用docker-compose 启动
version: '2'
services:
host1:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=123456
host2:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=123456
host3:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=123456
使用docker inspect 获取ip
host1: ip = 172.19.0.2
host2: ip = 172.19.0.3
host3: ip = 172.19.0.4
配置=================================
文件一: server.xml <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<user name="root" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">test</property> #指定与schema.xml 文件中配置的虚拟库schema绑定 高亮显示test
</user>
文件二: schema.xml <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="test" checkSQLschema="true" sqlMaxLimit="100000"> #name是虚拟库与server.xml中绑定 高亮显示test
<table name="test" dataNode="dn1,dn2,dn3" rule="rule19" /> #rule 引用当前目录下的rule.xml 文件中tableRule分片路由模式, dataNode绑定dataNode中的name实现虚拟库绑定分片 高亮显示rule19 高亮显示dn
</schema>
<dataNode name="dn1" dataHost="host1" database="dbs" /> #定义数据片由 table 引用 定义片存储的主机 dataHost指定绑定真是主机 database 指定真是主机的真实库并且映射到dn1中共table 使用,实现虚拟库绑定真是物理机器库 高亮显示dn 高亮显示 host
<dataNode name="dn2" dataHost="host2" database="dbs" /> #高亮显示dn 高亮显示 host
<dataNode name="dn3" dataHost="host3" database="dbs" /> #高亮显示dn 高亮显示 host
<!-- 主机1--> #定义真是主机 name字段绑定主机共分片dataNode条用
<dataHost name="host1" maxCon="10000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native" > #maxCon 最大链接maxmin 最小链接 balance指定读写分离的参数分片选着0即可
<heartbeat>select user()</heartbeat>
<writeHost host="hostM1" url="172.19.0.2:3306" user="root" #高亮显示 host
password="123456">
</writeHost>
</dataHost>
<!-- 主机2-->
<dataHost name="host2" maxCon="10000" minCon="10" balance="0" #高亮显示 host
writeType="0" dbType="mysql" dbDriver="native" >
<heartbeat>select user()</heartbeat>
<writeHost host="hostM2" url="172.19.0.3:3306" user="root"
password="123456">
</writeHost>
</dataHost>
<!-- 主机3 -->
<dataHost name="host3" maxCon="10000" minCon="10" balance="0" #高亮显示 host
writeType="0" dbType="mysql" dbDriver="native" >
<heartbeat>select user()</heartbeat>
<writeHost host="hostM3" url="172.19.0.4:3306" user="root"
password="123456">
</writeHost>
</dataHost>
</mycat:schema>
文件三: rule.xml <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
文件结构根据结构修改即可,两块配置是分离的 前面的调用后面定义的结构 使用<algorithm>去调用
<tableRule name="rule19"> #name定义与给schema.xml调用
<rule>
<columns>id</columns> #在数据库中的字段分片字段
<algorithm>murmur</algorithm> #指定函数调用function中的"murmur"
</rule>
</tableRule>
<function name="murmur">
定义分片规则
</function>
##########################################################################################
<?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="rule19"> #和schema.xml中的table 绑定 高亮显示rule19
<rule>
<columns>id</columns>
<algorithm>murmur</algorithm>
</rule>
</tableRule>
<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">3</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">
</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>