开启组从同步
在所有的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