1.下載mycat的tar包
wget http://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
2.解壓
mv Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz /usr/local/mycat.tar.gz
tar -zxvf mycat.tar.gz
3.進(jìn)入mycat/conf目錄
3.1修改邏輯庫的配置文schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
<table name="dm_order" dataNode="dn1,dn2,dn3" rule="auto-sharding-rang-mod-order" />
<table name="dm_order_link_user" dataNode="dn1,dn2,dn3" rule="auto-sharding-rang-mod-order-link" />
</schema>
<dataNode name="dn1" dataHost="host" database="dm_order1" />
<dataNode name="dn2" dataHost="host" database="dm_order2" />
<dataNode name="dn3" dataHost="host" database="dm_order3" />
<dataHost name="host" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select 1</heartbeat>
<writeHost host="hostM1" url="39.105.206.175:3306" user="root" password="root">
</writeHost>
</dataHost>
</mycat:schema>
3.2修改分表規(guī)則配置文件: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>
<tableRule name="auto-sharding-rang-mod-order">
<rule>
<columns>id</columns>
<algorithm>rang-mod-dm</algorithm>
</rule>
</tableRule>
<tableRule name="auto-sharding-rang-mod-order-link">
<rule>
<columns>orderId</columns>
<algorithm>rang-mod-dm</algorithm>
</rule>
</tableRule>
<function name="rang-mod-dm" class="io.mycat.route.function.PartitionByMod">
<!-- how many data nodes -->
<property name="count">3</property>
</function>
<function name="murmur"
class="io.mycat.route.function.PartitionByMurmurHash">
<property name="seed">0</property><!-- 默認(rèn)是0 -->
<property name="count">2</property><!-- 要分片的數(shù)據(jù)庫節(jié)點(diǎn)數(shù)量嚎研,必須指定功舀,否則沒法分片 -->
<property name="virtualBucketTimes">160</property><!-- 一個實(shí)際的數(shù)據(jù)庫節(jié)點(diǎn)被映射為這么多虛擬節(jié)點(diǎn),默認(rèn)是160倍,也就
是虛擬節(jié)點(diǎn)數(shù)是物理節(jié)點(diǎn)數(shù)的160倍 -->
<!-- <property name="weightMapFile">weightMapFile</property> 節(jié)點(diǎn)的權(quán)重闰靴,沒有指定權(quán)重的節(jié)點(diǎn)默認(rèn)是1。以properties文件
的格式填寫蚌本,以從0開始到count-1的整數(shù)值也就是節(jié)點(diǎn)索引為key加矛,以節(jié)點(diǎn)權(quán)重值為值。所有權(quán)重值必須是正整數(shù)儡羔,否則以1代替 -->
<!-- <property name="bucketMapPath">/etc/mycat/bucketMapPath</property>
用于測試時觀察各物理節(jié)點(diǎn)與虛擬節(jié)點(diǎn)的分布情況宣羊,如果指定了這個屬性,會把虛擬節(jié)點(diǎn)的murmur hash值與物理節(jié)點(diǎn)的映>射按行輸出到這個文件汰蜘,沒有默認(rèn)值仇冯,如果不指定,就不會輸出任何東西 -->
</function>
<function name="crc32slot"
class="io.mycat.route.function.PartitionByCRC32PreSlot">
<property name="count">2</property><!-- 要分片的數(shù)據(jù)庫節(jié)點(diǎn)數(shù)量族操,必須指定苛坚,否則沒法分片 -->
</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>
3.3 修改用戶的配置文件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為開啟實(shí)時統(tǒng)計、0為關(guān)閉 -->
<property name="useGlobleTableCheck">0</property> <!-- 1為開啟全加班一致性檢測色难、0為關(guān)閉 -->
<property name="sequnceHandlerType">2</property>
<!-- <property name="useCompression">1</property>--> <!--1為開啟mysql壓縮協(xié)議-->
<!-- <property name="fakeMySQLVersion">5.6.20</property>--> <!--設(shè)置模擬的MySQL版本號-->
<!-- <property name="processorBufferChunk">40960</property> -->
<!--
<property name="processors">1</property>
<property name="processorExecutor">32</property>
-->
<!--默認(rèn)為type 0: DirectByteBufferPool | type 1 ByteBufferArena-->
<property name="processorBufferPoolType">0</property>
<!--默認(rèn)是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> -->
<!--分布式事務(wù)開關(guān)泼舱,0為不過濾分布式事務(wù),1為過濾分布式事務(wù)(如果分布式事務(wù)內(nèi)只涉及全局表枷莉,則不過濾)娇昙,2為不過濾分布>式事務(wù),但是記錄分布式事務(wù)日志-->
<property name="handleDistributedTransactions">0</property>
<!--
off heap for merge/order/group/limit 1開啟 0關(guān)閉
-->
<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協(xié)調(diào)切換 -->
<property name="useZKSwitch">true</property>
</system>
<!-- 全局SQL防火墻設(shè)置 -->
<!--
<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="root">
<property name="password">123456</property>
<property name="schemas">TESTDB</property>
<!-- 表級 DML 權(quán)限設(shè)置 -->
<!--
<privileges check="false">
<schema name="TESTDB" dml="0110" >
<table name="tb01" dml="0000"></table>
<table name="tb02" dml="1111"></table>
</schema>
</privileges>
-->
</user>
</mycat:server
4.進(jìn)入mycat/bin目錄
啟動命令:./mycat start 或者 ./mycat console
停止命令:./mycat stop
重啟命令:./mycat restart
查看狀態(tài)命令:./mycat status
啟動mycat 如果報錯,輸出以下錯誤信息:
解決方法:找到.../mycat/conf/wrapper.conf,修改
wrapper.java.additional.10=-Xmx4G (大約在36行)
wrapper.java.additional.11=-Xms1G
改成:
wrapper.java.additional.10=-Xmx1G
wrapper.java.additional.11=-Xms256M
修改完成后蹲盘,重新執(zhí)行./mycat console