------ reader series separated mysql

I. Introduction: The basic principle of the separate read and write

   mysql的读写分离的基本原理是:让master(主数据库)来响应事务性操作,

Let slave (from the database) in response to select non-transactional operations,

Then copied from the master using transactional operations synchronized to the slave on master database. Simple load balancing.

Second, the preparatory work:

1, two servers ready, I'm ready here is 192.168.4.122 (main), 192.168.4.123 (from)

  另外准备一台服务器安装中间件服务器(192.168.4.125)

2, first of all to do master-slave synchronization of two servers.

3, prepare separate read and write software: maxscale-2.1.2-1 (intermediate)

Three, maxscale installation and configuration (4.125)

1, the installation: rpm -ivh maxscale-2.1.2-1.rhel.7.x86_64.rpm

2, modify the configuration file: vim /etc/maxscale.cnf

 54-60行注释掉,87-91注释掉

  10   threads=auto

  18 [server1]

   19 type=server

   20 address=192.168.4.122

   21 port=3306

   22 protocol=MySQLBackend

   23 [server2]

   24 type=server

   25 address=192.168.4.123

   26 port=3306

   27 protocol=MySQLBackend

  35 [MySQL Monitor]    //监视数据库的配置

   36 type=monitor

   37 module=mysqlmon

   38 servers=server1, server2

   39 user=scalemon  //监控

   40 passwd=123456

   41 monitor_interval=10000

 63 [Read-Write Service]    //配置查询读写权限的帐号

   64 type=service

   65 router=readwritesplit

   66 servers=server1, server2

   67 user=maxscale //接收客户端连接请求时,连接的用户名和密码在数据库服务上是否存在

   68 passwd=123456

   69 max_slave_connections=100%

   104 port=4010

3, an authorized user needs to add two above on the primary library (4.122)

grant replication slave,replication client on . to scalemon@'%' identified by "123456";

grant select on mysql.* to maxscale@'%' identified by "123456";

4, start the service: maxscale -f /etc/maxscale.cnf

  停止服务:ps -C   maxscale(查进程)        kill -9 13109(杀进程)

 查看服务是否启动:netstat -natulp | grep maxscale

5, on the primary library (4.122) was added to the user name of the client connection to the server

 grant  all  on  *.*   to student@'%' identified by '123456';

6, in the 4.125: maxadmin -P4010 -uadmin -pmariadb // backstage access control

list servers    //显示所有服务器主机,可以看到服务器的运行信息

7, do the landing method middleware client connection with the host:

mysql -h192.168.4.125 -P4006 -utest -p123456

8, Test Method: When the hang up, the client may write readable;

 但是当主挂掉后,客户端不可读不可写

Guess you like

Origin blog.51cto.com/14421632/2415094