mycat主要是提供了数据库库切分的一种具体实现配置,这一篇我们不做深入剖析,先让程序跑起来再说!
mycat官网:http://www.mycat.io/ #中文的别怕
1>环境:
CentOS操作系统
mysql5.6
主库主机:192.168.0.1
从库a主机:192.168.0.2
从库b主机:192.168.0.3由于测试,我没开太多虚拟机,所有把mycat服务器和从库b装在了一台机器上了
##################################
2>配置mycat先确保,配置好主从复制,半同步复制。(我之前博文有讲详细步骤)
3>开始配置mycat
(1)先安装JDK(因为mycat是用java实现的)
JDK 下载:http://www.oracle.com/technetwork/java/javase/downloads/
(2)在安装mycat
官网下载并解压:tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
(3)#配置/etc/profile
export JAVA_HOME=/usr/app/jdk1.8.0_171
export JRE_HOME=/usr/app/jdk1.8.0_171/jre
export MYCAT_HOME=/usr/app/mycat
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$MYCAT_HOME/bin
(4)mycat配置(先备份三个配置文件)
>>cd /d/mycat/conf
>>ls
rule.xml
server.xml
schema.xml
server.xml
<!-- 全局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">contract0</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">contract0</property>
<property name="readOnly">true</property>
</user>
schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="contract0" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
</schema>
<dataNode name="dn1" dataHost="localhost1" database="contract0" />
<dataHost name="localhost1" maxCon="100" minCon="4" balance="3"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="192.168.0.1:3306" user="root"
password="123123">
<!-- can have multi read hosts -->
<readHost host="hostS1" url="192.168.0.2:3306" user="root" password="123123" weight="1"/>
<readHost host="hostS2" url="192.168.0.1:3306" user="root" password="123123" weight="1"/>
</writeHost>
</dataHost>
</mycat:schema>
4>安装完成后,启动:
>>mycat --help
Usage: /d/mycat/bin/mycat { console | start | stop | restart | status | dump }
>>mycat start
OK,可以跑起来了!后续博文将详细介绍mycat!!