Mycat实现分库分表(一)

翻了翻自己之前WorkShop的产物,发现还有一个MyCat实现分库分表的东西可以分享一下,就拿出来写一下,还是老规矩,欢迎一起讨论,不喜勿喷...........................

第一部分:

目录

1.mycat原理

2.分片介绍

  2.1垂直切片

  2.2水平切片

3.配置文件

3.1 rule.xml

3.1.1 tableRule标签

3.2 schema.xml(sigimer)

3.2.1配置文件介绍

3.2.2 标签介绍

3.3 server.xml

3.3.1配置文件介绍

3.3.2标签介绍

4.启动及测试

4.1使用dos启动方法

4.2 测试


 

1.mycat原理

可以用拦截形容,它拦截了用户发送过来的SQL语句,首先对sql语句做了一些特定的分析,如分片分析,路由分析,读写分析,读写分离分析,缓存分析等,然后将此sql发送后端的真是数据库,并将反悔的结果做适当的处理,最终返回给用户

2.分片介绍

  2.1垂直切片

    将不同的表切分到不同的数据库中

  2.2水平切片

    将统一种表按照园中条件切分到不同的数据库中(常用)

3.配置文件

mycat主要有3个配置文件,rule.xml,schema.xml和server.xml,这主要对这3个文件作讲解

3.1 rule.xml

rule.xml 里面就定义了我们对表进行拆分所涉及到的规则定义。我们可以灵活的对表使用不同的分片算法,或者对表使用相同的算法但具体的参数不同。 
包含的标签 tableRule 和 function。

3.1.1 tableRule标签

   该文件主要定义了分片的规则,这个文件里面主要有tableRule 和 function 这两个标签。在具体的使用过程中可以按照需要添加tableRule和function

tableRule标签

<tableRule name="auto-sharding-long">

    <rule>

        <columns>id</columns>

        <algorithm>rang-long</algorithm>

    </rule>

</tableRule>

其中:name:用户表示不同的分表规则

     Columns:指定按哪一列进行拆分

     algorithm:改属性值为下面function标签中name的属性值,定义了链接表规则的具体具体路由算法,多个表规则可以连接到同一个路由算法上

function 标签

<function name="rang-long"

    class="org.opencloudb.route.function.AutoPartitionByLong">

    <property name="mapFile">autopartition-long.txt</property>

</function>

其中:name:标识算法的名字

      class:指定路由算法具体的类名字

      property:具体算法用到的一些属性

备注

1.Schema.xml

<schema name="testLiuHao" checkSQLschema="false" sqlMaxLimit="100">

        <table name="a_area_sum" dataNode="dn1,dn2" rule="auto-sharding-long" />

        <table name="s_code" primaryKey="ID" type="global" dataNode="dn1,dn2" />

</schema>

代码中rule的规则就是应引用rule.xml中

<tableRule name="auto-sharding-long">

        <rule>

            <columns>id</columns>

            <algorithm>rang-long</algorithm>

        </rule>

</tableRule>

<tableRule>标签中的名字。<tableRule>连接表规则和具体路由算法<algorithm>标签是下面function标签的名字

<function name="rang-long"

        class="io.mycat.route.function.AutoPartitionByLong">

        <property name="mapFile">autopartition-long.txt</property>

</function>

2.在rule.xml 中

<function name="rang-long"

        class="io.mycat.route.function.AutoPartitionByLong">

        <property name="mapFile">autopartition-long.txt</property>

</function>

其中autopartition-long.txt代表链接表的规则,其中文档中切分规则的个数一定要和自己schema.xml中(引用rule.xml中规则)的dataNode个数相同

3.2 schema.xml(sigimer)

3.2.1配置文件介绍

该文件是MyCat中重要的配置文件之一,管理者MyCat的逻辑库、表、分片规则、DataNode以及DataSource

<?xml version="1.0"?>

<!DOCTYPE mycat:schema SYSTEM "schema.dtd">

<mycat:schema xmlns:mycat="http://org.opencloudb/">

    <schema name="e3mall" checkSQLschema="false" sqlMaxLimit="100">

        <table name="tb_item" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" />

    </schema>

    <dataNode name="dn1" dataHost="localhost1" database="db1" />

    <dataNode name="dn2" dataHost="localhost1" database="db2" />

    <dataNode name="dn3" dataHost="localhost1" database="db3" />

    <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"

        writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">

        <heartbeat>select user()</heartbeat>

        <writeHost host="hostM1" url="192.168.20.216:3306" user="root"

            password="root">

        </writeHost>

    </dataHost>

</mycat:schema>

3.2.2 标签介绍

3.2.2.1 Schema标签

Schema标签:定义mycat实例中的逻辑库,MyCat可以有多个逻辑库,每个逻辑库都有自己的相关配置。可以使用schema标签来划分这些不同的逻辑库

<schema name="TESTDB"  checkSQLschema="false"  sqlMaxLimit="100"></schema>

<schema name="USERDB"  checkSQLschema="false"  sqlMaxLimit="100"></schema>

逻辑库的概念和 MYSQL 数据库中 Database 的概念相同,我们在查询这两个不同的额逻辑库中标的时候需要奇幻到该逻辑库下才可以查到所需要的表。

checkSQLschema标签:这个属性默认就是false,官方文档的意思就是是否去掉表前面的数据库的名称,”select * from db1.testtable” ,设置为true就会去掉db1。但是如果db1的名称不是schema的名称,那么也不会被去掉,因此官方建议不要使用这种语法。同时默认设置为false。

sqlMaxLimit标签:当该值设置为某个数值时。每条执行的 SQL 语句,如果没有加上 limit 语句,MyCat 也会自动的加上所对应的值。例如设置值为 100,执行”select * from test_table”,则效果为“selelct * from test_table limit 100”.

3.2.2.1.1 table标签

定义mycat实例中的逻辑表

<table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" ></table>

3.2.2.1.2 childTable标

<table name="customer" primaryKey="ID" dataNode="dn1,dn2" rule="sharding-by-intfile">   <childTable name="c_a" primaryKey="ID" joinKey="customer_id" parentKey="id" />

</table>

childTable 标签用于定义 E-R 分片的子表。通过标签上的属性与父表进行关联。

3.2.2.2 dataNode(分片节点)标签

dataNode 标签定义了 MyCat 中的数据节点,也就是我们通常说所的数据分片。一个 dataNode 标签就是一个独立的数据分片

<dataNode name="dn2" dataHost="localhost2" database="db2" />

上面的意思是:我们使用名字为localhsot2数据库实例上的db2物理数据库,这就组成一个数据分片,命名为dn2

3.2.2.3 dataHost(节点主机)标签

该标签定义了具体的数据库实例、读写分离配置和心跳语句。

<dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"  writeType="0" dbType="mysql" dbDriver="native">

<heartbeat>select user()</heartbeat>

<writeHost  host="hostM1"  url="localhost:3306"  user="root" password="123456">

</writeHost>

</dataHost>

3.2.2.3.1 heartbeat标签

这个标签内指明用于和后端数据库进行心跳检查的语句。 
例如:MYSQL 可以使用 select user(),Oracle 可以使用 select 1 from dual 等。

3.2.2.2.2 writeHost/readHost标签

这两个标签都指定后端数据库的相关配置,用于实例化后端连接池。唯一不同的是,writeHost 指定写实例、readHost 指定读实例。

在一个 dataHost 内可以定义多个 writeHost 和 readHost。但是,如果 writeHost 指定的后端数据库宕机,那么这个 writeHost 绑定的所有 readHost 都将不可用。另一方面,由于这个 writeHost 宕机,系统会自动的检测到,并切换到备用的 writeHost 上去。这两个标签的属性相同,这里就一起介绍。

全局配置及含义截图介绍

3.3 server.xml

3.3.1配置文件介绍

Server.xml保存了mycat需要的所有的系统配置信息,代码映射为SystemConfig类。

主要的标签有4个:system,user,firewarll,cluster.

<!DOCTYPE mycat:server SYSTEM "server.dtd">

<mycat:server xmlns:mycat="http://org.opencloudb/">

    <system>

    <property name="defaultSqlParser">druidparser</property>

    </system>

    <user name="user">

        <property name="password">user</property>

        <property name="schemas">e3mall</property>

        <property name="readOnly">false</property>

    </user>

</mycat:server>

 

3.3.2标签介绍

3.3.2.1 user标签

内容: <user name="test"> 说明用户名是test。

子标签: property,privileges.

3.3.2.1.1 property标签

3.3.2.1.1 privileges标签

对用户的 schema以及表进行精细化的DML权限控制

<privileges  check="false">

check表示是否开启DML权限检查。默认是关闭。 
server.dtd文件中 <!ELEMENT privileges (schema)*> 说明可以有多个schema的配置。

dml顺序说明:

    insert,update,select,delete

<schema name="db1" dml="0110" >

        <table name="tb01" dml="0000"></table>

        <table name="tb02" dml="1111"></table>

</schema>

3.3.2.1 system标签

这个标签内嵌套的所有 property 标签都与系统配置有关

 

<property name="charset">utf8</property>

字符集

<property name="processors">1</property>

处理线程数量,默认是cpu数量。

 

<property name="processorBufferChunk">4096</property>

每次读取留的数量,默认4096。

 

<property name="processorBufferPool">409600</property>

创建共享buffer需要占用的总空间大小。processorBufferChunk*processors*100。

 

<property name="processorBufferPoolType">0</property>

默认为0。0表示DirectByteBufferPool,1表示ByteBufferArena。

 

<property name="processorBufferLocalPercent">100</property>

二级共享buffer是processorBufferPool的百分比,这里设置的是百分比。

 

<property name="sequnceHandlerType">100</property>

全局ID生成方式。(0:为本地文件方式,1:为数据库方式;2:为时间戳序列方式;3:为ZK生成ID;4:为ZK递增ID生成。

 

<property name="useCompression">1</property>

是否开启mysql压缩协议。1为开启,0为关闭,默认关闭。

 

<property name="packetHeaderSize">4</property>

指定 Mysql 协议中的报文头长度。默认 4。

 

<property name="maxPacketSize">16M</property>

指定 Mysql 协议可以携带的数据最大长度。默认 16M。

 

<property name="idleTimeout">1800000</property>

指定连接的空闲超时时间。某连接在发起空闲检查下,发现距离上次使用超过了空闲时间,那么这个连接会被回收,就是被直接的关闭掉。默认 30 分钟,单位毫秒。

前端连接的初始化事务隔离级别,只在初始化的时候使用,后续会根据客户端传递过来的属性对后端数据库连接进行同步。默认为 REPEATED_READ,设置值为数字默认 3。

READ_UNCOMMITTED = 1;

READ_COMMITTED = 2;

REPEATED_READ = 3;

SERIALIZABLE = 4;

 

<property name="sqlExecuteTimeout">300</property>

1

SQL 执行超时的时间,Mycat 会检查连接上最后一次执行 SQL 的时间,若超过这个时间则会直接关闭这连接。默认时间为 300 秒,单位秒。

 

<property name="processorCheckPeriod">1000</property>

1

清理 NIOProcessor 上前后端空闲、超时和关闭连接的间隔时间。默认是 1 秒,单

位毫秒。

 

<property name="dataNodeIdleCheckPeriod">300000</property>

1

对后端连接进行空闲、超时检查的时间间隔,默认是 300 秒,单位毫秒。

 

<property name="dataNodeHeartbeatPeriod">10000</property>

1

对后端所有读、写库发起心跳的间隔时间,默认是 10 秒,单位毫秒。

 

<property name="bindIp">0.0.0.0</property>

1

mycat 服务监听的 IP 地址,默认值为 0.0.0.0。

 

<property name="serverPort">8066</property>

1

定义 mycat 的使用端口,默认值为 8066。

 

<property name="managerPort">9066</property>

1

定义 mycat 的管理端口,默认值为 9066。

 

<property name="fakeMySQLVersion">5.6</property>

1

mycat 模拟的 mysql 版本号,默认值为 5.6 版本,如非特需,不要修改这个值,目前支持设置 5.5,5.6,5.7 版本,其他版本可能会有问题。

 

<property name="useSqlStat">0</property> 

1

是否开启实时统计。1为开启;0为关闭 。

 

<property name="useGlobleTableCheck">0</property>  

1

是否开启全局表一致性检测。1为开启;0为关闭 。

 

<property name="handleDistributedTransactions">0</property>

1

分布式事务开关。0为不过滤分布式事务;1为过滤分布式事务;2 为不过滤分布式事务,但是记录分布式事务日志。

 

<property name="maxStringLiteralLength">65535</property>

1

默认是65535。 64K 用于sql解析时最大文本长度

以上举例的属性仅仅是一部分,可以配置的变量很多,具体可以查看SystemConfig这个类的属性内容。

System标签下的属性,一般是上线后,需要根据实际运行的情况,分析后调优的时候进行。

3.3.2.2 FireWall标签

顾名思义,这个就是关于防火墙的设置,也就是在网络层对请求的地址进行限制,主要是从安全角度来保证Mycat不被匿名IP进行访问

 

<firewall>

       <whitehost>

          <host host="127.0.0.1" user="mycat"/>

          <host host="127.0.0.2" user="mycat"/>

       </whitehost>

       <blacklist check="false">

       </blacklist>

</firewall>

设置很简单,很容易理解,只要设置了白名单,表示开启了防火墙,只有白名单的连接才可以进行连接。

 

3.3 wrapper.conf

还要修改wrapper.conf 中 指向jdk路径

wrapper.java.command=F:\Program Files (x86)\jdk1.8.0_131\bin\java.exe

4.启动及测试

4.1使用dos启动方法

管理员身份打开窗口

4.2 测试

使用可视化工具navicat进行链接mycat(链接的是mycat的逻辑库)。

端口号:8066

用户名、密码是在schema.xml中、rule.xml中配置的

链接成功之后:

a_area_sum 和 s_code作为新库中的表建立。并且与配置文件中一样。

参考文档

https://blog.csdn.net/tornadojava/article/details/54948662

https://www.cnblogs.com/llhhll/p/9261248.html

https://www.cnblogs.com/fxwl/p/7990906.html

https://blog.csdn.net/zzy_ayuan/article/details/78766329

rule.xml文件配置

https://blog.csdn.net/anzhen0429/article/details/77801498?utm_source=blogxgwz0

-----------------------------华丽的分割线-----------------------start----------------------------------------------------------

上面涉及到的两个表a_area_sum 和 s_code都是当时对应的一个数据量庞大的表,一个码表不用特殊理会

-----------------------------华丽的分割线-----------------------end---------------------------------------------------------

 

第二部分:

直接贴我自己的配置文件了,都是自己按照官网demo配置的,已经成功跑通。

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">auto-sharding-long.txt</property>
	</function>
	<function name="mod-long" class="io.mycat.route.function.PartitionByMod">
		<!-- how many data nodes -->
		<property name="count">2</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">2</property>
	</function>
</mycat:rule>

schema.xml

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
	<schema name="testLiuHao" checkSQLschema="false" sqlMaxLimit="100">
		<table name="a_area_sum" dataNode="dn1,dn2" rule="auto-sharding-long" />
		<table name="s_code" primaryKey="ID" type="global" dataNode="dn1,dn2" />
	</schema>
	
	<dataNode name="dn1" dataHost="localhost1" database="db1" />
	<dataNode name="dn2" dataHost="localhost2" database="db2" />
	
	<dataHost name="localhost1" 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="hostM1" url="localhost:3306" user="root"
				   password="root">
			<!-- can have multi read hosts -->
		<readHost host="hostS2" url="localhost:3306" user="root" password="root" />
		</writeHost>
	</dataHost>

	<dataHost name="localhost2" 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 -->
		<!-- /10/ -->
		<writeHost host="hostM1" url="localhost:3306" user="root"
				   password="root">
			<!-- can have multi read hosts -->
		<readHost host="hostS2" url="localhost:3306" user="root" password="root" />
		</writeHost>
	</dataHost>
	
</mycat:schema>

schema中文介绍.xml

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
	<!-- 逻辑库 -->
	<schema name="testLiuHao" checkSQLschema="false" sqlMaxLimit="100">
	name:逻辑数据库名字也就是在mycat中的名字;
	checkSQLschema:是否检查sql,用于拦截sql
	;sqlMaxLimit:sql查询返回条数
		<!-- 下面的这个rule在rule.xml文件中 -->
		<table name="a_area_sum" dataNode="dn1,dn2" rule="auto-sharding-long" />
		table中的 name:物理数据库表名字;dataNode:表存储那些节点,将a_area_sum表 按照分片规则
		分片存储,三个节点综合起来组成完整的a_area_sum表
		
		全局设定1
		<table name="s_code" primaryKey="ID" type="global" dataNode="dn1,dn2" />
		
	
		全局设定2
		<table name="customer" primaryKey="ID" dataNode="dn1,dn2"
			   rule="sharding-by-intfile">
			<childTable name="orders" primaryKey="ID" joinKey="customer_id"
						parentKey="id">
				<childTable name="order_items" joinKey="order_id"
							parentKey="id" />
			</childTable>
			<childTable name="customer_addr" primaryKey="ID" joinKey="customer_id"
						parentKey="id" />
		</table>
	
	</schema>
	<!--分片节点配置	name:数据节点名称,上面配置的相对应
					dataHost:物理数据库名,与datahost中name对应
					database:用于定义该分片属于数据库实例上 的具体库 -->
	<!-- 同一机器上面可以有多个分片数据库 -->
	<!-- 例子中的表述的意思为,使用名字为localhost1数据库实例上的db1物理数据库,这就组成一个数据分片,最后我们用dn1来标示这个分片 -->
	<dataNode name="dn1" dataHost="localhost1" database="db1" />
	<dataNode name="dn2" dataHost="localhost2" database="db2" />
	
	<!-- 节点主机配置 。多个分开配置就行,这里做demo我们选择在同一机器上建立两个库-->
	<!-- 节点主机(dataHost)配置 name:与dataNode(分片节点)中的dataHost一样
								blance:均衡负载的方式(为1,表示读写分离
								writeType:写入方式)-->
	<dataHost name="localhost1" 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 -->
		<!-- host标签:用于标识不同实例 -->
		<writeHost host="hostM1" url="localhost:3306" user="root"
				   password="root">
			<!-- can have multi read hosts -->
		<readHost host="hostS2" url="localhost:3306" user="root" password="root" />
		</writeHost>
	</dataHost>

	<dataHost name="localhost2" 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 -->
		<!-- host标签:用于标识不同实例 -->
		<writeHost host="hostM1" url="localhost:3306" user="root"
				   password="root">
			<!-- can have multi read hosts -->
		<readHost host="hostS2" url="localhost:3306" user="root" password="root" />
		</writeHost>
	</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>  


	<property name="useGlobleTableCheck">0</property>  


	<property name="sequnceHandlerType">2</property>

	<!--  <property name="useCompression">1</property>-->


	<!--  <property name="fakeMySQLVersion">5.6.20</property>-->


	<!-- <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>

	<property name="handleDistributedTransactions">0</property>

		<property name="useOffHeapForMerge">1</property>

	
		<property name="memoryPageSize">1m</property>


		<property name="spillsFileBufferSize">1k</property>

		<property name="useStreamOutput">0</property>


		<property name="systemReserveMemorySize">384m</property>


		<property name="useZKSwitch">true</property>


	</system>
	


	<user name="root">
		<property name="password">root</property>

		<property name="schemas">testLiuHao</property>
		<property name="readOnly">false</property>
		

	</user>
</mycat:server>

wrapper.conf(这个文件,我记得只需要配置他的jdk地址就行,不是主要的三大文件)

#********************************************************************
# Wrapper Properties
#********************************************************************
# Java Application
wrapper.java.command=C:\Program Files\Java\jdk1.7.0_51\bin\java.exe
wrapper.working.dir=..

# Java Main class.  This class must implement the WrapperListener interface
#  or guarantee that the WrapperManager class is initialized.  Helper
#  classes are provided to do this for you.  See the Integration section
#  of the documentation for details.
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
set.default.REPO_DIR=lib
set.APP_BASE=.

# Java Classpath (include wrapper.jar)  Add class path elements as
#  needed starting from 1
wrapper.java.classpath.1=lib/wrapper.jar
wrapper.java.classpath.2=conf
wrapper.java.classpath.3=%REPO_DIR%/*

# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=lib

# Java Additional Parameters
#wrapper.java.additional.1=
wrapper.java.additional.1=-DMYCAT_HOME=.
wrapper.java.additional.2=-server
wrapper.java.additional.3=-XX:MaxPermSize=64M
wrapper.java.additional.4=-XX:+AggressiveOpts
wrapper.java.additional.5=-XX:MaxDirectMemorySize=2G
wrapper.java.additional.6=-Dcom.sun.management.jmxremote
wrapper.java.additional.7=-Dcom.sun.management.jmxremote.port=1984
wrapper.java.additional.8=-Dcom.sun.management.jmxremote.authenticate=false
wrapper.java.additional.9=-Dcom.sun.management.jmxremote.ssl=false
wrapper.java.additional.10=-Xmx4G
wrapper.java.additional.11=-Xms1G

# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3

# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64

# Application parameters.  Add parameters as needed starting from 1
wrapper.app.parameter.1=io.mycat.MycatStartup
wrapper.app.parameter.2=start

#********************************************************************
# Wrapper Logging Properties
#********************************************************************
# Format of output for the console.  (See docs for formats)
wrapper.console.format=PM

# Log Level for console output.  (See docs for log levels)
wrapper.console.loglevel=INFO

# Log file to use for wrapper output logging.
wrapper.logfile=logs/wrapper.log

# Format of output for the log file.  (See docs for formats)
wrapper.logfile.format=LPTM

# Log Level for log file output.  (See docs for log levels)
wrapper.logfile.loglevel=INFO

# Maximum size that the log file will be allowed to grow to before
#  the log is rolled. Size is specified in bytes.  The default value
#  of 0, disables log rolling.  May abbreviate with the 'k' (kb) or
#  'm' (mb) suffix.  For example: 10m = 10 megabytes.
wrapper.logfile.maxsize=0

# Maximum number of rolled log files which will be allowed before old
#  files are deleted.  The default value of 0 implies no limit.
wrapper.logfile.maxfiles=0

# Log Level for sys/event log output.  (See docs for log levels)
wrapper.syslog.loglevel=NONE

#********************************************************************
# Wrapper Windows Properties
#********************************************************************
# Title to use when running as a console
wrapper.console.title=Mycat-server

#********************************************************************
# Wrapper Windows NT/2000/XP Service Properties
#********************************************************************
# WARNING - Do not modify any of these properties when an application
#  using this configuration file has been installed as a service.
#  Please uninstall the service before modifying this section.  The
#  service can then be reinstalled.

# Name of the service
wrapper.ntservice.name=mycat

# Display name of the service
wrapper.ntservice.displayname=Mycat-server

# Description of the service
wrapper.ntservice.description=The project of Mycat-server

# Service dependencies.  Add dependencies as needed starting from 1
wrapper.ntservice.dependency.1=

# Mode in which the service is installed.  AUTO_START or DEMAND_START
wrapper.ntservice.starttype=AUTO_START

# Allow the service to interact with the desktop.
wrapper.ntservice.interactive=false

wrapper.ping.timeout=120
configuration.directory.in.classpath.first=conf

也就是这里

备注:

还有个当时总结的文档,很多部分都是东拼西凑总结的。。。仅供参考 Mycat实现分库分表(二)

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值