专职DBA-基于MHA高可用搭建MySQL读写分离架构-Atlas

专职DBA-基于MHA高可用搭建MySQL读写分离架构-Atlas

1.Atlas介绍

Atlas是由Qihoo360,Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目。
它是在mysql-proxy-0.8.2版本的基础上,对其进行了优化,增加了一些新的功能特性。
360内部使用Atlas运行的mysql业务,每天承载的读写请求数达几十亿条。
下载地址:https://github.com/Qihoo360/Atlas/releases
注意:
1.Atlas只能安装运行在64位的系统上。
2.版本
CentOS-5.x安装Atlas-xx.el5.x86_64.rpm
CentOS-6.x安装Atlas-xx.el6.x86_64.rpm
3.后端mysql版本应大于5.1,建议使用mysql-5.6以上。

2.安装配置
[[email protected] ~]# wget https://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm
[[email protected] ~]# wget https://github.com/Qihoo360/Atlas/releases/download/sharding-1.0.1/Atlas-sharding_1.0.1-el6.x86_64.rpm

[[email protected] ~]# ps -ef | grep masterha
root      8560  6706  0 19:40 pts/0    00:00:00 perl /usr/bin/masterha_manager --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.conf
root      8647  6706  0 19:42 pts/0    00:00:00 grep --color=auto masterha

[[email protected] ~]# masterha_check_status --conf=/etc/masterha/app1.conf
app1 (pid:8560) is running(0:PING_OK), master:10.0.0.11

[[email protected] ~]# masterha_check_repl --global_conf=/etc/masterha/masterha_default.conf --conf=/etc/masterha/app1.conf
Fri Jul 26 19:43:16 2019 - [info] Reading default configuration from /etc/masterha/masterha_default.conf..
Fri Jul 26 19:43:16 2019 - [info] Reading application default configuration from /etc/masterha/app1.conf..
Fri Jul 26 19:43:16 2019 - [info] Reading server configuration from /etc/masterha/app1.conf..
Fri Jul 26 19:43:16 2019 - [info] MHA::MasterMonitor version 0.58.
Fri Jul 26 19:43:18 2019 - [info] GTID failover mode = 1
Fri Jul 26 19:43:18 2019 - [info] Dead Servers:
Fri Jul 26 19:43:18 2019 - [info] Alive Servers:
Fri Jul 26 19:43:18 2019 - [info]   10.0.0.11(10.0.0.11:3306)
Fri Jul 26 19:43:18 2019 - [info]   10.0.0.12(10.0.0.12:3306)
Fri Jul 26 19:43:18 2019 - [info]   10.0.0.13(10.0.0.13:3306)
Fri Jul 26 19:43:18 2019 - [info] Alive Slaves:
Fri Jul 26 19:43:18 2019 - [info]   10.0.0.12(10.0.0.12:3306)  Version=5.7.26-log (oldest major version between slaves) log-bin:enabled
Fri Jul 26 19:43:18 2019 - [info]     GTID ON
Fri Jul 26 19:43:18 2019 - [info]     Replicating from 10.0.0.11(10.0.0.11:3306)
Fri Jul 26 19:43:18 2019 - [info]     Primary candidate for the new Master (candidate_master is set)
Fri Jul 26 19:43:18 2019 - [info]   10.0.0.13(10.0.0.13:3306)  Version=5.7.26-log (oldest major version between slaves) log-bin:enabled
Fri Jul 26 19:43:18 2019 - [info]     GTID ON
Fri Jul 26 19:43:18 2019 - [info]     Replicating from 10.0.0.11(10.0.0.11:3306)
Fri Jul 26 19:43:18 2019 - [info]     Primary candidate for the new Master (candidate_master is set)
Fri Jul 26 19:43:18 2019 - [info] Current Alive Master: 10.0.0.11(10.0.0.11:3306)
Fri Jul 26 19:43:18 2019 - [info] Checking slave configurations..
Fri Jul 26 19:43:18 2019 - [info]  read_only=1 is not set on slave 10.0.0.12(10.0.0.12:3306).
Fri Jul 26 19:43:18 2019 - [info]  read_only=1 is not set on slave 10.0.0.13(10.0.0.13:3306).
Fri Jul 26 19:43:18 2019 - [info] Checking replication filtering settings..
Fri Jul 26 19:43:18 2019 - [info]  binlog_do_db= , binlog_ignore_db=
Fri Jul 26 19:43:18 2019 - [info]  Replication filtering check ok.
Fri Jul 26 19:43:18 2019 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Fri Jul 26 19:43:18 2019 - [info] Checking SSH publickey authentication settings on the current master..
Fri Jul 26 19:43:18 2019 - [info] HealthCheck: SSH to 10.0.0.11 is reachable.
Fri Jul 26 19:43:18 2019 - [info]
10.0.0.11(10.0.0.11:3306) (current master)
 +--10.0.0.12(10.0.0.12:3306)
 +--10.0.0.13(10.0.0.13:3306)

Fri Jul 26 19:43:18 2019 - [info] Checking replication health on 10.0.0.12..
Fri Jul 26 19:43:18 2019 - [info]  ok.
Fri Jul 26 19:43:18 2019 - [info] Checking replication health on 10.0.0.13..
Fri Jul 26 19:43:18 2019 - [info]  ok.
Fri Jul 26 19:43:18 2019 - [info] Checking master_ip_failover_script status:
Fri Jul 26 19:43:18 2019 - [info]   /etc/masterha/master_ip_failover --command=status --ssh_user=root --orig_master_host=10.0.0.11 --orig_master_ip=10.0.0.11 --orig_master_port=3306
Fri Jul 26 19:43:18 2019 - [info]  OK.
Fri Jul 26 19:43:18 2019 - [warning] shutdown_script is not defined.
Fri Jul 26 19:43:18 2019 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

[[email protected] ~]# ip addr show bond0
6: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:a1:4c:f7 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.11/24 brd 10.0.0.255 scope global bond0
       valid_lft forever preferred_lft forever
    inet 10.0.0.15/32 scope global bond0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fea1:4cf7/64 scope link
       valid_lft forever preferred_lft forever

[[email protected] ~]# rpm -ivh Atlas-2.2.1.el6.x86_64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:Atlas-2.2.1-1                    ################################# [100%]

[[email protected] ~]# cd /usr/local/mysql-proxy/conf/
[[email protected] /usr/local/mysql-proxy/conf]# ls -l
total 4
-rw-r--r-- 1 root root 2810 Dec 17  2014 test.cnf
[[email protected] /usr/local/mysql-proxy/conf]# mv test.cnf test.cnf.bak

看一下默认配置文件
[[email protected] /usr/local/mysql-proxy/conf]# cat test.cnf.bak
[mysql-proxy]

#带#号的为非必需的配置项目

#管理接口的用户名
admin-username = user

#管理接口的密码
admin-password = pwd

#Atlas后端连接的MySQL主库的IP和端口,可设置多项,用逗号分隔
proxy-backend-addresses = 127.0.0.1:3306

#Atlas后端连接的MySQL从库的IP和端口,@后面的数字代表权重,用来作负载均衡,若省略则默认为1,可设置多项,用逗号分隔
#proxy-read-only-backend-addresses = 127.0.0.1:3305@1

#用户名与其对应的加密过的MySQL密码,密码使用PREFIX/bin目录下的加密程序encrypt加密,下行的user1和user2为示例,将其替换为你的MySQL的用户名和加密密码!
pwds = user1:+jKsgB3YAG8=, user2:GS+tr4TPgqc=

#设置Atlas的运行方式,设为true时为守护进程方式,设为false时为前台方式,一般开发调试时设为false,线上运行时设为true,true后面不能有空格。
daemon = true

#设置Atlas的运行方式,设为true时Atlas会启动两个进程,一个为monitor,一个为worker,monitor在worker意外退出后会自动将其重启,设为false时只有worker,没有monitor,一般开发调试时设为false,线上运行时设为true,true后面不能有空格。
keepalive = true

#工作线程数,对Atlas的性能有很大影响,可根据情况适当设置
event-threads = 8

#日志级别,分为message、warning、critical、error、debug五个级别
log-level = message

#日志存放的路径
log-path = /usr/local/mysql-proxy/log

#SQL日志的开关,可设置为OFF、ON、REALTIME,OFF代表不记录SQL日志,ON代表记录SQL日志,REALTIME代表记录SQL日志且实时写入磁盘,默认为OFF
#sql-log = OFF

#慢日志输出设置。当设置了该参数时,则日志只输出执行时间超过sql-log-slow(单位:ms)的日志记录。不设置该参数则输出全部日志。
#sql-log-slow = 10

#实例名称,用于同一台机器上多个Atlas实例间的区分
#instance = test

#Atlas监听的工作接口IP和端口
proxy-address = 0.0.0.0:1234

#Atlas监听的管理接口IP和端口
admin-address = 0.0.0.0:2345

#分表设置,此例中person为库名,mt为表名,id为分表字段,3为子表数量,可设置多项,以逗号分隔,若不分表则不需要设置该项
#tables = person.mt.id.3

#默认字符集,设置该项后客户端不再需要执行SET NAMES语句
#charset = utf8

#允许连接Atlas的客户端的IP,可以是精确IP,也可以是IP段,以逗号分隔,若不设置该项则允许所有IP连接,否则只允许列表中的IP连接
#client-ips = 127.0.0.1, 192.168.1

#Atlas前面挂接的LVS的物理网卡的IP(注意不是虚IP),若有LVS且设置了client-ips则此项必须设置,否则可以不设置
#lvs-ips = 192.168.1.1

制作加密密码
因为我的repl账户和mha账户密码都是123
[[email protected] ~]# /usr/local/mysql-proxy/bin/encrypt 123
3yb5jEku5h4=

[[email protected] /usr/local/mysql-proxy/conf]# vim test.cnf
[mysql-proxy]
admin-username = user
admin-password = pwd
proxy-backend-addresses = 10.0.0.15:3306
proxy-read-only-backend-addresses = 10.0.0.12:3306,10.0.0.13:3306
pwds = repl:3yb5jEku5h4=,mha:3yb5jEku5h4=
daemon = true
keepalive = true
event-threads = 8
log-level = message
log-path = /usr/local/mysql-proxy/log
sql-log=ON
proxy-address = 0.0.0.0:33060
admin-address = 0.0.0.0:2345
charset=utf8

[[email protected] ~]# /usr/local/mysql-proxy/bin/mysql-proxyd test start
OK: MySQL-Proxy of test is started

[[email protected] ~]# ps -ef | grep proxy
root      9246     1  0 19:58 ?        00:00:00 /usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/usr/local/mysql-proxy/conf/test.cnf
root      9247  9246  0 19:58 ?        00:00:00 /usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/usr/local/mysql-proxy/conf/test.cnf
root      9271  6706  0 19:58 pts/0    00:00:00 grep --color=auto proxy

[[email protected] ~]# ss -tunlp | grep proxy
tcp    LISTEN     0      128       *:2345                  *:*                   users:(("mysql-proxy",pid=9247,fd=9))
tcp    LISTEN     0      128       *:33060                 *:*                   users:(("mysql-proxy",pid=9247,fd=10))

[[email protected] ~]# netstat -tunlp | grep proxy
tcp        0      0 0.0.0.0:2345            0.0.0.0:*               LISTEN      9247/mysql-proxy
tcp        0      0 0.0.0.0:33060           0.0.0.0:*               LISTEN      9247/mysql-proxy

3.Atlas功能测试
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\zhouwanchun>mysql -umha -p -h 10.0.0.14 -P33060
Enter password: ***
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.81-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql>

(1).测试读操作
mysql> select @@server_id;
+-------------+
| @@server_id |
+-------------+
|      123306 |
+-------------+
1 row in set (0.01 sec)

mysql> select @@server_id;
+-------------+
| @@server_id |
+-------------+
|      133306 |
+-------------+
1 row in set (0.00 sec)

mysql> select @@server_id;
+-------------+
| @@server_id |
+-------------+
|      123306 |
+-------------+
1 row in set (0.00 sec)

mysql> select @@server_id;
+-------------+
| @@server_id |
+-------------+
|      133306 |
+-------------+
1 row in set (0.00 sec)

(2).测试写操作
mysql> begin;select @@server_id;commit;
Query OK, 0 rows affected (0.01 sec)

+-------------+
| @@server_id |
+-------------+
|      113306 |
+-------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

C:\Users\zhouwanchun>

4.生产用户要求
开发人员申请一个应用:
用户:app(insert,update,select)
密码:123
要通过10.0.0.% 网段登录

(1).在主库中创建用户app
[[email protected] ~]# mysql -S /data/mysql/3306/mysql.sock -p
Enter password:

db01 [(none)]> create user ‘app‘@‘10.0.0.%‘ identified by ‘123‘;
Query OK, 0 rows affected (0.01 sec)

db01 [(none)]> grant insert,update,select on *.* to ‘app‘@‘10.0.0.%‘;
Query OK, 0 rows affected (0.01 sec)

db01 [(none)]> show grants for ‘app‘@‘10.0.0.%‘;
+---------------------------------------------------------+
| Grants for app@10.0.0.%                                 |
+---------------------------------------------------------+
| GRANT SELECT, INSERT, UPDATE ON *.* TO ‘app‘@‘10.0.0.%‘ |
+---------------------------------------------------------+
1 row in set (0.00 sec)

(2).在Atlas中添加生产用户
[[email protected] ~]# /usr/local/mysql-proxy/bin/encrypt 123
3yb5jEku5h4=

[[email protected] ~]# cd /usr/local/mysql-proxy/conf/
[[email protected] /usr/local/mysql-proxy/conf]# vim test.cnf
pwds = repl:3yb5jEku5h4=,mha:3yb5jEku5h4=,app:3yb5jEku5h4=

[[email protected] ~]# /usr/local/mysql-proxy/bin/mysql-proxyd test restart
OK: MySQL-Proxy of test is stopped
OK: MySQL-Proxy of test is started

Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。

C:\Users\zhouwanchun>mysql -uapp -p -h 10.0.0.14 -P33060
Enter password: ***
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.81-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql> exit;
Bye

5.Atlas基本管理
连接管理接口
基于密钥连接服务器db04
# ssh root@10.0.0.14

[[email protected] ~]# mysql -uuser -ppwd -h 127.0.0.1 -P2345
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.99-agent-admin

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

db04 [(none)]>

打印帮助
db04 [(none)]> select * from help;
+----------------------------+---------------------------------------------------------+
| command                    | description                                             |
+----------------------------+---------------------------------------------------------+
| SELECT * FROM help         | shows this help                                         |
| SELECT * FROM backends     | lists the backends and their state                      |
| SET OFFLINE $backend_id    | offline backend server, $backend_id is backend_ndx‘s id |
| SET ONLINE $backend_id     | online backend server, ...                              |
| ADD MASTER $backend        | example: "add master 127.0.0.1:3306", ...               |
| ADD SLAVE $backend         | example: "add slave 127.0.0.1:3306", ...                |
| REMOVE BACKEND $backend_id | example: "remove backend 1", ...                        |
| SELECT * FROM clients      | lists the clients                                       |
| ADD CLIENT $client         | example: "add client 192.168.1.2", ...                  |
| REMOVE CLIENT $client      | example: "remove client 192.168.1.2", ...               |
| SELECT * FROM pwds         | lists the pwds                                          |
| ADD PWD $pwd               | example: "add pwd user:raw_password", ...               |
| ADD ENPWD $pwd             | example: "add enpwd user:encrypted_password", ...       |
| REMOVE PWD $pwd            | example: "remove pwd user", ...                         |
| SAVE CONFIG                | save the backends to config file                        |
| SELECT VERSION             | display the version of Atlas                            |
+----------------------------+---------------------------------------------------------+
16 rows in set (0.00 sec)

查询后端所有节点信息
db04 [(none)]> select * from backends;
+-------------+----------------+-------+------+
| backend_ndx | address        | state | type |
+-------------+----------------+-------+------+
|           1 | 10.0.0.15:3306 | up    | rw   |
|           2 | 10.0.0.12:3306 | up    | ro   |
|           3 | 10.0.0.13:3306 | up    | ro   |
+-------------+----------------+-------+------+
3 rows in set (0.00 sec)

动态删除节点
db04 [(none)]> remove backend 3;
Empty set (0.00 sec)

保存配置到配置文件
db04 [(none)]> save config;
Empty set (0.01 sec)

db04 [(none)]> select * from backends;
+-------------+----------------+-------+------+
| backend_ndx | address        | state | type |
+-------------+----------------+-------+------+
|           1 | 10.0.0.15:3306 | up    | rw   |
|           2 | 10.0.0.12:3306 | up    | ro   |
+-------------+----------------+-------+------+
2 rows in set (0.00 sec)

[[email protected] ~]# cd /usr/local/mysql-proxy/conf/
[[email protected] /usr/local/mysql-proxy/conf]# grep "addresses" test.cnf
proxy-backend-addresses=10.0.0.15:3306
proxy-read-only-backend-addresses=10.0.0.12:3306

动态添加节点
db04 [(none)]> add slave 10.0.0.13:3306;
Empty set (0.00 sec)

db04 [(none)]> save config;
Empty set (0.00 sec)

db04 [(none)]> select * from backends;
+-------------+----------------+-------+------+
| backend_ndx | address        | state | type |
+-------------+----------------+-------+------+
|           1 | 10.0.0.15:3306 | up    | rw   |
|           2 | 10.0.0.12:3306 | up    | ro   |
|           3 | 10.0.0.13:3306 | up    | ro   |
+-------------+----------------+-------+------+
3 rows in set (0.00 sec)

[[email protected] /usr/local/mysql-proxy/conf]# grep "addresses" test.cnf
proxy-backend-addresses=10.0.0.15:3306
proxy-read-only-backend-addresses=10.0.0.12:3306,10.0.0.13:3306

6.自动分表
使用Atlas的分表功能时,首先需要在配置文件test.cnf设置tables参数。
tables参数设置格式:数据库名.表名.分表字段.子表数量
比如:
你的数据库名叫china,表名叫city,分表字段叫id,总共分为2张表。
那么就写为china.city.id.2
如果还有其他的分表,以逗号分隔即可。

7.关于读写分离建议
MySQL-Router ---》MySQL官方
ProxySQL -------》Percona
Maxscale -------》MariaDB

原文地址:https://www.cnblogs.com/zhouwanchun/p/11249584.html

时间: 2024-11-09 03:50:41

专职DBA-基于MHA高可用搭建MySQL读写分离架构-Atlas的相关文章

[记录]MySQL读写分离(Atlas和MySQL-proxy)

MySQL读写分离(Atlas和MySQL-proxy) 一.阿里云使用Atlas从外网访问MySQL(RDS) (同样的方式修改配置文件可以实现代理也可以实现读写分离,具体看使用场景) 1.在跳板机上使用Atals中转访问RDS不会影响效率,不要认为使用Atals后连接数据库会慢,连接数会疯狂占用,事实情况是刚好相反. Atlas不处理主从数据库数据同步,只是个负载均衡的连接池工具,主从同步请使用其他工具另行实现,本文只为了外网访问RDS(流量免费),实现连接池,有效利用RDS连接数. Atl

mysql+proxysql+keepalived实现高可用的数据库读写分离

前言 为了降低一台数据库的IO,远程连接数据库的时候,可以实现读写分离进行调度.这里就出现了一个单点,所以必须要做一个高可用.当然数据库服务器也需要做主从复制. 实验结构 说明:上图的拓扑只是整个架构中的一个小部分,其余功能的实现此图并未规划出来.此拓扑实现的目的是利用proxysql实现数据读写分离,并对proxysql高可用.两台安装了Keepalived和proxysql虚拟成一个VIP对外提供服务.这两台mysql服务器做的半同步复制,192.168.32.111是主节点负责用户的写操作

mysql读写分离中间件atlas的性能测试

公司最近要对上读写分离的中间件,打算对现下比较流行的中间件逐一进行性能测试.首先测试的是atlas. 此次测试分为两个部分,(1)atlas与直连db的性能比对,(2)event-threads参数对atlas性能的影响 一,简介 Atlas是由 Qihoo 360公司Web平台部基础架构团队开发维护的一个基于MySQL协议的数据中间层项目.它在MySQL官方推出的MySQL-Proxy 0.8.2版本的基础上,修改了大量bug,添加了很多功能特性. 主要功能: 1.读写分离 2.从库负载均衡

mysql+mha高可用搭建

主库:172.25.254.125 备库:172.25.254.225 管理节点:172.25.254.126 在开始之前,请先配置好服务器间的时间同步和名称解析 一:在数据库节点安装mha node [[email protected] ~]# rpm -ivh epel-release-5-4.noarch.rpm Retrieving epel-release-5-4.noarch.rpm warning: /var/tmp/rpm-xfer.yqwfYT: Header V3 DSA s

高性能高可用Mysql读写分离架构设计

https://ke.qq.com/webcourse/index.html#course_id=235439&term_id=100277631&taid=2034508828481455&vid=n1425370i9r 原文地址:https://www.cnblogs.com/cxxjohnson/p/9151958.html

MySQL读写分离架构(KHPM)

Keepalived HAProxy ProxySQL MySQL Keepalived+HAProxy 应用程序入口无单点故障ProxySQL Cluster ProxySQL无单点故障MHA MySQL无单点故障(MHA Manager后续用ORCH RAFT代替,实现无单点故障) 原文地址:https://blog.51cto.com/aimax/2430628

Consul, ProxySQL and MySQL MHA(mysql 读写分离,高可用)

背景:mysql 官方目前没有提供比较成熟,稳定的高可用的方案,使得Mysql的高可用方案相对较少,一般都只有简单的主从,今天和大家分享一个Consul, ProxySQL and MySQL MHA架构的高可用方案: 架构特性:1,高可用2,读写分离,查询路由3,sql过滤等功能 Installation of Consul:Firstly, we'll need to install the required packages, download the Consul archive and

Atlas+keepalived实现mysql读写分离

本文主要介绍atlas安装.mysql读写分离的配置.mysql主从配置及利用keepalived解决atlas单点故障. Atlas介绍 Atlas是基于mysql-proxy做的二次开发.Atlas是一个位于应用程序与MySQL之间中间件.在后端DB看来,Atlas相当于连接它的客户端,在前端应用看来,Atlas相当于一个DB.Atlas作为服务端与应用程序通讯,它实现了MySQL的客户端和服务端协议,同时作为客户端与MySQL通讯.它对应用程序屏蔽了DB的细节,同时为了降低MySQL负担,

详解MySQL读写分离

主从复制的原理MySQL的主从复制和读写分离两者有着紧密的联系,首先要部署主从复制,只有主从复制完成了才能在此基础上进行数据的读写分离. 读写分离的原理简单来说,读写分离就是只在主服务器上写,只在从服务器上读.基本原理是让主数据库处理事务性查询,而从服务器处理select查询.数据库复制被用来把事务性查询导致的变更同步到从数据库中. 基于中间代理层实现:代理一般位于客户端和服务器之间,代理服务器接到客户段的请求通过判断后转发到后端数据库. 实验环境1 一台centos7作为客户端测试IP为192