mycat_分库分表,读写分离技术安装
作者:互联网
1,yum安装jdk 并配置环境变量
2,关闭防火墙 ,必须
3,在/usr/local/目录下新建一个mycat的目录
4,将tar.gz压缩包拷贝到mycat目录下
5,解压目录
6,将一下文件进行拷贝
schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://org.opencloudb/">
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
<!-- test_table 是数据库需要拆分的表 dataNode 对应 下面的dataNode dn1,dn2,dn3......分拆多个 -->
<!-- rule="mod-long" 对应 找到 name="mod-long" class="org.opencloudb.route.function.PartitionByMod 类 ,修改 <property name="count">1</property> count代表需要分片多少个库,
如果是3就表示拆成了3个数据库,每次插入都要 对3取模, 插入的字段分别存入到不同的数据库
常用分片规则:
按照周 月
这里1个就改一个 -->
<table name="test_table" dataNode="dn1,dn2,dn3" rule="mod-long" primaryKey="ID" />
</schema>
<!-- test2 test3 test4 代表拆分成了多个数据库的数据库名,这里还要去修改rule.xml 配置文件,同级的
-->
<dataNode name="dn1" dataHost="localhost1" database="test2" />
<dataNode name="dn2" dataHost="localhost1" database="test3" />
<dataNode name="dn3" dataHost="localhost1" database="test4" />
<!-- 数据库主从读写配置,balance重要0:主从都在一个机子上 1:双主双从 选举机制 2: 所有的读操作在主备切换 3:读写完全分离 生产环境选1和3 -->
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="2"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts 写数据库配置 -->
<writeHost host="hostM1" url="192.168.1.162:3306" user="root"
password="root">
<!-- 读数据库配置 -->
<readHost host="hostS1" url="192.168.1.163:3305" user="slave" password="123456" />
</writeHost>
</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://org.opencloudb/">
<system>
<property name="defaultSqlParser">druidparser</property>
<!-- <property name="processorBufferChunk">40960</property> -->
<!--
<property name="processors">1</property>
<property name="processorExecutor">32</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="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>
<user name="root">
<property name="password">123456</property>
<property name="schemas">TESTDB</property>
</user>
<user name="user">
<property name="password">user</property>
<property name="schemas">TESTDB</property>
<property name="readOnly">true</property>
</user>
<!-- <cluster> <node name="cobar1"> <property name="host">127.0.0.1</property>
<property name="weight">1</property> </node> </cluster> -->
<!-- <quarantine> <host name="1.2.3.4"> <property name="user">test</property>
</host> </quarantine> -->
</mycat:server>
7,如果无法启动表示看日志
查看日志 /mycat/logs/wrapper.log发现如下信息
解决方案:
在mycat/conf/wrapper.conf 下增加:
wrapper.java.command=java安装目录/bin/java
8,启动native连接测试
标签:分库,java,--,32,wrapper,mycat,分表,目录 来源: https://blog.csdn.net/qq_37430469/article/details/123618098