記錄一下mycat的幾個常用的配置文件

<?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分片

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章