Mycat Read/write separation

Source: Internet
Author: User

Version: mycat1.0
Only need to read and write separate functions, the sub-database of the table is not required.

The configuration file involved:
1.conf/server.xml
The main configuration is mycat user name and password, mycat user name and password and the MySQL user name password is separate, the application connection Mycat Use this user name and password.

<? xml version= "1.0" encoding= "UTF-8"?><!DOCTYPE mycat:server SYSTEM "SERVER.DTD" ><Mycat:serverxmlns:mycat="http://org.opencloudb/" > <System>  <!-- <property name= "Processors" >32</property> <property name= "Processorexecutor" >32</property> <property name= "ServerPort" >8066</property> <property name= "Managerport" >9066</property> - </System> <user name= "root" >  <property name= "password" >root</property>  << Span class= "title" >property name= "schemas" > Database name </property> </user></ MYCAT:SERVER>              

2.conf/schema.xml
The main configuration of the master-slave database connection address information, schema can not configure the table definition, if configured to check the syntax of SQL, there are many problems mycat.

 <? xml version= "1.0"?><!DOCTYPE mycat:schema SYSTEM "SCHEMA.DTD" ><Mycat:schemaxmlns:mycat="http://org.opencloudb/" > <SchemaName="Database Name"Checksqlschema="False"Datanode="DN1" > </Schema> <DataNodeName="DN1"datahost="Localhost1"Database="Database name"/> <DatahostName="Localhost1"maxcon="1000"mincon="100"Balance="1"Dbtype="MySQL"Dbdriver="Native" >  <Heartbeat>select User ()</Heartbeat>  <!--can have multi write hosts--  <Writehosthost="10.1.3.50"Url="10.1.3.50:3306"User="Database user name"password="Database Password" >   <!--can have multi read hosts--   <Readhosthost="10.1.3.5"Url="10.1.3.5:3306"User="Database user name"password="Database Password"/>   <Readhosthost="10.1.3.6"Url="10.1.3.6:3306"User="Database user name"password="Database Password"/>  </Writehost>  <!--writehost host= "10.1.3.34" url= "10.1.3.34:3306" user= "Database user name" password= "Database Password"--   <! --can have multi read hosts-->   <! --readhost host= "10.1.3.7" url= "10.1.3.7:3306" user= "Database user name" password= "Database Password"/-->   <! --readhost host= "10.1.3.8" url= "10.1.3.8:3306" user= "Database user name" password= "Database Password"/-->  <! --/writehost--> </datahost ></MYCAT:SCHEMA>      

High availability and read/write separation
Mycat's read-write separation mechanism is as follows:
• SQL within a transaction, all of the nodes are written, unless a SELECT statement begins with a comment/*balance*/
• Auto-Commit SELECT statement will be a daytime node and randomly load balanced among all available read nodes
• When a master node is down, all its read nodes are no longer in use, because at this point, the synchronization fails, the data is not up to date, and the MYCAT uses all the read nodes corresponding to the other master node to achieve select load Balancing.
• When all primary nodes fail, for system high availability, all SELECT statements that are submitted automatically will still be committed to all surviving read nodes, and many of the system's pages will still be able to come out of the data, but the user's modification or submission will fail.

The balance property of the Datahost is set to:
• 0, do not open the read and write separation mechanism
• 1, all readhost and stand by writehost participate in the load balancing of SELECT statements, simply put, when dual master dual slave mode (M1->S1,M2->S2, and M1 and M2 are mainly prepared), under normal circumstances, M2,S1, S2 all participate in load balancing of the SELECT statement.
• 2, all readhost and writehost participate in the load balancing of the SELECT statement, that is, all hosts can assume load balancing when the system has a low write operation pressure.
A datahost element that indicates a set of databases in which data is synchronized, and the DBA needs to ensure that the set of database servers is synchronized with data replication. Writehost is equivalent to master DB server, while its readhost is slave DB server that synchronizes from the database. When Datahost is configured with multiple writehost, any one writehost down, Mycat is automatically detected and attempts to switch to the next available writehost.

Mycat supports high-availability enterprise-class features, depending on your application's characteristics, you can configure several strategies:
• The backend database is configured as a master multi-slave and opens the read-write separation mechanism.
• Backend database configured as dual master dual slave (multi-Slave), and open read/write separation mechanism
• Backend database configured for multi-master and multi-Slave, and open read-write separation mechanism
The following two configurations, with higher system availability, when one of the write nodes (master node) fails, Mycat will detect (heartbeat mechanism) and automatically switch to the next write node, mycat at any time, will only write data to a write node.

Mycat Read/write separation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.