在上一片博客中,讲述了怎么去配置MHA架构!这片博客不再细说,只说明其中MySQL主从搭建,这里使用的是gtid加上半同步复制!
上一片博客中,把MySQL主从的搭建由filename和pos的过程改变为如下的基于gtid的过程就可以,因此不再详细说明,只展示gtid的搭建!
四台服务器分配如下:
MHA管理节点: 10.0.102.214
MySQL主节点: 10.0.102.204
MySQL从节点1: 10.0.102.179 【这个节点可以作为备用的主】
MySQL从节点2: 10.0.102.221
搭建基于gtid的数据库复制!
第一步:保证三个服务器的数据是一致的【处于一致的状态】
第二步:在主上和备用的主上创建复制账户,用户名和密码要保持一致!
第三步:开启gtid,加载半同步复制的插件!
三台服务器中配置文件加入以下参照:
plugin_dir=/usr/local/mysql/lib/plugin/ #因为这里MySQL5.7是源码安装的位置,若是使用rpm包安装,则注意更改位置plugin_load=semisync_master.so #这两个插件尽量在每个服务器都安装吧
plugin_load=semisync_slave.so
gtid-mode=on #开启gtid
enforce-gtid-consistency #确保gtid全局的一致性
log-bin=character_set_server=utf8 #设置字符集
log_slave_updates #gtid复制时,一定要开启
设置完配置文件之后,重启服务器,然后再从上执行以下命令!
mysql> change master to master_host="10.0.102.204", master_user="repl",master_password="123456",master_auto_position = 1;
Query OK,0 rows affected, 2 warnings (0.09sec)
mysql>start slave;
Query OK,0 rows affected (0.01 sec)
若上面没有报错,则使用show slave status查看复制的状态!
检查MHA的状态
ssh状态检查:
[root@test3 ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf
Sun Dec 9 11:42:50 2018 - [warning] Global configuration file /etc/masterha_default.cnf notfound. Skipping.
SunDec 9 11:42:50 2018 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
SunDec 9 11:42:50 2018 - [info] Reading server configuration from /etc/masterha/app1.cnf..
SunDec 9 11:42:50 2018 - [info]Starting SSH connection tests..
SunDec 9 11:42:51 2018 - [debug]SunDec 9 11:42:50 2018 - [debug] Connecting via SSH from root@10.0.102.204(10.0.102.204:22) to root@10.0.102.179(10.0.102.179:22)..
SunDec 9 11:42:51 2018 - [debug]ok.
SunDec 9 11:42:51 2018 - [debug] Connecting via SSH from root@10.0.102.204(10.0.102.204:22) to root@10.0.102.221(10.0.102.221:22)..
SunDec 9 11:42:51 2018 - [debug]ok.
SunDec 9 11:42:51 2018 - [debug]SunDec 9 11:42:51 2018 - [debug] Connecting via SSH from root@10.0.102.179(10.0.102.179:22) to root@10.0.102.204(10.0.102.204:22)..
SunDec 9 11:42:51 2018 - [debug]ok.
SunDec 9 11:42:51 2018 - [debug] Connecting via SSH from root@10.0.102.179(10.0.102.179:22) to root@10.0.102.221(10.0.102.221:22)..
SunDec 9 11:42:51 2018 - [debug]ok.
SunDec 9 11:42:52 2018 - [debug]SunDec 9 11:42:51 2018 - [debug] Connecting via SSH from root@10.0.102.221(10.0.102.221:22) to root@10.0.102.204(10.0.102.204:22)..
SunDec 9 11:42:52 2018 - [debug]ok.
SunDec 9 11:42:52 2018 - [debug] Connecting via SSH from root@10.0.102.221(10.0.102.221:22) to root@10.0.102.179(10.0.102.179:22)..
SunDec 9 11:42:52 2018 - [debug]ok.
SunDec 9 11:42:52 2018 - [info] All SSH connection tests passed successfully.
masterha_check_ssh --conf=/etc/masterha/app1.cnf
[root@test3 ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf
Sun Dec 9 11:42:50 2018 - [warning] Global configuration file /etc/masterha_default.cnf notfound. Skipping.
SunDec 9 11:42:50 2018 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
SunDec 9 11:42:50 2018 - [info] Reading server configuration from /etc/masterha/app1.cnf..
SunDec 9 11:42:50 2018 - [info]Starting SSH connection tests..
SunDec 9 11:42:51 2018 - [debug]SunDec 9 11:42:50 2018 - [debug] Connecting via SSH from root@10.0.102.204(10.0.102.204:22) to root@10.0.102.179(10.0.102.179:22)..
SunDec 9 11:42:51 2018 - [debug]ok.
SunDec 9 11:42:51 2018 - [debug] Connecting via SSH from root@10.0.102.204(10.0.102.204:22) to root@10.0.102.221(10.0.102.221:22)..
SunDec 9 11:42:51 2018 - [debug]ok.
SunDec 9 11:42:51 2018 - [debug]SunDec 9 11:42:51 2018 - [debug] Connecting via SSH from root@10.0.102.179(10.0.102.179:22) to root@10.0.102.204(10.0.102.204:22)..
SunDec 9 11:42:51 2018 - [debug]ok.
SunDec 9 11:42:51 2018 - [debug] Connecting via SSH from root@10.0.102.179(10.0.102.179:22) to root@10.0.102.221(10.0.102.221:22)..
SunDec 9 11:42:51 2018 - [debug]ok.
SunDec 9 11:42:52 2018 - [debug]SunDec 9 11:42:51 2018 - [debug] Connecting via SSH from root@10.0.102.221(10.0.102.221:22) to root@10.0.102.204(10.0.102.204:22)..
SunDec 9 11:42:52 2018 - [debug]ok.
SunDec 9 11:42:52 2018 - [debug] Connecting via SSH from root@10.0.102.221(10.0.102.221:22) to root@10.0.102.179(10.0.102.179:22)..
SunDec 9 11:42:52 2018 - [debug]ok.
SunDec 9 11:42:52 2018 - [info] AllSSH connection tests passed successfully.[root@test3 ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
Sun Dec 9 11:43:39 2018 - [warning] Global configuration file /etc/masterha_default.cnf notfound. Skipping.
SunDec 9 11:43:39 2018 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
SunDec 9 11:43:39 2018 - [info] Reading server configuration from /etc/masterha/app1.cnf..
SunDec 9 11:43:39 2018 - [info] MHA::MasterMonitor version 0.56.
SunDec 9 11:43:39 2018 - [info] GTID failover mode = 1SunDec 9 11:43:39 2018 - [info]Dead Servers:
SunDec 9 11:43:39 2018 - [info]Alive Servers:
SunDec 9 11:43:39 2018 - [info] 10.0.102.204(10.0.102.204:3