MySQL master-slave replication and read-write separation

Source: Internet
Author: User
Tags iptables

Experimental topology:

Address assignment:
Client 192.168.1.1
Amoeba 192.168.1.2
Mysql-master 192.168.1.3
Mysql-slave1 192.168.1.4
Mysql-slave2 192.168.1.5
1, Configuration Time synchronization
1) on master, use Yum to install NTP and modify its profile/etc/ntp.conf to start the service. Open the iptables exception for UDP port 123.
2) perform/usr/sbin/ntpdate 192.168.1.3 on both slave to synchronize time synchronization with master.
2, master-slave replication
Note: The iptables exception for TCP port 3306 is required on all three MySQL databases.
1) configuration of master server master
Configuration of the/ETC/MY.CNF

Restart MYSQLD Service

Execute mysql-u root-p log in to the MySQL database and authorize the server

2) configuration from server slave (two from server configuration)
Configuration of the/ETC/MY.CNF

Restart Services (Service mysqld restart), log in to MySQL configuration startup slave

Show slave status\g to see if the master-slave copy is running properly. Master-slave replication relies on both the SQL process and the IO process, which means "yes" for normal operation.

3. Read/write separation
MySQL read-write separation can be implemented in two ways, based on the internal implementation of program code and middleware-based implementation, this time using amoeba is one of the methods based on middleware implementation.
1) configuration of Amoeba middleware server
Installing the JDK

Modify/etc/profile

The execution source/etc/profile takes effect immediately, java-version to see if the installation is complete.

Installing Amoeba

Modify the Amoeba configuration file/usr/local/amoeba/conf/amoeba.xml


Modify the Amoeba configuration file/usr/local/amoeba/conf/dbservers.xml



Start Amoeba, view ports

So the amoeba middleware needs to turn on TCP port 8066iptables exceptions.
2) Three MySQL need to give Aomeba authorization (three same operation)

4, the Client connection amoeba. (normal should add-p8066 after the command, I later changed the port to 3306, you do not have to add the port number in the back)

Note: Enter the password for ' amoeba ' at the horizontal line ' 123456b ', while the password for ' Chen ' in the command is ' 123456c '.
In summary, the final result is:
1) on the slave log on to the local MySQL write data, will not sync to master, and write data on master, you can sync to slave.
2) Turn off the master-slave copy, write the data on the client, you can see the data on Master, slave (because the client writes the data directly to master).
3) after the master-slave replication is turned off, log on to the local MySQL write data on master, the client cannot read the data, but the client can read the local write data on the slave (because the client read data is read from slave).

MySQL master-slave replication and 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.