MySQL高可用搭建方案之(MMM)(二)

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介: MySQL高可用搭建方案之(MMM)(二)
开启组从同步

在所有的slave上面执行如下命令,此时的binlog文件和日志点的位置,可以在master1上面使用show master status

命令查看,或者查看导出数据的时候,生成的.sql

文件。在master1节点上执行mysqldump

导出命令的时候,我们指定的--master-data=2

,这个参数会在导出的.sql

文件中标记当前master1节点上binlog日志的文件名称和日志偏移量。

change master to master_host='172.20.0.11', master_user='repl_user', master_password='repl_user',
MASTER\_LOG\_FILE='mysql-bin.000003', MASTER\_LOG\_POS=1034;

开启组从同步:

start slave;

查看同步状态:

mysql> show slave status\\G  
*************************** 1. row ***************************  
Slave\_IO\_State: Waiting for master to send event  
Master_Host: 172.20.0.11  
Master\_User: repl\_user  
Master_Port: 3306  
Connect_Retry: 60  
Master\_Log\_File: mysql-bin.000003  
Read\_Master\_Log_Pos: 1034  
Relay\_Log\_File: mysql-relay.000002  
Relay\_Log\_Pos: 320  
Relay\_Master\_Log_File: mysql-bin.000003  
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: 1034  
Relay\_Log\_Space: 523  
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: 11  
Master_UUID: 047bcc07-7424-11eb-96b4-0242ac14000b  
Master\_Info\_File: mysql.slave\_master\_info  
SQL_Delay: 0  
SQL\_Remaining\_Delay: NULL  
Slave\_SQL\_Running_State: Slave has read all relay log; waiting for more updates  
Master\_Retry\_Count: 86400  
Master_Bind:  
Last\_IO\_Error_Timestamp:  
Last\_SQL\_Error_Timestamp:  
Master\_SSL\_Crl:  
Master\_SSL\_Crlpath:  
Retrieved\_Gtid\_Set:  
Executed\_Gtid\_Set:  
Auto_Position: 0  
Replicate\_Rewrite\_DB:  
Channel_Name:  
Master\_TLS\_Version:  
1 row in set (0.00 sec)
mysql>
配置主与主的同步

上面我们配置好了master1->slave1,master1->slave2

的同步。我们还需要在master1和master2直接配置互相同步对方。

现在master2上面配置master1作为它的主库。参考上面slave1和slave2上面的配置。执行如下命令:

change master to master_host='172.20.0.11', MASTER\_LOG\_FILE='mysql-bin.000003', MASTER\_LOG\_POS=1034;
start slave user='repl_user' password='repl_user';
show slave status\\G

然后再配置master2到master1的同步。此时我们需要查看一下master2上面的binlog日志名称和日志偏移量是多少。使用如下命令查看:

mysql> show master status\\G  
*************************** 1. row ***************************  
File: mysql-bin.000003  
Position: 623  
Binlog\_Do\_DB:  
Binlog\_Ignore\_DB:  
Executed\_Gtid\_Set:  
1 row in set (0.00 sec)
mysql>

然后我们登录到master1上面,执行如下命令,配置master2作为master1的主库。

change master to master_host='172.20.0.21', MASTER\_LOG\_FILE='mysql-bin.000003', MASTER\_LOG\_POS=623;
start slave user='repl_user' password='repl_user';
show slave status\\G

验证双主双从同步的效果如下:

安装MMM

修改apt-get源

在下载MMM之前,我们先修改一下apt-get

源,然后更新一下apt-get

源。如下所示,因为此时的容器中,没有vim

命令,所以我们使用echo "xxx" >/etc/apt/sources.list

的方式去更新apt-get

的源。

echo "  
deb http://mirrors.aliyun.com/debian/ buster main non-free contrib  
deb http://mirrors.aliyun.com/debian-security buster/updates main  
deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib  
deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian-security buster/updates main  
deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib  
deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib  
deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib  
" > etc/apt/sources.list
• 1

注意,在更新镜像源的时候,要根据自己的Debian系统的版本,我的Debian系统的版本是buster

版本,所以你要根据自己的系统版本网上找到对应的镜像地址。接着,我们更新一下系统。

root@master1:/etc/apt# apt-get update  
Get:1 http://security.debian.org/debian-security buster/updates InRelease \[65.4 kB\]  
Get:2 http://repo.mysql.com/apt/debian buster InRelease \[21.5 kB\]  
Get:3 http://mirrors.ustc.edu.cn/debian buster InRelease \[122 kB\]  
Get:4 http://security.debian.org/debian-security buster/updates/main amd64 Packages \[267 kB\]  
Get:5 http://mirrors.ustc.edu.cn/debian buster-updates InRelease \[51.9 kB\]  
Get:6 http://mirrors.ustc.edu.cn/debian buster/main amd64 Packages \[7907 kB\]  
Get:7 http://repo.mysql.com/apt/debian buster/mysql-5.7 amd64 Packages \[5693 B\]  
Get:8 http://mirrors.ustc.edu.cn/debian buster-updates/main amd64 Packages \[9504 B\]  
Fetched 8450 kB in 10s (871 kB/s)  
Reading package lists... Done  
root@master1:/etc/apt#

更新完成之后,我们先安装一下我们经常用到的几个命令:

apt-get install net-tools wget vim make cmake inetutils-ping iproute2 iproute2-doc -y
下载MMM

推荐使用源码来安装,这样可以在任何Linux系统版本上面进行安装,例如:Ubuntu、Debian、CentOS、Redhat等等。不用因为系统版本的问题找对应的rpm

包,找对应的deb

包。

通过如下步骤来获取MMM的源码。

登录Debian的官方网站:https://www.debin.org,然后点击跟多关于下载与软件介绍的连接。

此时我们会进入如下页面:https://www.debian.org/intro/index#software,然后点击软件包连接。

接着,我们会进入如下页面:https://www.debian.org/distrib/packages#search_packages,根据选项输入mysql-mmm

,点击搜索按钮。

点击上面的搜索按钮后,进入如下页面:https://packages.debian.org/search?keywords=mysql-mmm&searchon=names&suite=oldstable§ion=all,然后我们点击页面中的Debian系统的版本,选择jessie

版本,因为mysql-mmm

是比较老的一种MySQL考可用架构,在最新的Debian系统中,已经没有这样的软件包了,所以我们选择老版本的jessie

版本,这个版本中包含mysql-mmm

的源码。

点击完成jessie

之后,进入如下页面:https://packages.debian.org/search?suite=jessie&searchon=names&keywords=mysql-mmm,此时我们已经搜索到了mysql-mmm

的软件。点击其中任何一个链接,进入详细页面。

进入如下的页面:https://packages.debian.org/jessie/mysql-mmm-tools,我们选择下载源码文件。

或者我们可以右键复制下载地址:http://deb.debian.org/debian/pool/main/m/mysql-mmm/mysql-mmm_2.2.1.orig.tar.gz,使用wget命令下载源码到MySQL服务器上。

wget http://deb.debian.org/debian/pool/main/m/mysql-mmm/mysql-mmm_2.2.1.orig.tar.gz

如果要下载.deb文件,可以点击上面图片中的硬件架构下面的all

连接,进入下面页面后,选择对应的距离我们最近镜像地址,我选择的为ftp.cn.debian.org

这个镜像地址,然后复制下载链接地址,使用wget下载即可。这里贴出如下的下载示例:

wget http://ftp.cn.debian.org/debian/pool/main/m/mysql-mmm/mysql-mmm-tools\_2.2.1-1.1\_all.deb  
wget http://ftp.cn.debian.org/debian/pool/main/m/mysql-mmm/mysql-mmm-monitor\_2.2.1-1.1\_all.deb  
wget http://ftp.cn.debian.org/debian/pool/main/m/mysql-mmm/mysql-mmm-common\_2.2.1-1.1\_all.deb  
wget http://ftp.cn.debian.org/debian/pool/main/m/mysql-mmm/mysql-mmm-agent\_2.2.1-1.1\_all.deb

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
2月前
|
存储 关系型数据库 MySQL
Mysql高可用|索引|事务 | 调优
Mysql高可用|索引|事务 | 调优
|
3月前
|
SQL 容灾 关系型数据库
rds容灾与高可用
rds容灾与高可用
30 4
|
3月前
|
关系型数据库 MySQL
电子好书发您分享《MySQL MGR 8.0高可用实战》
电子好书发您分享《MySQL MGR 8.0高可用实战》 电子好书发您分享《MySQL MGR 8.0高可用实战》
92 1
|
2月前
|
SQL 存储 关系型数据库
MySQL索引(二)索引优化方案有哪些
MySQL索引(二)索引优化方案有哪些
52 0
|
20天前
|
存储 SQL 分布式计算
搭建Mysql Cluster集群实现高可用
搭建Mysql Cluster集群实现高可用
18 0
|
1月前
|
canal 消息中间件 关系型数据库
【分布式技术专题】「分布式技术架构」MySQL数据同步到Elasticsearch之N种方案解析,实现高效数据同步
【分布式技术专题】「分布式技术架构」MySQL数据同步到Elasticsearch之N种方案解析,实现高效数据同步
89 0
|
1月前
|
SQL 关系型数据库 MySQL
【MySQL技术之旅】(7)总结和盘点优化方案系列之常用SQL的优化
【MySQL技术之旅】(7)总结和盘点优化方案系列之常用SQL的优化
71 1
|
1月前
|
缓存 关系型数据库 MySQL
史上最全MySQL 大表优化方案(长文)
史上最全MySQL 大表优化方案(长文)
536 0
|
2月前
|
监控 容灾 关系型数据库
rds容灾与高可用
rds容灾与高可用
56 6
|
3月前
|
SQL 关系型数据库 MySQL
Mysql高可用,索引,事务与调优:提高数据库性能的关键技术
在当今互联网时代,高可用性、稳定性和性能是数据库的三大关键要素。本文将深入探讨Mysql高可用、索引、事务和调优等方面的技术,为读者提供实用的解决方案和经验。
24 0