MySQL read-write separation

Source: Internet
Author: User
Tags lua

Mysql Read-write separation

MySQL read-write separation technology is also known as the MySQL Proxy service, through the MySQL On the base of master-slave synchronization, a proxy server is added to realize load balancing by allocating read and write operations to different servers for accessing the database, thus increasing the speed of database access.

To build MySQL Read and write separation service, the first to build a mysql master-Slave synchronization service, where the primary server is responsible for write operations, that is, as a write server, from the server responsible for read operations, that is, read the server. Install the agent software and MySQL database on the proxy server during the construction process . Its specific allocation policy needs to be implemented by script, this article adopts the package default script.

Build steps:

1. build MySQL master-Slave synchronization server

2. Proxy Server Install agent software and turn on service

This article uses the mysql-proxy-0.8.3-linux-rhel5-x86-64bit.tar.gz Agent package, which does not need to be installed and can be used directly after decompression.

(1) Unpacking Packages

TAR-ZXF mysql-proxy-0.8.3-linux-rhel5-x86-64bit.tar.gz-c/usr/local/mysql-proxy

Enter the extracted directory

(2) to add execute permissions for an assignment policy script

Its allocation policy script is located in the /usr/local/mysql-proxy/share/doc/mysql-proxy/ directory under the software directory , where the Rw-splitting.lua It's a policy script .

chmod a+x rw-splitting.lua// Add Execute permissions to the script

(3) release the 3306 Port and start the service

Netstat-tnlup | grep:3306// Check if 3306 Port is occupied

Enter the directory /usr/local/mysql-proxy/bin directory, where mysql-proxy is the startup script for the proxy service

Use the ./mysql-proxy [ option ] to start the service:

The options have the following meanings:

-P: Specify IP address, Port for agent listening

-r: Specifies the IP address, Port of the Read server

-B: Specifies the IP address, Port of the Write server

-S: Specify The path to the Lua script file

--keepalive: Automatically restarts this process if the process crashes

Note: This service needs to be running after it is started, so it can be placed in the background when the service is started, and it needs to be shut down by killing process when the service is shut down.

3. Test

Related Article

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.