欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

记录一下mycat的几个常用的配置文件

程序员文章站 2024-02-21 17:21:58
...
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://org.opencloudb/">

<schema name="test" checkSQLschema="false" sqlMaxLimit="1000000">
<!--不需要分库,随便指定一个表放置即可-->
<table name="t_onlyone" primaryKey="id" type="global" dataNode="test-dn1" />
<!--需要分库分表,指定表名称-->
<table name="t_tables"  primaryKey="id"  dataNode="test-dn$1-100,test-dn$101-200" rule="test-id-rule"/>
</schema>
<!--分片,记录对应的数据库表名称   1-100为一个库    101-200为一个库-->
<dataNode name="test-dn$1-100" dataHost="test-host1" database="test_$1-100" />
<dataNode name="test-dn$101-200" dataHost="test-host2" database="test_$101-200" />

<!--路由规则-->
<dataHost name="test-host1" maxCon="5000" minCon="100" balance="2" writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="150">
<heartbeat>select 1</heartbeat>
<writeHost host="hostM1" url="127.0.0.1:3015" user="write_read" password="write123456">
<readHost host="hostS1" url="127.0.0.1:3016" user="read" password="read123456"/>
</writeHost>

<dataHost name="test-host2" maxCon="5000" minCon="100" balance="2" writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="150">
<heartbeat>select 1</heartbeat>
<writeHost host="hostM1" url="127.0.0.1:3015" user="write_read" password="write123456">
<readHost host="hostS1" url="127.0.0.1:3016" user="read" password="read123456"/>
</writeHost>

</dataHost>

schema.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://org.opencloudb/">
	<system>
		<property name="defaultSqlParser">druidparser</property>
	        <!--  <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->
   		<!-- <property name="processorBufferChunk">40960</property> -->
		<property name="processors">4</property> 
		<property name="processorExecutor">32</property> 
		<!--默认是65535 64K 用于sql解析时最大文本长度 -->
		<!--<property name="maxStringLiteralLength">65535</property>-->
		<property name="sequnceHandlerType">1</property>
		<!--<property name="backSocketNoDelay">1</property>-->
		<!--<property name="frontSocketNoDelay">1</property>-->
		<!--<property name="processorExecutor">16</property>-->
		<!-- 
			<property name="mutiNodeLimitType">1</property> 0:开启小数量级(默认) ;1:开启亿级数据排序
		    	<property name="mutiNodePatchSize">100</property> 亿级数量排序批量
			<property name="processors">32</property> <property name="processorExecutor">32</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> 
		-->
	</system>

<!--连接mycat的账号密码   跟连接mysql一样 -->
<user name="test_wr">
         <property name="password">123456</property>
         <property name="schemas">test</property>
</user>
<user name="test_r">
         <property name="password">123456</property>
         <property name="schemas">test</property>
</user>	
</mycat:server>

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:rule SYSTEM "rule.dtd">
<mycat:rule xmlns:mycat="http://org.opencloudb/">
<!--schema.xml内的规则映射名-->
<tableRule name="id-rule">
       <rule>
           <columns>id</columns>
           <algorithm>range-mod</algorithm>
       </rule>
</tableRule>
<tableRule name="date_time-rule_new">
       <rule>
           <columns>date</columns>
           <algorithm>partbymonth_new</algorithm>
       </rule>
</tableRule>

<!--id分配规则在partition-range-mod.txt-->
<function name="range-mod" class="org.opencloudb.route.function.AutoPartitionByLong">
       <property name="mapFile">partition-range-mod.txt</property>
</function>
<!--按日期分片的规则   配置规则的表的 dataNode 的分片,必须和分片规则数量一致,例如 2016-01 到 2031-08 ,每一个月一个分片,一共需要10个分片。   按天分 也是一样的需要加一行 <property name="sPartionDay">2</property> 表示几天为一个分片  -->
<function name="partbymonth_new" class="org.opencloudb.route.function.PartitionByMonth">
       <property name="dateFormat">yyyy-MM</property>
       <property name="sBeginDate">2020-01</property>
       <property name="sEndDate">2021-01</property>
</function>
</mycat:rule>

rule.xml

# range start-end ,data node group size
0-100k=0
100k-200k=100
200k-300k=1
300k-400k=101
400k-500k=2

partition-range-mod.txt    表数据为0-100k id分在0分片,100-200k在100分片 200-300k在1分片

相关标签: mycat