The separation of reading and writing in mycat

Posted by biocyberman on Sun, 05 Jan 2020 22:05:19 +0100

mycat mainly provides a specific configuration of database segmentation. In this article, we will not do in-depth analysis, let the program run first!

MYCAT official website: http://www.mycat.io/ ා don't be afraid of Chinese

1 > environment:

CentOS operating system
mysql5.6
Master database host: 192.168.0.1
Slave a host: 192.168.0.2
Slave b host: 192.168.0.3

Because of the test, I didn't open too many virtual machines, so I installed mycat server and slave b on one machine

##################################

2> To configure mycat, first ensure that the master-slave replication and semi synchronous replication are configured. (I have detailed steps in my previous blog)

3> Start configuring mycat

(1) Install JDK first (because mycat is implemented in java)

JDK Download: http://www.oracle.com/technetwork/java/javase/downloads/ 

(2) Installing mycat on

Download and unzip on the official website: tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

(3) Configure / 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 configuration (back up three profiles first)

>>cd /d/mycat/conf
>>ls
rule.xml
server.xml
schema.xml 

server.xml

        <!-- Overall situation SQL Firewall settings -->
        <!-- 
        <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>

                <!-- Table level DML Permission settings -->
                <!--            
                <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> After installation, start:
>>mycat --help
Usage: /d/mycat/bin/mycat { console | start | stop | restart | status | dump }
>>mycat start

OK, you can run! The following blog will introduce mycat in detail!!

Topics: mycat xml Database firewall