Home php教程 php手册 php+sqlrelay+mysql实现连接池及读写负载均衡

php+sqlrelay+mysql实现连接池及读写负载均衡

Jun 06, 2016 pm 07:47 PM
accomplish Read and write load connect

在大型的web应用中数据库经常成为并发访问的一个瓶颈,为了有效的解决并发访问的瓶颈,利用多台数据库master-slave的模式来增加web的并发访问量。 master-slave模式是为了数据同步的问题。 sqlrelay解决连接池问题以及实现读写分离的均衡负载。 sqlrelay配置3

在大型的web应用中数据库经常成为并发访问的一个瓶颈,为了有效的解决并发访问的瓶颈,利用多台数据库master-slave的模式来增加web的并发访问量。
master-slave模式是为了数据同步的问题。
sqlrelay解决连接池问题以及实现读写分离的均衡负载。
sqlrelay配置3个instance A/B/C,A负责从Master和slave读取数据,B负责写数据,且只写Master,C为router,负责调度应用。
php通过A还是通过B连接数据库。
在实际配置中,由于master承担了读写操作,那么在instance A的配置中,可以把从Master的连接稍微降小,把从slave连接读取数据的连接数稍稍增大以此进行平衡。
一、MySQL master/slave配置
################
#mster/slave配置
################
master:192.168.1.51
slave:192.168.1.50
1、master配置
/etc/my.cnf 中加入
binlog-do-db=book book为数据库名
确保
server-id=1
log-bin=mysql-bin
授权给rep用户进行复制操作
GRANT REPLICATION SLAVE ON book.* TO rep@192.168.1.50 IDENTIFIED BY '123456';
重启master服务
2、配置slave
vi /etc/my.cnf
设置下面4行
server-id       = 2
master-host     =   192.168.1.51
master-user     =   rep
master-password =   123456
重启slave
3、把master的原始数据导入slave。
二、sqlrelay配置
当前行业中比较流行的连接池解决方案几乎都不支持php,经过多番努力终于在找到了一个开源的连接池技术--------sqlrelay。
sqlreplay支持的语言:
C C++ Perl  Python PHP Ruby  Java TCL Zope 

sqlreplay支持的数据库:

Oracle MySQL mSQL PostgreSQL Sybase MS SQL Server   IBM DB2 Interbase Sybase SQLite ODBC MS Access
sqlreplay的网站
http://sqlrelay.sourceforge.net/。




基本思路:
1、配置2个实例用以最终处理业务
clubs-read
clubi-write
其中读取的 instance分别配置两个连接,且两个连接启动对等的连接数。
2、配置一个instance来调度读写操作,即clubr
通过router来区分读写连接不同的mysql数据库。



       
       
               
                       
               

               
                       
                       
               

       

       
               
                       

 
               
                       
               

       

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to connect keep body fat scale How to connect keep body fat scale Mar 07, 2024 pm 04:50 PM

How to connect the keep body fat scale? Keep has a specially designed body fat scale, but most users do not know how to connect the keep body fat scale. Next is the graphic tutorial on the connection method of the keep body fat scale that the editor brings to users. , interested users come and take a look! How to connect the keep body fat scale 1. First open the keep software, go to the main page, click [My] in the lower right corner, and select [Smart Hardware]; 2. Then on the My Smart Devices page, click the [Add Device] button in the middle; 3 , then select the device you want to add interface, select [Smart Body Fat/Weight Scale]; 4. Then on the device model selection page, click the [keep body fat scale] option; 5. Finally, in the interface shown below, finally [Add Now] at the bottom

How to implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

How to implement SSL passthrough in HAProxy How to implement SSL passthrough in HAProxy Mar 20, 2024 am 09:30 AM

Keeping web servers load balanced is one of the key measures to prevent downtime. Using a load balancer is a reliable approach, with HAProxy being a highly regarded choice. Using HAProxy, you can accurately configure the load balancing method and support SSL passthrough to ensure the security of communication between the client and the server. It starts by exploring the importance of implementing SSL passthrough in HAProxy, followed by a detailed discussion of the steps required to implement this feature and an example for better understanding. What is SSL passthrough? Why is it important? As a load balancer, HAProxy accepts and distributes the load flowing to your web servers across configured servers. Load distribution is targeted to client devices and

PHP Programming Guide: Methods to Implement Fibonacci Sequence PHP Programming Guide: Methods to Implement Fibonacci Sequence Mar 20, 2024 pm 04:54 PM

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

How to implement the WeChat clone function on Huawei mobile phones How to implement the WeChat clone function on Huawei mobile phones Mar 24, 2024 pm 06:03 PM

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

How to connect OnePlus watch to Bluetooth headset_How to connect OnePlus watch to Bluetooth headset How to connect OnePlus watch to Bluetooth headset_How to connect OnePlus watch to Bluetooth headset Mar 23, 2024 pm 01:16 PM

1. Place the earphones in the earphone box and keep the lid open. Press and hold the button on the box to enter the pairing state of the earphones. 2. Turn on the watch music function and select Bluetooth headphones, or select Bluetooth headphones in the watch settings function. 3. Select the headset on the watch to pair successfully.

Three Ways to Fix Edge Your Connection Isn't Private Three Ways to Fix Edge Your Connection Isn't Private Mar 13, 2024 pm 01:30 PM

When you use the Edge browser to access web pages, have you ever encountered a prompt that your connection is not a dedicated connection, causing web browsing to fail? How is this going? Many friends don’t know how to deal with this problem. You can take a look at the following three solutions. Method 1 (simple and crude): In the edge browser, you can try to solve the problem of the website being inaccessible by entering the settings and turning off the security function, and then blocking location permissions in the website permissions. It is important to note that the effectiveness and duration of this approach may vary, and specific effects cannot be determined. After restarting your browser, you can try visiting the website to see if the issue is resolved. Method 2: Adjust the keyboard to English input

Steps to connect game controller to Gohan Arcade Steps to connect game controller to Gohan Arcade Mar 19, 2024 pm 03:55 PM

How to connect Bluetooth controller to Gohan Arcade? Gohan Game Center is a game box used by many mobile game players. It contains a large number of popular game resources and rich game-related functions. Below, the editor will introduce the game controller connection method. Players, please take a look. 1. First go to the homepage of Gohan Game Center APP, and then click the "My" option in the lower right corner of the homepage; 2. Find the [Controller] function in the My page, the location is shown in the picture below, and click to go to settings; 3. Select to turn it on For the Bluetooth function of the mobile phone, confirm that the power of the controller is on; 4. Finally, follow the instructions of the controller to make a matching connection. If the connection is successful, you can use the mobile game to experience various games.

See all articles