初期测试过程中,原本采用kingshard中作为中间件的项目,但在测试的过程中,发现了不支持不同分表的join,只能选择放弃,改成mycat做测试
下载地址为
[root@gzsd-ks01-101110214 download]# wget http://dl.mycat.io/1.6.5/Mycat-server-1.6.5-release-20171117203123-linux.tar.gz
[root@gzsd-ks01-101110214 download]# tar xvf Mycat-server-1.6.5-release-20171117203123-linux.tar.gz
- 需要有java的支持,这里直接使用yum进行安装
[root@gzsd-ks01-101110214 mycat]# yum -y install java
- 将解压的目录放到标准目录中
[root@gzsd-ks01-101110214 download]# mv mycat /usr/local/
- 查看对应的目录树
[root@gzsd-ks01-101110214 download]# tree /usr/local/mycat/
/usr/local/mycat/
├── bin
│ ├── dataMigrate.sh
│ ├── init_zk_data.sh
│ ├── mycat
│ ├── rehash.sh
│ ├── startup_nowrap.sh
│ ├── wrapper-linux-ppc-64
│ ├── wrapper-linux-x86-32
│ └── wrapper-linux-x86-64
├── catlet
├── conf
│ ├── autopartition-long.txt
│ ├── auto-sharding-long.txt
│ ├── auto-sharding-rang-mod.txt
│ ├── cacheservice.properties
│ ├── dbseq.sql
│ ├── ehcache.xml
│ ├── index_to_charset.properties
│ ├── log4j2.xml
│ ├── migrateTables.properties
│ ├── myid.properties
│ ├── partition-hash-int.txt
│ ├── partition-range-mod.txt
│ ├── rule.xml
│ ├── schema.xml
│ ├── sequence_conf.properties
│ ├── sequence_db_conf.properties
│ ├── sequence_distributed_conf.properties
│ ├── sequence_time_conf.properties
│ ├── server.xml
│ ├── sharding-by-enum.txt
│ ├── wrapper.conf
│ ├── zkconf
│ │ ├── autopartition-long.txt
│ │ ├── auto-sharding-long.txt
│ │ ├── auto-sharding-rang-mod.txt
│ │ ├── cacheservice.properties
│ │ ├── ehcache.xml
│ │ ├── index_to_charset.properties
│ │ ├── partition-hash-int.txt
│ │ ├── partition-range-mod.txt
│ │ ├── rule.xml
│ │ ├── schema.xml
│ │ ├── sequence_conf.properties
│ │ ├── sequence_db_conf.properties
│ │ ├── sequence_distributed_conf-mycat_fz_01.properties
│ │ ├── sequence_distributed_conf.properties
│ │ ├── sequence_time_conf-mycat_fz_01.properties
│ │ ├── sequence_time_conf.properties
│ │ ├── server-mycat_fz_01.xml
│ │ ├── server.xml
│ │ └── sharding-by-enum.txt
│ └── zkdownload
│ └── auto-sharding-long.txt
├── lib
│ ├── asm-4.0.jar
│ ├── commons-collections-3.2.1.jar
│ ├── commons-lang-2.6.jar
│ ├── curator-client-2.11.0.jar
│ ├── curator-framework-2.11.0.jar
│ ├── curator-recipes-2.11.0.jar
│ ├── disruptor-3.3.4.jar
│ ├── dom4j-1.6.1.jar
│ ├── druid-1.0.26.jar
│ ├── ehcache-core-2.6.11.jar
│ ├── fastjson-1.2.12.jar
│ ├── guava-19.0.jar
│ ├── hamcrest-core-1.3.jar
│ ├── hamcrest-library-1.3.jar
│ ├── jline-0.9.94.jar
│ ├── joda-time-2.9.3.jar
│ ├── jsr305-2.0.3.jar
│ ├── kryo-2.10.jar
│ ├── leveldb-0.7.jar
│ ├── leveldb-api-0.7.jar
│ ├── libwrapper-linux-ppc-64.so
│ ├── libwrapper-linux-x86-32.so
│ ├── libwrapper-linux-x86-64.so
│ ├── log4j-1.2.17.jar
│ ├── log4j-1.2-api-2.5.jar
│ ├── log4j-api-2.5.jar
│ ├── log4j-core-2.5.jar
│ ├── log4j-slf4j-impl-2.5.jar
│ ├── mapdb-1.0.7.jar
│ ├── minlog-1.2.jar
│ ├── mongo-java-driver-2.11.4.jar
│ ├── Mycat-server-1.6.5-release.jar
│ ├── mysql-binlog-connector-java-0.6.0.jar
│ ├── mysql-connector-java-5.1.35.jar
│ ├── netty-3.7.0.Final.jar
│ ├── netty-buffer-4.1.9.Final.jar
│ ├── netty-common-4.1.9.Final.jar
│ ├── objenesis-1.2.jar
│ ├── reflectasm-1.03.jar
│ ├── sequoiadb-driver-1.12.jar
│ ├── slf4j-api-1.6.1.jar
│ ├── univocity-parsers-2.2.1.jar
│ ├── velocity-1.7.jar
│ ├── wrapper.jar
│ └── zookeeper-3.4.6.jar
├── logs
│ └── wrapper.log
└── version.txt
7 directories, 96 files
- 设置环境变量
[root@gzsd-ks01-101110214 download]# vim /etc/profile
MYCAT_HOME=/usr/local/mycat
[root@gzsd-ks01-101110214 download]# source /etc/profile
- 修改server.xml文件
[root@gzsd-ks01-101110214 download]# vim $MYCAT_HOME/conf/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="nonePasswordLogin">0</property> <!-- 0为需要密码登陆、1为不需要密码登陆 ,默认为0,设置为1则需要指定默认账户-->
<property name="useHandshakeV10">1</property>
<property name="useSqlStat">1</property> <!-- 1为开启实时统计、0为关闭 -->
<property name="useGlobleTableCheck">0</property> <!-- 1为开启全加班一致性检测、0为关闭 -->
<property name="sequnceHandlerType">2</property>
<property name="subqueryRelationshipCheck">false</property> <!-- 子查询中存在关联查询的情况下,检查关联字段中是否有分片字段 .默认 false -->
<!-- <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->
<!-- <property name="fakeMySQLVersion">5.6.20</property>--> <!--设置模拟的MySQL版本号-->
<!-- <property name="processorBufferChunk">40960</property> -->
<!--
<property name="processors">1</property>
<property name="processorExecutor">32</property>
-->
<!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena | type 2 NettyBufferPool -->
<property name="processorBufferPoolType">0</property>
<!--默认是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> -->
<!--分布式事务开关,0为不过滤分布式事务,1为过滤分布式事务(如果分布式事务内只涉及全局表,则不过滤),2为不过滤分布式事务,但是记录分布式事务日志-->
<property name="handleDistributedTransactions">0</property>
<!--
off heap for merge/order/group/limit 1开启 0关闭
-->
<property name="useOffHeapForMerge">1</property>
<!--
单位为m
-->
<property name="memoryPageSize">64k</property>
<!--
单位为k
-->
<property name="spillsFileBufferSize">1k</property>
<property name="useStreamOutput">0</property>
<!--
单位为m
-->
<property name="systemReserveMemorySize">384m</property>
<!--是否采用zookeeper协调切换 -->
<property name="useZKSwitch">false</property>
<!-- XA Recovery Log日志路径 -->
<!--<property name="XARecoveryLogBaseDir">./</property>-->
<!-- XA Recovery Log日志名称 -->
<!--<property name="XARecoveryLogBaseName">tmlog</property>-->
</system>
<!-- 全局SQL防火墙设置 -->
<!--白名单可以使用通配符%或着*-->
<!--例如<host host="127.0.0.*" user="root"/>-->
<!--例如<host host="127.0.*" user="root"/>-->
<!--例如<host host="127.*" user="root"/>-->
<!--例如<host host="1*7.*" user="root"/>-->
<!--这些配置情况下对于127.0.0.1都能以root账户登录-->
<!--
<firewall>
<whitehost>
<host host="1*7.0.0.*" user="root"/>
</whitehost>
<blacklist check="false">
</blacklist>
</firewall>
-->
<user name="root" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">wms_output_0000</property>
<!-- 表级 DML 权限设置 -->
<!--
<privileges check="false">
<schema name="TESTDB" dml="0110" >
<table name="tb01" dml="0000"></table>
<table name="tb02" dml="1111"></table>
</schema>
</privileges>
-->
</user>
<user name="user">
<property name="password">user</property>
<property name="schemas">wms_output_0000</property>
<property name="readOnly">true</property>
</user>
</mycat:server>
- 修改schema.xml文件
[root@gzsd-ks01-101110214 download]# vim $MYCAT_HOME/conf/schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="wms_output_0000" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
<table name="wmp_so_package" primaryKey="id" autoIncrement="true" subTables="wmp_so_package$1-128" type="global" dataNode="dn1" rule="mod-long" />
<table name="wmp_sale_order" primaryKey="id" autoIncrement="true" subTables="wmp_sale_order$1-128" type="global" dataNode="dn1" rule="mod-long" />
</schema>
<dataNode name="dn1" dataHost="cluster1" database="wms_output_0000" />
<dataHost name="cluster1" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="hostM1" url="10.11.10.215:3306" user="gz_mycat_account" password="alo!7TTg@123">
<readHost host="hostS1" url="10.11.10.216:3306" user="gz_mycat_account" password="alo!7TTg@123" />
</writeHost>
</dataHost>
</mycat:schema>
- 修改rule.xml文件
[root@gzsd-ks01-101110214 download]# vim $MYCAT_HOME/conf/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="mod-long">
<rule>
<columns>id</columns>
<algorithm>mod-long</algorithm>
</rule>
</tableRule>
<function name="mod-long" class="io.mycat.route.function.PartitionByMod">
<!-- how many data nodes -->
<property name="count">128</property>
</function>
</mycat:rule>
- 启动
[root@gzsd-ks01-101110214 download]# cd $MYCAT_HOME
[root@gzsd-ks01-101110214 mycat]# ./bin/mycat start
Starting Mycat-server...
- 查看端口
[root@gzsd-ks01-101110214 mycat]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 878/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1349/master
tcp 0 0 127.0.0.1:32000 0.0.0.0:* LISTEN 12104/java
tcp6 0 0 :::9066 :::* LISTEN 12104/java
tcp6 0 0 :::16305 :::* LISTEN 12104/java
tcp6 0 0 :::22 :::* LISTEN 878/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1349/master
tcp6 0 0 :::42620 :::* LISTEN 12104/java
tcp6 0 0 :::1984 :::* LISTEN 12104/java
tcp6 0 0 :::8066 :::* LISTEN 12104/java
配置完成后,即可使用客户端工具连接进行操作。
启动之前,需要明确的一个点就是,指定的库和指定的分表个数,一定要先在DB上创建了先。schema.xml和rule分别对应,在这里,有两个分表,分表均为128张表,即
分表 | 库 | 数目 | 说明 |
---|---|---|---|
wmp_so_package | wms_output_0000 | 128 | schema.xml配置 |
wmp_sale_order | wms_output_0000 | 128 | schema.xml配置 |
启动的时候,可能会碰到如下问题
FATAL | wrapper | 2017/12/05 17:21:16 | There were 5 failed launches in a row, each lasting less than 300 seconds. Giving up.
FATAL | wrapper | 2017/12/05 17:21:16 | There may be a configuration problem: please check the logs.
STATUS | wrapper | 2017/12/05 17:21:16 | <-- Wrapper Stopped
出现这种问题的解决办法是在hosts中加入对应的信息
如果还有其他问题,则可以打开debug进行查证