SuSE上运行MyCat(二):配置单点MyCat
https://www.jianshu.com/p/8848f6a802b1
SuSE上运行MyCat(二):配置单点MyCat
目标
通过本文操作,搭建静态结构如下图的一个MyCat集群。为了节省资源,3个物理库都将存放在同一个MySQL实例当中。
![](https://upload-images.jianshu.io/upload_images/6033023-333a3101bafac831.png?imageMogr2/auto-orient/strip|imageView2/2/w/725/format/webp)
部署MySQL节点
创建分片节点(库)
CREATE DATABASE mycat00;
CREATE DATABASE mycat01;
CREATE DATABASE mycat02;
CREATE TABLE mycat00.test_tbl(
id INT UNSIGNED NOT NULL PRIMARY KEY,
date DATETIME NOT NULL );
CREATE TABLE mycat01.test_tbl(
id INT UNSIGNED NOT NULL PRIMARY KEY,
date DATETIME NOT NULL );
CREATE TABLE mycat02.test_tbl(
id INT UNSIGNED NOT NULL PRIMARY KEY,
date DATETIME NOT NULL );
创建虚拟表用户
CREATE USER 'root'@'%' IDENTIFIED BY 'root';
GRANT ALL PRIVILIGES ON `mycat%`.* TO 'root'@'%';
插入原始数据
INSERT INTO mycat00.test_tbl(id,date)
VALUES (0,'2000-01-01');
INSERT INTO mycat01.test_tbl(id,date)
VALUES (1,'2000-02-01');
INSERT INTO mycat02.test_tbl(id,date)
VALUES (2,'2000-03-01');
配置MyCat
MyCat的配置文件集中在其配置文件夹/usr/local/mycat/conf内,以下工作将以该文件夹为基准。
路由规则(rule.xml)
备份原有路由规则文件rule.xml后,将整个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="cicular_month_rule">
<rule>
<columns>date</columns>
<algorithm>cicular_month</algorithm>
</rule>
</tableRule>
<function name="cicular_month"
class="io.mycat.route.function.PartitionByMonth">
<property name="dateFormat">yyyy-MM-dd</property>
<property name="sBeginDate">2000-01-01</property>
<property name="sEndDate">2000-03-01</property>
<property name="nPartition">3</property>
</function>
</mycat:rule>
配置虚拟库及虚拟表(schema.xml)
备份原有虚拟库文件schema.xml后,将整个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="test_tbl" dataNode="dn00,dn01,dn02" rule="cicular_month_rule" />
</schema>
<dataNode name="dn00" dataHost="dh00" database="mycat00" />
<dataNode name="dn01" dataHost="dh00" database="mycat01" />
<dataNode name="dn02" dataHost="dh00" database="mycat02" />
<dataHost name="dh00"
dbType="mysql" dbDriver="native"
maxCon="9" minCon="1" balance="0" switchType="0">
<heartbeat>select 1</heartbeat>
<writeHost host="host00"
url="192.168.35.125:3306" user="root" password="root" />
</dataHost>
</mycat:schema>
配置MyCat服务信息(server.xml及myid.properties)
备份原有服务器配置文件server.xml后,将整个server.xml改写成如下内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">
<system>
<property name="useSqlStat">0</property>
<property name="useGlobleTableCheck">0</property>
<property name="sequnceHandlerType">2</property>
<property name="processorBufferPoolType">0</property>
<property name="handleDistributedTransactions">0</property>
<property name="useOffHeapForMerge">1</property>
<property name="memoryPageSize">1m</property>
<property name="spillsFileBufferSize">1k</property>
<property name="useStreamOutput">0</property>
<property name="systemReserveMemorySize">384m</property>
<property name="useZKSwitch">false</property>
<property name="serverPort">8066</property>
<property name="managerPort">9066</property>
</system>
<user name="mycat_root">
<property name="password">123456</property>
<property name="schemas">TESTDB</property>
</user>
<user name="user">
<property name