搭建MySQL代理服务器实现读写分离+主从同步_MySQL
代理服务器
实验需求:
1.配置2台MySQL服务器(192.168.100.2,192.168.100.3)+1台代理服务器(192.168.100.1),实现MySQL代理的读写分离。
2.用户只需要访问MySQL代理服务器,实际的SQL查询、写入操作交给后台的2台MySQL服务器来完成。
3.2台MySQL服务器实现主从同步,其中Master服务器允许SQL查询、写入,Slave服务器只允许SQL查询。
Ubuntu下Nginx做负载实现高性能WEB服务器5---MySQL主主同步http://www.linuxidc.com/Linux/2012-06/61687p5.htm
生产环境MySQL主主同步主键冲突处理http://www.linuxidc.com/Linux/2013-07/86890.htm
MySQL主从失败 错误Got fatal error 1236http://www.linuxidc.com/Linux/2012-02/54729.htm
MySQL主从复制,单台服务器上实施http://www.linuxidc.com/Linux/2013-03/81913.htm
一 .MASTER数据库服务器(192.168.100.2)的配置
1.安装软件包(本实验采用MySQL5.6版本)
# rpm -qa | grep -i mysql
MySQL-shared-5.6.15-1.el6.x86_64
MySQL-devel-5.6.15-1.el6.x86_64
MySQL-embedded-5.6.15-1.el6.x86_64
MySQL-test-5.6.15-1.el6.x86_64
MySQL-server-5.6.15-1.el6.x86_64
MySQL-client-5.6.15-1.el6.x86_64
MySQL-shared-compat-5.6.15-1.el6.x86_64
2.启动服务并登录数据库本机对代理服务器做用户授权
# service mysql start && chkconfig mysql on
mysql> grant all on *.* to proxyuser@"192.168.100.1" identified by "123456";
3.创建测试数据库和表
mysql> create database proxydb;
mysql> create table proxydb.proxytab(id int);
mysql> insert into proxydb.proxytab values (2);
二 .SLAVE数据库服务器(192.168.100.3)的配置
1.安装软件包
2.启动服务并登录数据库本机对代理服务器做用户授权
# service mysql start && chkconfig mysql on
mysql> grant all on *.* to proxyuser@"192.168.100.1" identified by "123456"; //与MASTER数据库服务器做一样的授权
3.创建测试数据库和表
mysql> create database proxydb; //创建一样的库和表
mysql> create table proxydb.proxytab(id int);
mysql> insert into proxydb.proxytab values (3); //为了能测试区分2台不同数据库服务器,先插入不同数据
三.MySQL代理服务器配置
1.在做代理服务器上测试授权用户能否登录2台数据库服务器
# mysql -h192.168.100.2 -uproxyuser -p123456 //登录MASTER服务器
mysql> select * from proxydb.proxytab;
+------+
| id |
+------+
| 2 |
+------+
1 row in set (0.00 sec)
# mysql -h192.168.100.3 -uproxyuser -p123456 //登录SLAVE服务器
mysql> select * from proxydb.proxytab;
+------+
| id |
+------+
| 3 |
+------+
1 row in set (0.00 sec)
2.释放3306端口
# service mysqld stop
# chkconfig mysqld off
# netstat -tulnp | grep :3306
3.安装提供代理服务器的软件包
# tar zxvf mysql-proxy-0.8.3-linux-rhel5-x86-64bit.tar.gz
# mv mysql-proxy-0.8.3-linux-rhel5-x86-64bit /usr/local/mysql-proxy //此包为绿色免安装
# yum -y install lua //此软件使用LUA脚本语言,因此需要安装好lua软件包
代理服务启动时 会设置 负责写的数据库 负责读数据库服务器
调用脚本来区分用户的访问类型
指定自己监听的端口
4.启动代理服务
cd /usr/local/mproxy/bin/
使用bin目录下的mysql-proxy脚本来启动代理服务
# ./mysql-proxy -P 192.168.100.1:3306 -r 192.168.100.3:3306 -b 192.168.100.2:3306 -s /usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua &
主要命令选项:
-P:指定代理监听的IP地址、端口
-r:指定读服务器的IP地址、端口
-b:指定写服务器的IP地址、端口
-s:指定lua脚本文件
--keepalive:如果服务进程崩溃,尝试重启此进程
5.查看代理进程是否运行
# jobs
# netstat -tulnp | grep :3306
tcp 0 0 192.168.100.1:3306 0.0.0.0:* LISTEN 3314/mysql-proxy
//代理进程必须处于运行状态,客户端才能通过代理服务访问到后端的数据库服务器。
6.查看读写分离脚本
# vim /usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua
……
40 min_idle_connections = 4, //默认并发请求大于4才实行读写分离
41 max_idle_connections = 8,
更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2014-05/102265p2.htm

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Several Windows users have complained that when they try to access some websites on Google Chrome browser on their systems, they are unable to access the web pages. It also displays a message on the browser saying "The site cannot be reached" with error code ERR_ADDRESS_UNREACHABLE. There could be many potential reasons behind this issue, it could be due to website server issues, proxy server settings, unstable internet connection, etc. If you encounter similar problems, don't panic. After deeply analyzing the problem in this article, we got a bunch of solutions. Before proceeding, try the following workarounds: Try checking if the user is trying to access the site from other devices and there are no issues, then this

With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the "Discover" button in the lower right corner, and then select the "Notes" option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the "Follow" button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select "Personal Information"

The Local Users and Groups utility is built into Computer Management and can be accessed from the console or independently. However, some users find that local users and groups are missing in Windows 11. For some people who have access to it, the message suggests that this snap-in may not work with this version of Windows 10. To manage user accounts for this computer, use the User Accounts tool in Control Panel. The issue has been reported in previous iterations of Windows 10 and is usually caused by issues or oversights on the user's side. Why are local users and groups missing in Windows 11? You are running Windows Home edition, local users and groups are available on Professional edition and above. Activity

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

When accessing the Internet through popular web browsers such as Mozilla Firefox, Google Chrome, Internet Explorer, etc., many users face the problem of proxy server not responding. The main reason why this error may appear on your computer may be due to incorrect proxy settings. Incorrect proxy settings can be corrected by disabling the proxy, so we can resolve the issue. In this article, we explain through 3 different methods how you can easily disable the proxy in your machine and thus fix the proxy server not responding issue. Read on to learn this simple trick. Method 1: Disable Proxy via Internet Properties Step 1: Press W Simultaneously

Certain folders are not always accessible due to permissions, and in today’s guide we will show you how to access user folders on your old hard drive on Windows 11. The process is simple but can take a while, sometimes even hours, depending on the size of the drive, so be extra patient and follow the instructions in this guide closely. Why can't I access my user folders on my old hard drive? User folders are owned by another computer, so you cannot modify them. You don't have any permissions on the folder other than ownership. How to open user files on old hard drive? 1. Take ownership of the folder and change permissions Find the old user directory, right-click on it and select Properties. Navigate to "An

Many users have been added to the Ubuntu system. I want to delete the users that are no longer in use. How to delete them? Let’s take a look at the detailed tutorial below. 1. Open the terminal command line and use the userdel command to delete the specified user. Be sure to add the sudo permission command, as shown in the figure below. 2. When deleting, be sure to be in the administrator directory. Ordinary users do not have this permission. , as shown in the figure below 3. After the delete command is executed, how to judge whether it has been truly deleted? Next we use the cat command to open the passwd file, as shown in the figure below 4. We see that the deleted user information is no longer in the passwd file, which proves that the user has been deleted, as shown in the figure below 5. Then we enter the home file

sudo (superuser execution) is a key command in Linux and Unix systems that allows ordinary users to run specific commands with root privileges. The function of sudo is mainly reflected in the following aspects: Providing permission control: sudo achieves strict control over system resources and sensitive operations by authorizing users to temporarily obtain superuser permissions. Ordinary users can only obtain temporary privileges through sudo when needed, and do not need to log in as superuser all the time. Improved security: By using sudo, you can avoid using the root account during routine operations. Using the root account for all operations may lead to unexpected system damage, as any mistaken or careless operation will have full permissions. and
