mariadb separate read and write

mycat

  maraidb master-slave architecture, is the main responsible for writing, reading from responsible, but if there is no front-end scheduler, it is not possible to read and write separation. This involves an intermediate station, it is mycat. It must be separated from the read and write on the main infrastructure.

Three from the main configuration architecture.

mycat side configuration:

First, add in the hosts file (each machine add)

mycat:192.168.24.10

hostM1:192.168.24.8

hostM2:192.168.24.9

Second, you need to install java1.8 version or above

Third, download the source package mycat

wget http://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

mv mycat /usr/local/

Four, vim /usr/local/mycat/conf/server.xml set the following parameters

<user name="testuser1">

<property name="password">testuser1</property>

<property name="schemas">testdb,testdb1</property>

</user>

<user name="testuser2">

<property name="password">testuser2</property>

<property name="schemas">testdb,testdb1</property>

<property name="readOnly">true</property>

</user>

# Testuser1 for user-written

# Testuser2 used to read the user

#testdb is mycat is a logical library

Five, vim /usr/local/mycat/conf/schema.xml configuration (please backup cp schema.xml schema.xml.bak, then schema.xml empty file, paste the following)

<?xml version="1.0"?>

<!DOCTYPE mycat:schema SYSTEM "schema.dtd">

<mycat:schema xmlns:mycat="http://io.mycat/">

<schema name="testdb" checkSQLschema="false" sqlMaxLimit="1000" dataNode="dn1">

</schema>

<schema name="testdb1" checkSQLschema="false" sqlMaxLimit="1000" dataNode="dn2">

</schema>

 

<dataNode name="dn1" dataHost="hostM1" database="test" />

<dataNode name="dn2" dataHost="hostM1" database="test1" />

<dataHost name="hostM1" maxCon="2000" minCon="1" balance="1" writeType="1" dbType="mysql" dbDriver="native" switchType=

"1" slaveThreshold="100">

<heartbeat>select user()</heartbeat>

<writeHost host="hostM1" url="192.168.24.8:3306" user="testuser1" password="testuser1">

<readHost host="hostS1" url="192.168.24.9.:3306" user="testuser2" password="testuser2" />

</writeHost>

</dataHost>

</mycat:schema>

Sixth, start mycat service

/usr/local/mycat/bin/mycat start

Seven, login

8066 is a management port

9066 is the port connected to the back-end database, the default is 9066, after logging the port directly with the show @@ datasource; query statement to master reading and writing from the state library

-H MySQL 192.168 . 24.10 -P8066 -utestuser1 - ptestuser1 (can perform CRUD) 

MySQL -H 192.168 . 24.10 -P9066 -utestuser1 -ptestuser1 (node status can be viewed)

View heartbeat status: show @@ heartbeat \ G

# Check the front end of the connection status: show @@ connection \ G

# View backend state: show @@ backend \ G

# View database resource status: show @@ datasource

The master node end: Create a User

grant all on *.* to testuser1@'%' identified by 'testuser1';

grant all on *.* to testuser2@'%' identified by 'testuser

Guess you like

Origin www.cnblogs.com/shuaiyin/p/10962517.html