MaxScale Binlog Server实践

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介:

简介

Part1:写在最前

在之前的博文中有说到MaxScale,作为中间件,配合MHA使用或者主从使用可实现读写分离和负载均衡,今天简单介绍下MaxScale作为Binlog Server来减少主从延迟的问题;MySQL的主从架构中,链式拓扑的架构比较容易出现主从延迟的问题。本文着重介绍MaxScale作为Binlog Server是如何降低主从延迟的。


MaxScale配合MHA请移步至:

http://suifu.blog.51cto.com/9167728/1869520


Part2:本文环境

HE1:192.168.1.248 slave

HE3:192.168.1.250 master

HE4:192.168.1.251 maxscale



架构演示

wKiom1hBDgqiaSonAABgUFOcZ7o048.png


效果对比

wKioL1hH2fbhvd-3AABJo7D13KY463.png

实战

Part1:安装maxscale

[root@HE4 ~]# yum -y install maxscale-2.0.1-2.centos.6.x86_64.rpm

[root@HE4 ~]# mkdir -p /data/binlog

[root@HE4 ~]# useradd maxscale

[root@HE4 ~]# chown -R maxscale. /data/binlog

[root@HE4 ~]# cat /etc/maxscale.cnf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[maxscale]
threads=1
##根据CPU核数设置
[Replication]
type =service
router=binlogrouter
user=mysync
passwd =MANAGER
# 使用主库上的repl复制账号
# 权限:
#   GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'repl'@'%' IDENTIFIED BY   'repl';
router_options=server_id=1251,heartbeat=30,binlogdir= /data/binlog ,transaction_safety=1,mariadb10-compatibility=1,send_slave_heartbeat=1
# server_id设置maxscale的,记得不能与主和从库重复,要唯一
#   heartbeat=30秒,意思为当maxscale在30秒内没有接收到主库推送的binlog日志,发送心跳检查
#   binlogdir设置接收binlog的存放路径,目录属性chown -R maxscale.maxscale   /data/binlog
# transaction_safety=1此参数用于启用binlog日志中的不完整事务检测。   当MariaDB MaxScale启动时,如果当前binlog文件已损坏或找到不完整的事务,则可能会出现错误消息。   在正常工作期间,binlog事件不会分配到从库,直到事务已经提交。 默认值为off,设置transaction_safety = on以启用不完全事务检测。
#   send_slave_heartbeat=1开启心跳检查
[Replication   Listener]
type =listener
service=Replication
protocol=MySQLClient
port=5308
# 后端的从库CHANGE   MASTER TO这个端口,默认5308
[CLI]
type =service
router=cli
[CLI Listener]
type =listener
service=CLI
protocol=maxscaled
port=6603


Part2:启动Maxscale

[root@HE4 ~]# /etc/init.d/maxscale start

Starting MaxScale: maxscale (pid 16680) is running...      [  OK  ]

[root@HE4 ~]# /etc/init.d/maxscale status

Checking MaxScale status: MaxScale (pid  16680) is running.[  OK  ]


Part3:从库配置

1
2
3
4
5
6
7
8
9
10
11
[root@HE1 ~] # mysql -umysync -pMANAGER -h192.168.1.251 -P5308
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection  id  is 3196
Server version: 10.0.0 2.0.1-maxscale
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
MySQL [(none)]>  CHANGE MASTER TO MASTER_HOST= '192.168.1.250' ,MASTER_USER= 'mysync' ,MASTER_PASSWORD= 'MANAGER' ,MASTER_PORT=3306,MASTER_LOG_FILE= 'mysql-bin.000005' ,MASTER_LOG_POS=20;
ERROR 1234 (42000): Can not  set  MASTER_LOG_POS to 20: Permitted binlog pos is 4. Specified master_log_file=mysql-bin.000005
MySQL [(none)]>  CHANGE MASTER TO MASTER_HOST= '192.168.1.250' ,MASTER_USER= 'mysync' ,MASTER_PASSWORD= 'MANAGER' ,MASTER_PORT=3306,MASTER_LOG_FILE= 'mysql-bin.000005' ,MASTER_LOG_POS=4;
MySQL [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)

这里可以看出,Maxscale binlog server只能从位置4开始配置


配置好后,在/data/binlog下生成的binlog文件

[root@HE4 ~]# cd /data/binlog/

[root@HE4 binlog]# ls

cache  master.ini  mysql-bin.000003


Part4:主库配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@HE3 ~] # mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection  id  is 7
Server version: 10.1.16-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000005 |      652 |              |                  |
+------------------+----------+--------------+------------------+
1 row  in  set  (0.00 sec)
MariaDB [(none)]>  grant replication client,replication slave on *.* to  'mysync' @ '192.168.1.%'  identified by  'MANAGER' ;
MariaDB [(none)]>flush privileges;



Part5:主从配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
从库指向binlogserver
[root@HE1 ~] # mysql -uroot -pMANAGER
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection  id  is 5
Server version: 10.1.16-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST= '192.168.1.251' ,MASTER_USER= 'mysync' ,MASTER_PASSWORD= 'MANAGER' ,MASTER_PORT=5308,MASTER_LOG_FILE= 'mysql-bin.000005' ,MASTER_LOG_POS=652;
Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
                Slave_IO_State: Waiting  for  master to send event
                   Master_Host: 192.168.1.251
                   Master_User: mysync
                   Master_Port: 5308
                 Connect_Retry: 60
               Master_Log_File: mysql-bin.000005
           Read_Master_Log_Pos: 652
                Relay_Log_File: mysql-relay-bin.000002
                 Relay_Log_Pos: 537
         Relay_Master_Log_File: mysql-bin.000005
              Slave_IO_Running: Yes
             Slave_SQL_Running: Yes
               Replicate_Do_DB: 
           Replicate_Ignore_DB: 
            Replicate_Do_Table: 
        Replicate_Ignore_Table: 
       Replicate_Wild_Do_Table: 
   Replicate_Wild_Ignore_Table: 
                    Last_Errno: 0
                    Last_Error: 
                  Skip_Counter: 0
           Exec_Master_Log_Pos: 652
               Relay_Log_Space: 835
               Until_Condition: None
                Until_Log_File: 
                 Until_Log_Pos: 0
            Master_SSL_Allowed: No
            Master_SSL_CA_File: 
            Master_SSL_CA_Path: 
               Master_SSL_Cert: 
             Master_SSL_Cipher: 
                Master_SSL_Key: 
         Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                 Last_IO_Errno: 0
                 Last_IO_Error: 
                Last_SQL_Errno: 0
                Last_SQL_Error: 
   Replicate_Ignore_Server_Ids: 
              Master_Server_Id: 1250
                Master_SSL_Crl: 
            Master_SSL_Crlpath: 
                    Using_Gtid: No
                   Gtid_IO_Pos: 
       Replicate_Do_Domain_Ids: 
   Replicate_Ignore_Domain_Ids: 
                 Parallel_Mode: conservative
1 row  in  set  (0.00 sec)




——总结——

生产环境中,大多采用的是一主多从架构,例如星状拓扑和链式拓扑,星状拓扑在从库过多的情况下,会增加主库的io压力,而链式拓扑虽然缓解了主库的网络IO压力,但其缺点是:二级Slave得到最新的数据,需要再经过一层的复制才到达,期间的延迟比一主多从架构要大。而采用maxscale binlog server则避免了这类问题。由于者的水平有限,编写时间也很仓促,文中难免会出现一些错误或者不准确的地方,不妥之处恳请读者批评指正。



 本文转自 dbapower 51CTO博客,原文链接:http://blog.51cto.com/suifu/1878847,如需转载请自行联系原作者




相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
关系型数据库 MySQL Java
Flink作业报错:Caused by: The connector is trying to read binlog starting at GTIDs ..., but this is no longer available on the server
Flink作业报错:Caused by: The connector is trying to read binlog starting at GTIDs ..., but this is no longer available on the server
Flink作业报错:Caused by: The connector is trying to read binlog starting at GTIDs ..., but this is no longer available on the server
|
关系型数据库 MySQL
binlog server还是不靠谱吗?
1、背景 MySQL包含许多种日志,其中包括:redo log、undo log、error log、binlog等等,其中binlog是区别其他关系型数据库所独有的,也是MySQL中最重要的日志之一,其作用是用于主备复制、闪回、基于时间点恢复等等;本文基于公司产品需求,对比研究5.7版本下binlog server备份binlog的功能,以及该工具的优缺点。
936 0
|
监控 关系型数据库
|
监控 关系型数据库 大数据
|
3天前
|
存储 安全 关系型数据库
Mysql 的binlog日志的优缺点
MySQL的binlog(二进制日志)是一个记录数据库更改的日志文件,它包含了所有对数据库执行的更改操作,如INSERT、UPDATE和DELETE等。binlog的主要目的是复制和恢复。以下是binlog日志的优缺点: ### 优点: 1. **数据恢复**:当数据库出现意外故障或数据丢失时,可以利用binlog进行点恢复(point-in-time recovery),将数据恢复到某一特定时间点。 2. **主从复制**:binlog是实现MySQL主从复制功能的核心组件。主服务器将binlog中的事件发送到从服务器,从服务器再重放这些事件,从而实现数据的同步。 3. **审计**:b
|
3天前
|
SQL 关系型数据库 MySQL
mysql的binlog恢复数据
mysql的binlog恢复数据
33 0
|
3天前
|
存储 SQL 安全
浅谈MySQL Binlog
浅谈MySQL Binlog
48 0
|
3天前
|
SQL 存储 关系型数据库
解析MySQL Binlog:从零开始的入门指南【binlog入门指南】
解析MySQL Binlog:从零开始的入门指南【binlog入门指南】
1494 0
|
3天前
|
SQL 关系型数据库 MySQL
Mysql 的binlog日志的原理【4月更文挑战第1天】
【4月更文挑战第1天】 MySQL的binlog(二进制日志)是一个记录数据库更改的日志文件,它主要用于复制和恢复操作。以下是binlog日志的工作原理的简要概述: **事件写入**:当MySQL服务器执行一个事务时,它会将该事务中所有对数据库的修改操作(如INSERT、UPDATE和DELETE等)记录为一个事件(event)。这些事件包含了修改操作的相关信息,如操作类型、涉及的表、修改的行等。