mycat separation of read and write database middleware

  mycat core concepts

  Mycat defined logical library, database management

  Logical sub-library required logical table stored in the sub-table contained in the library table

  Datanode data node storing node (node ​​fragment), a logic table slice

  Host datahost data host (master node), the node where the data

  writehost write a real database service host host

  readhost read Host

  mysql master-slave synchronization configuration

  1, synchronized to create an account on the primary database

  grant replication slave on *.* to 'repl'@'192.168.5.125' identified by '123456';

  2, the master node configuration, open binlog, vi /etc/my.cnf, add the following configuration

MySQL--bin = log bin # log file name prefix 
server integer -id = 1 # in the cluster unique id, the value may be 1 to 2 ^ 32-1

  3, restart mysql, enter, mysql client, SHOW MASTER STATUS view the main library status

  4, from the node, adding configure, vi /etc/my.cnf, add

server-id=2

  5, from entering mysql client node, performs the synchronization setting CHANGE MASTER TO statement host library 

CHANGE MASTER TO MASTER_HOST='192.168.5.144',MASTER_USER='repl',MASTER_PASSWORD='123456';

  6, open from the library START SLAVE; SHOW SLAVE STATUS from the library to view the state;

  7, the following command in the master library, to see whether a corresponding database, and data tables from the database

CREATE DATABASE orders CHARACTER SET 'utf8';

use orders;

CREATE TABLE t_order (
order_id BIGINT PRIMARY KEY,
order_time DATETIME,
customer_id BIGINT,
order_amount DECIMAL(8,2)
);

  mycat master-slave configuration

  Reference detailed configuration: http://www.mycat.io/document/mycat-definitive-guide.pdf

  1, schema.xml configuration logic library data node, data host

<? Xml Version = "1.0" ?> 
<! : DOCTYPE myCat the SYSTEM Schema "schema.dtd" > 
< myCat: Schema xmlns: myCat = "HTTP: //io.mycat/" > 
! <- Note: inside element according to a certain schema, the order dataNode, dataHost configuration -> 
< Schema name = "MYDB1" checkSQLschema = "to false" sqlMaxLimit = "100" 
Datanode = "mydn1" > 
</ Schema > 
< Datanode name = "mydn1" DataHost = "dhost1" Database = "orders" />
<dataNode name="mydn2" dataHost="dhost2" database="orders" />
<!-- 读写分离第一种配置方式 -->
<dataHost name="dhost1" maxCon="1000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select user()</heartbeat>
<writeHost host="myhostM1" url="192.168.100.218:3306" user="mike"
password="Mike666!">
<readHost host="myhostS1" url="192.168.100.219:3306"
user="mike" password="Mike666!" weight="1" />
</writeHost>
</dataHost>
<!-- 读写分离第二种配置方式 -->
<dataHost name="dhost2" maxCon="1000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select user()</heartbeat>
<writeHost host="myhostM2" url="192.168.100.218:3306" user="mike"
password="Mike666!"></writeHost>
<writeHost host="myhostS2" url="192.168.100.219:3306" user="mike"
password="Mike666!"></writeHost>
</dataHost>
</mycat:schema>

  2, server.xml configure the user database permissions

<user name="root" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">mydb1</property>
</user>

  3, the difference between the two configurations of the separate read and write mode

  The first host read write mysql not hang up after use, the second stage after the first machine a second hang mysql mysql normal read and write, in fact stand by mode (standby mode)

  4, navicat or java api like mysql to connect to a single configuration, mycat will help us achieve separate read and write

Guess you like

Origin www.cnblogs.com/hhhshct/p/11355138.html