上一片博客中,讲述了怎么去配置MHA架构!这片博客不再细说,只说明其中MySQL主从搭建,这里使用的是gtid加上半同步复制!

步骤与上一片博客一样,不同之处在于MySQL主从的搭建!详细的gtid搭建过程https://www.cnblogs.com/wxzhe/p/10055154.html

上一片博客中,把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.09 sec)

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 not found. Skipping.
Sun Dec  9 11:42:50 2018 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Sun Dec  9 11:42:50 2018 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Sun Dec  9 11:42:50 2018 - [info] Starting SSH connection tests..
Sun Dec  9 11:42:51 2018 - [debug] 
Sun Dec  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)..
Sun Dec  9 11:42:51 2018 - [debug]   ok.
Sun Dec  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)..
Sun Dec  9 11:42:51 2018 - [debug]   ok.
Sun Dec  9 11:42:51 2018 - [debug] 
Sun Dec  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)..
Sun Dec  9 11:42:51 2018 - [debug]   ok.
Sun Dec  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)..
Sun Dec  9 11:42:51 2018 - [debug]   ok.
Sun Dec  9 11:42:52 2018 - [debug] 
Sun Dec  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)..
Sun Dec  9 11:42:52 2018 - [debug]   ok.
Sun Dec  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)..
Sun Dec  9 11:42:52 2018 - [debug]   ok.
Sun Dec  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 not found. Skipping.
Sun Dec  9 11:42:50 2018 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Sun Dec  9 11:42:50 2018 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Sun Dec  9 11:42:50 2018 - [info] Starting SSH connection tests..
Sun Dec  9 11:42:51 2018 - [debug] 
Sun Dec  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)..
Sun Dec  9 11:42:51 2018 - [debug]   ok.
Sun Dec  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)..
Sun Dec  9 11:42:51 2018 - [debug]   ok.
Sun Dec  9 11:42:51 2018 - [debug] 
Sun Dec  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)..
Sun Dec  9 11:42:51 2018 - [debug]   ok.
Sun Dec  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)..
Sun Dec  9 11:42:51 2018 - [debug]   ok.
Sun Dec  9 11:42:52 2018 - [debug] 
Sun Dec  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)..
Sun Dec  9 11:42:52 2018 - [debug]   ok.
Sun Dec  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)..
Sun Dec  9 11:42:52 2018 - [debug]   ok.
Sun Dec  9 11:42:52 2018 - [info] All SSH 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 not found. Skipping.
Sun Dec  9 11:43:39 2018 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Sun Dec  9 11:43:39 2018 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Sun Dec  9 11:43:39 2018 - [info] MHA::MasterMonitor version 0.56.
Sun Dec  9 11:43:39 2018 - [info] GTID failover mode = 1
Sun Dec  9 11:43:39 2018 - [info] Dead Servers:
Sun Dec  9 11:43:39 2018 - [info] Alive Servers:
Sun Dec  9 11:43:39 2018 - [info]   10.0.102.204(10.0.102.204:3306)
Sun Dec  9 11:43:39 2018 - [info]   10.0.102.179(10.0.102.179:3306)
Sun Dec  9 11:43:39 2018 - [info]   10.0.102.221(10.0.102.221:3306)
Sun Dec  9 11:43:39 2018 - [info] Alive Slaves:
Sun Dec  9 11:43:39 2018 - [info]   10.0.102.179(10.0.102.179:3306)  Version=5.7.22-log (oldest major version between slaves) log-bin:enabled
Sun Dec  9 11:43:39 2018 - [info]     GTID ON
Sun Dec  9 11:43:39 2018 - [info]     Replicating from 10.0.102.204(10.0.102.204:3306)
Sun Dec  9 11:43:39 2018 - [info]     Primary candidate for the new Master (candidate_master is set)
Sun Dec  9 11:43:39 2018 - [info]   10.0.102.221(10.0.102.221:3306)  Version=5.7.22-log (oldest major version between slaves) log-bin:enabled
Sun Dec  9 11:43:39 2018 - [info]     GTID ON
Sun Dec  9 11:43:39 2018 - [info]     Replicating from 10.0.102.204(10.0.102.204:3306)
Sun Dec  9 11:43:39 2018 - [info]     Not candidate for the new Master (no_master is set)
Sun Dec  9 11:43:39 2018 - [info] Current Alive Master: 10.0.102.204(10.0.102.204:3306)
Sun Dec  9 11:43:39 2018 - [info] Checking slave configurations..
Sun Dec  9 11:43:39 2018 - [info]  read_only=1 is not set on slave 10.0.102.179(10.0.102.179:3306).
Sun Dec  9 11:43:39 2018 - [info]  read_only=1 is not set on slave 10.0.102.221(10.0.102.221:3306).
Sun Dec  9 11:43:39 2018 - [info] Checking replication filtering settings..
Sun Dec  9 11:43:39 2018 - [info]  binlog_do_db= , binlog_ignore_db= 
Sun Dec  9 11:43:39 2018 - [info]  Replication filtering check ok.
Sun Dec  9 11:43:39 2018 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Sun Dec  9 11:43:39 2018 - [info] Checking SSH publickey authentication settings on the current master..
Sun Dec  9 11:43:39 2018 - [info] HealthCheck: SSH to 10.0.102.204 is reachable.
Sun Dec  9 11:43:39 2018 - [info] 
10.0.102.204(10.0.102.204:3306) (current master)
 +--10.0.102.179(10.0.102.179:3306)
 +--10.0.102.221(10.0.102.221:3306)

Sun Dec  9 11:43:39 2018 - [info] Checking replication health on 10.0.102.179..
Sun Dec  9 11:43:39 2018 - [info]  ok.
Sun Dec  9 11:43:39 2018 - [info] Checking replication health on 10.0.102.221..
Sun Dec  9 11:43:39 2018 - [info]  ok.
Sun Dec  9 11:43:39 2018 - [info] Checking master_ip_failover_script status:
Sun Dec  9 11:43:39 2018 - [info]   /usr/local/bin/master_ip_failover --ssh_user=root --command=status --ssh_user=root --orig_master_host=10.0.102.204 --orig_master_ip=10.0.102.204 --orig_master_port=3306 


IN SCRIPT TEST====service keepalived stop==service keepalived start===

Checking the Status of the script.. OK 
Sun Dec  9 11:43:39 2018 - [info]  OK.
Sun Dec  9 11:43:39 2018 - [warning] shutdown_script is not defined.
Sun Dec  9 11:43:39 2018 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.
[root@test3 

相关文章:

  • 2021-10-31
  • 2021-06-29
  • 2018-06-25
  • 2022-12-23
  • 2021-07-21
  • 2021-12-12
  • 2021-07-01
猜你喜欢
  • 2021-06-17
  • 2021-10-15
  • 2021-08-09
  • 2022-12-23
  • 2021-11-10
  • 2021-06-18
  • 2022-12-23
相关资源
相似解决方案