mycat集群部署文档
jdk安装
1、下载jdk并解压(下载略)

2、添加java环境变量(需root账号)

3、验证java是否安装成功

配置hosts vim /etc/hosts ###集群的主机都需配置

Mysql及zookeeper安装(略)
Mycat安装
1、下载并解压mycat

2、配置schema.xml文件

3、配置server.xml文件

4、配置myid.properties文件

5.配置rule.xml(略)
6、初始化zk配置
conf]# ../bin/init_zk_data.sh
7、启动mycat服务
conf]# ../bin/mycat/mycat start
MyCAT说明
wget http://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
vim schema.xml
<?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <!-- 定义一个MyCat的模式,逻辑数据库名称TestDB --> <!-- “checkSQLschema”:描述的是当前的连接是否需要检测数据库的模式 --> <!-- “sqlMaxLimit”:表示返回的最大的数据量的行数 --> <!-- “dataNode="dn1"”:该操作使用的数据节点是dn1的逻辑名称 --> <schema name="zhime-theme" checkSQLschema="true" sqlMaxLimit="100" dataNode="zhime-theme"/> <!-- 定义数据的操作节点 --> <!-- “dataHost="localhost1"”:定义数据节点的逻辑名称 --> <!-- “database="mldn"”:定义数据节点要使用的数据库名称 --> <dataNode name="zhime-theme" dataHost="zhime-theme" database="zhime-theme" /> <!-- 定义数据节点,包括了各种逻辑项的配置 --> <dataHost name="zhime-theme" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <!-- 配置真实MySQL与MyCat的心跳 --> <heartbeat>select user()</heartbeat> <!-- 配置真实的MySQL的连接路径 --> <writeHost host="zhime-theme" url="10.10.111.2:3306" user="root" password="bnh1923"></writeHost> </dataHost> </mycat:schema>
vim server.xml
<user name="root"> <property name="password">bnh1923</property> <property name="schemas">zhime-theme</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="zhime-theme"> <property name="password">bnh1923</property> <property name="schemas">zhime-theme</property> <property name="readOnly">false</property> </user>
wget http://nexus.mycat.io/content/groups/public/io/mycat/mycat/Mycat-web/1.0-SNAPSHOT/Mycat-web-1.0-20160617.083134-5-20160617163048-linux.tar.gz
vim mycat-web/WEB-INF/classes/mycat.properties
zookeeper=10.10.111.80:2181 sqlonline.server=10.10.111.2 sqlonline.user=root sqlonline.passwd=123456
web访问:http://localhost:8082/mycat
-----------------------------------------------------------------------------------------------------------
###多实例配置
vim schema.xml
<?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema> <schema name="aone" checkSQLschema="false" sqlMaxLimit="100" dataNode="aone"/> <schema name="mtop" checkSQLschema="false" sqlMaxLimit="100" dataNode="mtop"/> <dataNode name="aone" dataHost="aone" database="aone"/> <dataNode name="mtop" dataHost="mtop" database="mtop"/> <dataHost name="aone" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="aone" url="192.168.1.220:3301" user="root" password="bnh1923"/> </dataHost> <dataHost name="mtop" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="mtop" url="192.168.1.220:3302" user="root" password="bnh1923"/> </dataHost> </mycat:schema>
vim server.xml
<user name="aone"> <property name="password">bnh1923</property> <property name="schemas">aone</property> </user> <user name="mtop"> <property name="password">bnh1923</property> <property name="schemas">mtop</property> </user>
案例: schema.xml
<?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema> <schema name="zhime-api" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-api"/> <schema name="zhime-company" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-company"/> <schema name="zhime-newpoint" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-newpoint"/> <schema name="zhime-rating" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-rating"/> <schema name="zhime-circle" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-circle"/> <schema name="zhime-treaty" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-treaty"/> <schema name="zhime-score" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-score"/> <schema name="zhime-message" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-message"/> <schema name="zhime-addressbook" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-addressbook"/> <schema name="zhime-resume" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-resume"/> <schema name="zhime-operation" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-operation"/> <schema name="zhime-uc-center" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-uc-center"/> <schema name="dubboconfig" checkSQLschema="false" sqlMaxLimit="100" dataNode="dubboconfig"/> <schema name="activiti6" checkSQLschema="false" sqlMaxLimit="100" dataNode="activiti6"/> <schema name="db_huhahome_crm" checkSQLschema="false" sqlMaxLimit="100" dataNode="db_huhahome_crm"/> <schema name="zhime-email" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-email"/> <schema name="zhime-theme" checkSQLschema="false" sqlMaxLimit="100" dataNode="zhime-theme"/> <schema name="huhacitytttc" checkSQLschema="false" sqlMaxLimit="100" dataNode="huhacitytttc"/> <schema name="xmpp" checkSQLschema="false" sqlMaxLimit="100" dataNode="xmpp"/> <schema name="dianping" checkSQLschema="false" sqlMaxLimit="100" dataNode="dianping"/> <dataNode name="zhime-api" dataHost="zhime-api" database="zhime-api"/> <dataNode name="zhime-company" dataHost="zhime-company" database="zhime-company"/> <dataNode name="zhime-newpoint" dataHost="zhime-newpoint" database="zhime-newpoint"/> <dataNode name="zhime-rating" dataHost="zhime-rating" database="zhime-rating"/> <dataNode name="zhime-circle" dataHost="zhime-circle" database="zhime-circle"/> <dataNode name="zhime-treaty" dataHost="zhime-treaty" database="zhime-treaty"/> <dataNode name="zhime-score" dataHost="zhime-score" database="zhime-score"/> <dataNode name="zhime-message" dataHost="zhime-message" database="zhime-message"/> <dataNode name="zhime-addressbook" dataHost="zhime-addressbook" database="zhime-addressbook"/> <dataNode name="zhime-resume" dataHost="zhime-resume" database="zhime-resume"/> <dataNode name="zhime-operation" dataHost="zhime-operation" database="zhime-operation"/> <dataNode name="zhime-uc-center" dataHost="zhime-uc-center" database="zhime-uc-center"/> <dataNode name="dubboconfig" dataHost="dubboconfig" database="dubboconfig"/> <dataNode name="activiti6" dataHost="activiti6" database="activiti6"/> <dataNode name="db_huhahome_crm" dataHost="db_huhahome_crm" database="db_huhahome_crm"/> <dataNode name="zhime-email" dataHost="zhime-email" database="zhime-email"/> <dataNode name="zhime-theme" dataHost="zhime-theme" database="zhime-theme"/> <dataNode name="huhacitytttc" dataHost="huhacitytttc" database="huhacitytttc"/> <dataNode name="xmpp" dataHost="xmpp" database="xmpp"/> <dataNode name="dianping" dataHost="dianping" database="dianping"/> <dataHost name="zhime-api" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-api" url="10.8.82.2:3301" user="zhime-api" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-company" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-company" url="10.8.82.2:3302" user="zhime-company" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-newpoint" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-newpoint" url="10.8.82.2:3303" user="zhime-newpoint" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-rating" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-rating" url="10.8.82.2:3304" user="zhime-rating" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-circle" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-circle" url="10.8.82.2:3305" user="zhime-circle" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-treaty" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-treaty" url="10.8.82.2:3306" user="zhime-treaty" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-score" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-score" url="10.8.82.2:3307" user="zhime-score" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-message" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-message" url="10.8.82.2:3308" user="zhime-message" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-addressbook" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-addressbook" url="10.8.82.2:3309" user="zhime-addressbook" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-resume" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-resume" url="10.8.82.2:3310" user="zhime-resume" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-operation" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-operation" url="10.8.82.2:3311" user="zhime-operation" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-uc-center" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-uc-center" url="10.8.82.2:3312" user="zhime-uc-center" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="dubboconfig" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="dubboconfig" url="10.8.82.2:3313" user="root" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="activiti6" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="activiti6" url="10.8.82.2:3314" user="root" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="db_huhahome_crm" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="db_huhahome_crm" url="10.8.82.2:3315" user="huhahome_crm" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-email" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-email" url="10.8.82.2:3316" user="zhime-email" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="zhime-theme" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="zhime-theme" url="10.8.82.2:3317" user="zhime-theme" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="huhacitytttc" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="huhacitytttc" url="10.8.82.2:3318" user="root" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="xmpp" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="xmpp" url="10.8.82.2:3319" user="root" password="sunfun!QAZ2wsx"/> </dataHost> <dataHost name="dianping" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="dianping" url="10.8.82.2:3320" user="root" password="sunfun!QAZ2wsx"/> </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> <!-- 1为开启实时统计、0为关闭 --> <property name="useGlobleTableCheck">0</property> <!-- 1为开启全加班一致性检测、0为关闭 --> <property name="sequnceHandlerType">2</property> <!-- <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--> <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">1m</property> <!-- 单位为k --> <property name="spillsFileBufferSize">1k</property> <property name="useStreamOutput">0</property> <!-- 单位为m --> <property name="systemReserveMemorySize">384m</property> <!--是否采用zookeeper协调切换 --> <property name="useZKSwitch">true</property> </system> <!-- 全局SQL防火墙设置 --> <!-- <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 权限设置 --> <!-- <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="zhime-api"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-api</property> </user> <user name="zhime-company"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-company</property> </user> <user name="zhime-newpoint"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-newpoint</property> </user> <user name="zhime-rating"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-rating</property> </user> <user name="zhime-circle"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-circle</property> </user> <user name="zhime-treaty"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-treaty</property> </user> <user name="zhime-score"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-score</property> </user> <user name="zhime-message"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-message</property> </user> <user name="zhime-addressbook"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-addressbook</property> </user> <user name="zhime-resume"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-resume</property> </user> <user name="zhime-operation"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-operation</property> </user> <user name="zhime-uc-center"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-uc-center</property> </user> <user name="dubboconfig"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">dubboconfig</property> </user> <user name="activiti6"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">activiti6</property> </user> <user name="huhahome_crm"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">db_huhahome_crm</property> </user> <user name="zhime-email"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-email</property> </user> <user name="zhime-theme"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">zhime-theme</property> </user> <user name="huhacitytttc"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">huhacitytttc</property> </user> <user name="xmpp"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">xmpp</property> </user> <user name="dianping"> <property name="password">sunfun!QAZ2wsx</property> <property name="schemas">dianping</property> </user> </mycat:server>