MySQL/MariaDB数据库的MHA实现高可用实战
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
一.MySQL高可用常见的解决方案
1>.Multi-Master Replication Manager for MySQL(简称MMM)
Mysql主主复制管理器是一套灵活的脚本程序,基于perl实现,用来对mysql replication进行监控和故障迁移,并能管理mysql Master-Master复制的配置(同一时间只有一个节点是可写的)
博主推荐阅读:
http://www.mysql-mmm.org
https://code.google.com/archive/p/mysql-master-master/downloads
2>.Master High Availability(简称MHA)
对主节点进行监控,可实现自动故障转移至其它从节点;通过提升某一从节点为新的主节点,基于主从复制实现,还需要客户端配合实现,目前MHA主要支持一主多从的架构,要搭建MHA,要求一个复制集群中必须最少有三台数据库服务器,一主二从,即一台充当master,一台充当备用master,另外一台充当从库,出于机器成本的考虑,淘宝进行了改造,目前淘宝TMHA已经支持一主一从
博主推荐阅读:
https://code.google.com/archive/p/mysql-master-ha/
3>.MySQL extended with the Write Set Replication(简称Galera Cluster:wsrep)
通过wsrep协议在全局实现复制;任何一节点都可读写,不需要主从复制,实现多主读写
4>.Group Replication(简称GR)
MySQL官方提供的组复制技术(MySQL 5.7.17引入的技术),基于原生复制技术Paxos算法
二.MHA概述
1>.MHA集群架构
如下图所示:
MHA是基于perl语言开发的,它需要单独部署到一台服务器上,我们称之为manager。
MHA可用监控多组主从复制集群(建议使用半同步复制),当任何一组中的master节点宕机,可用迅速该组中的slave节点提升为master,这个过程是自动切换的,无需我们手动切换。
2>.MHA选择master过程
(1)从宕机崩溃的master保存二进制日志事件(binlog events)
(2)识别含有最新更新的slave
(3)应用差异的中继日志(relay log)到其他的slave
(4)应用从master保存的二进制日志事件(binlog events)
(5)提升一个slave为新的master
(6)使其他的slave连接新的master进行复制
3>.MHA的组件
MHA软件由两部分组成,Manager工具包和Node工具包。
Manager工具包主要包括以下几个工具:
masterha_check_ssh:
检查MHA的SSH配置状况
masterha_check_repl:
检查MySQL复制状况
masterha_manger:
启动MHA
masterha_check_status:
检测当前MHA运行状态
masterha_master_monitor:
检测master是否宕机
masterha_master_switch:
故障转移(自动或手动)
masterha_conf_host:
添加或删除配置的server信息 Node工具包:这些工具通常由MHA Manager的脚本触发,无需人为操作)主要包括以下几个工具:
save_binary_logs:
保存和复制master的二进制日志
apply_diff_relay_logs:
识别差异的中继日志事件并将其差异的事件应用于其他的slave
filter_mysqlbinlog:
去除不必要的ROLLBACK事件(MHA已不再使用此工具)
purge_relay_logs:
清除中继日志(不会阻塞SQL线程)
注意:
为了尽可能的减少主库硬件损坏宕机造成的数据丢失,因此在配置MHA的同时建议配置成MySQL .5版本及以上的半同步复制
4>.自定义扩展
secondary_check_script:
通过多条网络路由检测master的可用性
master_ip_ailover_script:
更新Application使用的masterip
shutdown_script:
强制关闭master节点
report_script:
发送报告
init_conf_load_script:
加载初始配置参数
master_ip_online_change_script:
更新master节点ip地址
5>.配置文件
global配置:
为各application提供默认配置
application配置:
为每个主从复制集群
三.MHA部署实战
1>.搭建半同步复制
博主推荐阅读:
https://www.cnblogs.com/yinzhengjie/p/11828475.html 试验环境说明(搭建步骤如上所述,配置文件需要稍作修改):
node102.yinzhengjie.org.cn:
master节点
node103.yinzhengjie.org.cn:
slave节点
node104.yinzhengjie.org.cn:
MHA节点
[root@node102.yinzhengjie.org.cn ~]# cat /etc/my.cnf
[mysqld]
server-id =
binlog_format = row
log_bin = /data/mysql/logbin/master-
skip_name_resolve = #跳过名称反向解析,建议生产环境也开启它!
character-set-server = utf8mb4
default_storage_engine = InnoDB
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock [mysqld_safe]
log-error = /var/log/mariadb/mariadb.log
pid-file = /var/run/mariadb/mariadb.pid !includedir /etc/my.cnf.d
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# cat /etc/my.cnf
[root@node103.yinzhengjie.org.cn ~]# cat /etc/my.cnf
[mysqld]
server-id =
binlog_format = row
read-only = on #大家是否有疑问该参数是否应该使用默认的OFF呢?没错,的确是应该为OFF,但是我们这里设置为ON也没有关系,当MHA将它提升为主时会自动将其关闭!我们一会通过试验来验证一下~
relay_log = relay-log-
relay_log_index = relay-log-.index
log_bin = /data/mysql/logbin/master- #既然slave将来可能要被提升为master,因此我们务必要开启二进制功能哟
skip_name_resolve = #跳过名称解析,生产环境建议开启
relay_log_purge = #不清空中继日志,如果默认情况 relay_log_purge= 时,SQL线程就会自动将之前的relay log全部删除。而当relay_log_purge= 时,旧的relay log则会被保留。
character-set-server = utf8mb4
default_storage_engine = InnoDB
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock [mysqld_safe]
log-error = /var/log/mariadb/mariadb.log
pid-file = /var/run/mariadb/mariadb.pid !includedir /etc/my.cnf.d
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# cat /etc/my.cnf
[root@node102.yinzhengjie.org.cn ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> SELECT user,host,password FROM mysql.user;
+---------+----------------------------+-------------------------------------------+
| user | host | password |
+---------+----------------------------+-------------------------------------------+
| root | localhost | |
| root | node102.yinzhengjie.org.cn | |
| root | 127.0.0.1 | |
| root | :: | |
| | localhost | |
| | node102.yinzhengjie.org.cn | |
| copy | 172.30.1.10% | *BD0B1F48FDC55BD27555FC2F22FF29A68A25A1D7 |
| monitor | 172.30.1.10% | *BD0B1F48FDC55BD27555FC2F22FF29A68A25A1D7 |
| sqluser | 172.30.1.10% | *BD0B1F48FDC55BD27555FC2F22FF29A68A25A1D7 |
+---------+----------------------------+-------------------------------------------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> GRANT ALL ON *.* TO mhauser@'172.30.1.10%' IDENTIFIED BY 'yinzhengjie';
Query OK, rows affected (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> SELECT user,host,password FROM mysql.user;
+---------+----------------------------+-------------------------------------------+
| user | host | password |
+---------+----------------------------+-------------------------------------------+
| root | localhost | |
| root | node102.yinzhengjie.org.cn | |
| root | 127.0.0.1 | |
| root | :: | |
| | localhost | |
| | node102.yinzhengjie.org.cn | |
| copy | 172.30.1.10% | *BD0B1F48FDC55BD27555FC2F22FF29A68A25A1D7 |
| monitor | 172.30.1.10% | *BD0B1F48FDC55BD27555FC2F22FF29A68A25A1D7 |
| sqluser | 172.30.1.10% | *BD0B1F48FDC55BD27555FC2F22FF29A68A25A1D7 |
| mhauser | 172.30.1.10% | *BD0B1F48FDC55BD27555FC2F22FF29A68A25A1D7 |
+---------+----------------------------+-------------------------------------------+
rows in set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> QUIT
Bye
[root@node102.yinzhengjie.org.cn ~]#
在master节点创建mhauser@'172.30.1.10%'用户,该用户专门用于mha软件(权限要给大点)的管理账号
2>.同步集群时间(凡是涉及到集群部署的服务,建议第一步配置ntpd服务)
[root@node104.yinzhengjie.org.cn ~]# yum -y install ntp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.zju.edu.cn
* extras: mirrors..com
* updates: mirrors..com
base | 3.6 kB ::
extras | 2.9 kB ::
proxysql_repo | 2.9 kB ::
updates | 2.9 kB ::
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 :4.2.6p5-.el7.centos will be updated
---> Package ntp.x86_64 :4.2.6p5-.el7.centos will be an update
--> Processing Dependency: ntpdate = 4.2.6p5-.el7.centos for package: ntp-4.2.6p5-.el7.centos.x86_64
--> Running transaction check
---> Package ntpdate.x86_64 :4.2.6p5-.el7.centos will be updated
---> Package ntpdate.x86_64 :4.2.6p5-.el7.centos will be an update
--> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================
Updating:
ntp x86_64 4.2.6p5-.el7.centos base k
Updating for dependencies:
ntpdate x86_64 4.2.6p5-.el7.centos base k Transaction Summary
=================================================================================================================================================
Upgrade Package (+ Dependent package) Total download size: k
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(/): ntpdate-4.2.6p5-.el7.centos.x86_64.rpm | kB ::
(/): ntp-4.2.6p5-.el7.centos.x86_64.rpm | kB ::
-------------------------------------------------------------------------------------------------------------------------------------------------
Total 2.3 MB/s | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : ntpdate-4.2.6p5-.el7.centos.x86_64 /
Updating : ntp-4.2.6p5-.el7.centos.x86_64 /
Cleanup : ntp-4.2.6p5-.el7.centos.x86_64 /
Cleanup : ntpdate-4.2.6p5-.el7.centos.x86_64 /
Verifying : ntp-4.2.6p5-.el7.centos.x86_64 /
Verifying : ntpdate-4.2.6p5-.el7.centos.x86_64 /
Verifying : ntpdate-4.2.6p5-.el7.centos.x86_64 /
Verifying : ntp-4.2.6p5-.el7.centos.x86_64 / Updated:
ntp.x86_64 :4.2.6p5-.el7.centos Dependency Updated:
ntpdate.x86_64 :4.2.6p5-.el7.centos Complete!
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# yum -y install ntp #在所有节点都安装该软件
[root@node104.yinzhengjie.org.cn ~]# sed -i 's@\#restrict@restrict@' /etc/ntp.conf
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# sed -i 's#192.168.1.0#172.30.1.0#' /etc/ntp.conf
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# sed -i 's@^server@#server@' /etc/ntp.conf
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# echo "#Add by yinzhengjie" >> /etc/ntp.conf
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# echo "server 127.127.1.0" >> /etc/ntp.conf
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# echo "fudge 127.127.1.0 stratum 10" >> /etc/ntp.conf
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# echo SYNC_HWCLOCK=yes >> /etc/sysconfig/ntpd
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# systemctl start ntpd #我们将该节点作为ntpd服务器
[root@node104.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# crontab -l
*/ * * * * /usr/sbin/ntpdate node104.yinzhengjie.org.cn
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# crontab -l #将ntpd服务器指向我们自建的NTP服务器
[root@node103.yinzhengjie.org.cn ~]# crontab -l
*/ * * * * /usr/sbin/ntpdate node104.yinzhengjie.org.cn
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# crontab -l
3>.在所有节点实现相互之间ssh key验证
[root@node104.yinzhengjie.org.cn ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
Generating public/private rsa key pair.
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:0Z9W+Tcm9JZubmusNmNPcDqcXmDidatAyki30ei6UtM root@node104.yinzhengjie.org.cn
The key's randomart image is:
+---[RSA ]----+
| |
| . . |
| . . .o |
| .o..o...|
| .S+ ++* Oo|
| .o=E*.= % +|
| ...= o =.* |
| . . o=B+ |
| .o. o+B+.|
+----[SHA256]-----+
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
[root@node104.yinzhengjie.org.cn ~]# ssh-copy-id 172.30.1.104
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '172.30.1.104 (172.30.1.104)' can't be established.
ECDSA key fingerprint is SHA256:F3IVf82keybIystuO6PYRfwr0o5dTftrmAHJWzqO4IA.
ECDSA key fingerprint is MD5::5d:d8:0a:4a:b4::0f::be:2c:::db::e7.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.30.1.104's password: Number of key(s) added: Now try logging into the machine, with: "ssh '172.30.1.104'"
and check to make sure that only the key(s) you wanted were added. [root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# ssh-copy-id 172.30.1.104
[root@node104.yinzhengjie.org.cn ~]# cat ~/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGyN4MPfwSHf1jHHGoKYnIfrHtdmZUVaxh/uC/f872v1ZsQb1GH1P+VTWN35xEgHkPvqBDO3iqzU4SIhcu9bkfzpkSlrvr3m/3vLx9Zxpxv
Nu++VdISIU6RQ+dtiUHeaF9vOSG7JzDIjd+2duruIyxwVZ40Ldwt13QXw83vYDuG5jnR7eYrnW4yV6lVs8UifxXLYOXvdKXX3xF8TIcT2j3VJESkOzT1XtHaCyVjVfRot9RRSDXP0mATPJUvny/1ptOYhTqJETNdTGA2yM5IOy20gjQ7PStTVIJ4PQ4V4MtiVoNjj3pecUX84Kii0tAdsr5fwcRII1GYRs7H03BgK9J root@node104.yinzhengjie.org.cn[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# cat ~/.ssh/authorized_keys
[root@node104.yinzhengjie.org.cn ~]# scp -rp /root/.ssh 172.30.1.102:/root/
The authenticity of host '172.30.1.102 (172.30.1.102)' can't be established.
ECDSA key fingerprint is SHA256:ol1jiTSkfqSxf3SNjS0ACh+P53IUItM5HIgn2gkPj5Q.
ECDSA key fingerprint is MD5:2e::d3:4e:9c:b2:9b:::b4:::e1:6d:3f:b7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.30.1.102' (ECDSA) to the list of known hosts.
root@172.30.1.102's password:
id_rsa % .5MB/s :
id_rsa.pub % .3KB/s :
known_hosts % .4KB/s :
authorized_keys % .9KB/s :
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# scp -rp /root/.ssh 172.30.1.102:/root/
[root@node104.yinzhengjie.org.cn ~]# scp -rp /root/.ssh 172.30.1.103:/root/
The authenticity of host '172.30.1.103 (172.30.1.103)' can't be established.
ECDSA key fingerprint is SHA256:auvfSu0iwTr185exd1pfdhwkXf9wkA8VTXwYx8JrM1c.
ECDSA key fingerprint is MD5:ae:6b:0f:b6:0c::bb:b8:a4:fe::dc:::4f:1e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.30.1.103' (ECDSA) to the list of known hosts.
root@172.30.1.103's password:
id_rsa % .0MB/s :
id_rsa.pub % .5KB/s :
known_hosts % .6KB/s :
authorized_keys % .1MB/s :
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# scp -rp /root/.ssh 172.30.1.103:/root/
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# ssh 172.30.1.102
Last login: Tue Nov :: from 172.30.1.104
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# ssh 172.30.1.104
Last login: Tue Nov :: from 172.30.1.102
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# exit
logout
Connection to 172.30.1.104 closed.
[root@node102.yinzhengjie.org.cn ~]# exit
logout
Connection to 172.30.1.102 closed.
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# ssh 172.30.1.103
Last login: Tue Nov :: from 172.30.1.254
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# ssh 172.30.1.104
Last login: Tue Nov :: from 172.30.1.102
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# exit
logout
Connection to 172.30.1.104 closed.
[root@node103.yinzhengjie.org.cn ~]# exit
logout
Connection to 172.30.1.103 closed.
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]#
验证node104.yinzhengjie.org.cn是否可以MySQL主从复制集群免密钥互登录
4>.安装MHA工具包
[root@node104.yinzhengjie.org.cn ~]# ll #下载MHA软件包,并将被管理节点软件包拷贝到MySQL集群
total
-rw-r--r-- root root Oct : mha4mysql-manager-0.56-.el6.noarch.rpm
-rw-r--r-- root root Oct : mha4mysql-node-0.56-.el6.noarch.rpm
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# scp mha4mysql-node-0.56-.el6.noarch.rpm 172.30.1.102:~
mha4mysql-node-0.56-.el6.noarch.rpm % 35KB .0MB/s :
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# scp mha4mysql-node-0.56-.el6.noarch.rpm 172.30.1.103:~
mha4mysql-node-0.56-.el6.noarch.rpm % 35KB .4MB/s :
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# ll /etc/yum.repos.d/
total
-rw-r--r--. root root Nov CentOS-Base.repo
-rw-r--r--. root root Nov CentOS-CR.repo
-rw-r--r--. root root Nov CentOS-Debuginfo.repo
-rw-r--r--. root root Nov CentOS-fasttrack.repo
-rw-r--r--. root root Nov CentOS-Media.repo
-rw-r--r--. root root Nov CentOS-Sources.repo
-rw-r--r--. root root Nov CentOS-Vault.repo
-rw-r--r-- root root Nov : proxysql.repo
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# yum -y install epel-release
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.zju.edu.cn
* extras: mirrors.zju.edu.cn
* updates: mirrors.zju.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch :- will be installed
--> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================
Installing:
epel-release noarch - extras k Transaction Summary
=================================================================================================================================================
Install Package Total download size: k
Installed size: k
Downloading packages:
epel-release--.noarch.rpm | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release--.noarch /
Verifying : epel-release--.noarch / Installed:
epel-release.noarch :- Complete!
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# ll /etc/yum.repos.d/
total
-rw-r--r--. root root Nov CentOS-Base.repo
-rw-r--r--. root root Nov CentOS-CR.repo
-rw-r--r--. root root Nov CentOS-Debuginfo.repo
-rw-r--r--. root root Nov CentOS-fasttrack.repo
-rw-r--r--. root root Nov CentOS-Media.repo
-rw-r--r--. root root Nov CentOS-Sources.repo
-rw-r--r--. root root Nov CentOS-Vault.repo
-rw-r--r-- root root Oct epel.repo
-rw-r--r-- root root Oct epel-testing.repo
-rw-r--r-- root root Nov : proxysql.repo
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# yum -y install epel-release #管理节点依赖EPEL源
[root@node104.yinzhengjie.org.cn ~]# ll
total
-rw-r--r-- root root Oct : mha4mysql-manager-0.56-.el6.noarch.rpm
-rw-r--r-- root root Oct : mha4mysql-node-0.56-.el6.noarch.rpm
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# yum -y install mha4mysql-*
Loaded plugins: fastestmirror
Examining mha4mysql-manager-0.56-.el6.noarch.rpm: mha4mysql-manager-0.56-.el6.noarch
Marking mha4mysql-manager-0.56-.el6.noarch.rpm to be installed
Examining mha4mysql-node-0.56-.el6.noarch.rpm: mha4mysql-node-0.56-.el6.noarch
Marking mha4mysql-node-0.56-.el6.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mha4mysql-manager.noarch :0.56-.el6 will be installed
--> Processing Dependency: perl(Config::Tiny) for package: mha4mysql-manager-0.56-.el6.noarch
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 7.9 kB ::
* base: mirrors.zju.edu.cn
* epel: hkg.mirror.rackspace.com
* extras: mirrors..com
* updates: mirrors..com
epel | 5.3 kB ::
(/): epel/x86_64/group_gz | kB ::
(/): epel/x86_64/updateinfo | 1.0 MB ::
(/): epel/x86_64/primary_db | 6.9 MB ::
--> Processing Dependency: perl(Config::Tiny) for package: mha4mysql-manager-0.56-.el6.noarch
--> Processing Dependency: perl(Log::Dispatch) for package: mha4mysql-manager-0.56-.el6.noarch
--> Processing Dependency: perl(Log::Dispatch) for package: mha4mysql-manager-0.56-.el6.noarch
--> Processing Dependency: perl(Log::Dispatch::File) for package: mha4mysql-manager-0.56-.el6.noarch
--> Processing Dependency: perl(Log::Dispatch::Screen) for package: mha4mysql-manager-0.56-.el6.noarch
--> Processing Dependency: perl(Parallel::ForkManager) for package: mha4mysql-manager-0.56-.el6.noarch
--> Processing Dependency: perl(Parallel::ForkManager) for package: mha4mysql-manager-0.56-.el6.noarch
---> Package mha4mysql-node.noarch :0.56-.el6 will be installed
--> Running transaction check
---> Package perl-Config-Tiny.noarch :2.14-.el7 will be installed
---> Package perl-Log-Dispatch.noarch :2.41-.el7. will be installed
--> Processing Dependency: perl(Params::Validate) >= 0.15 for package: perl-Log-Dispatch-2.41-.el7..noarch
--> Processing Dependency: perl(Class::Load) for package: perl-Log-Dispatch-2.41-.el7..noarch
--> Processing Dependency: perl(MIME::Lite) for package: perl-Log-Dispatch-2.41-.el7..noarch
--> Processing Dependency: perl(Mail::Send) for package: perl-Log-Dispatch-2.41-.el7..noarch
--> Processing Dependency: perl(Mail::Sender) for package: perl-Log-Dispatch-2.41-.el7..noarch
--> Processing Dependency: perl(Mail::Sendmail) for package: perl-Log-Dispatch-2.41-.el7..noarch
--> Processing Dependency: perl(Params::Validate) for package: perl-Log-Dispatch-2.41-.el7..noarch
---> Package perl-Parallel-ForkManager.noarch :1.18-.el7 will be installed
--> Running transaction check
---> Package perl-Class-Load.noarch :0.20-.el7 will be installed
--> Processing Dependency: perl(Package::Stash) >= 0.14 for package: perl-Class-Load-0.20-.el7.noarch
--> Processing Dependency: perl(Module::Runtime) >= 0.012 for package: perl-Class-Load-0.20-.el7.noarch
--> Processing Dependency: perl(Module::Implementation) >= 0.04 for package: perl-Class-Load-0.20-.el7.noarch
--> Processing Dependency: perl(Try::Tiny) for package: perl-Class-Load-0.20-.el7.noarch
--> Processing Dependency: perl(Module::Runtime) for package: perl-Class-Load-0.20-.el7.noarch
--> Processing Dependency: perl(Data::OptList) for package: perl-Class-Load-0.20-.el7.noarch
---> Package perl-MIME-Lite.noarch :3.030-.el7 will be installed
--> Processing Dependency: perl(MIME::Types) >= 1.28 for package: perl-MIME-Lite-3.030-.el7.noarch
--> Processing Dependency: perl(Email::Date::Format) for package: perl-MIME-Lite-3.030-.el7.noarch
---> Package perl-Mail-Sender.noarch :0.8.-.el7 will be installed
---> Package perl-Mail-Sendmail.noarch :0.79-.el7 will be installed
---> Package perl-MailTools.noarch :2.12-.el7 will be installed
--> Processing Dependency: perl(Net::SMTP::SSL) for package: perl-MailTools-2.12-.el7.noarch
---> Package perl-Params-Validate.x86_64 :1.08-.el7 will be installed
--> Running transaction check
---> Package perl-Data-OptList.noarch :0.107-.el7 will be installed
--> Processing Dependency: perl(Sub::Install) >= 0.921 for package: perl-Data-OptList-0.107-.el7.noarch
--> Processing Dependency: perl(Params::Util) for package: perl-Data-OptList-0.107-.el7.noarch
---> Package perl-Email-Date-Format.noarch :1.002-.el7 will be installed
---> Package perl-MIME-Types.noarch :1.38-.el7 will be installed
---> Package perl-Module-Implementation.noarch :0.06-.el7 will be installed
---> Package perl-Module-Runtime.noarch :0.013-.el7 will be installed
---> Package perl-Net-SMTP-SSL.noarch :1.01-.el7 will be installed
---> Package perl-Package-Stash.noarch :0.34-.el7 will be installed
--> Processing Dependency: perl(Package::Stash::XS) >= 0.26 for package: perl-Package-Stash-0.34-.el7.noarch
--> Processing Dependency: perl(Package::DeprecationManager) for package: perl-Package-Stash-0.34-.el7.noarch
---> Package perl-Try-Tiny.noarch :0.12-.el7 will be installed
--> Running transaction check
---> Package perl-Package-DeprecationManager.noarch :0.13-.el7 will be installed
--> Processing Dependency: perl(List::MoreUtils) for package: perl-Package-DeprecationManager-0.13-.el7.noarch
---> Package perl-Package-Stash-XS.x86_64 :0.26-.el7 will be installed
---> Package perl-Params-Util.x86_64 :1.07-.el7 will be installed
---> Package perl-Sub-Install.noarch :0.926-.el7 will be installed
--> Running transaction check
---> Package perl-List-MoreUtils.x86_64 :0.33-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================
Installing:
mha4mysql-manager noarch 0.56-.el6 /mha4mysql-manager-0.56-.el6.noarch k
mha4mysql-node noarch 0.56-.el6 /mha4mysql-node-0.56-.el6.noarch k
Installing for dependencies:
perl-Class-Load noarch 0.20-.el7 base k
perl-Config-Tiny noarch 2.14-.el7 base k
perl-Data-OptList noarch 0.107-.el7 base k
perl-Email-Date-Format noarch 1.002-.el7 epel k
perl-List-MoreUtils x86_64 0.33-.el7 base k
perl-Log-Dispatch noarch 2.41-.el7. epel k
perl-MIME-Lite noarch 3.030-.el7 epel k
perl-MIME-Types noarch 1.38-.el7 epel k
perl-Mail-Sender noarch 0.8.-.el7 epel k
perl-Mail-Sendmail noarch 0.79-.el7 epel k
perl-MailTools noarch 2.12-.el7 base k
perl-Module-Implementation noarch 0.06-.el7 base k
perl-Module-Runtime noarch 0.013-.el7 base k
perl-Net-SMTP-SSL noarch 1.01-.el7 base 9.1 k
perl-Package-DeprecationManager noarch 0.13-.el7 base k
perl-Package-Stash noarch 0.34-.el7 base k
perl-Package-Stash-XS x86_64 0.26-.el7 base k
perl-Parallel-ForkManager noarch 1.18-.el7 epel k
perl-Params-Util x86_64 1.07-.el7 base k
perl-Params-Validate x86_64 1.08-.el7 base k
perl-Sub-Install noarch 0.926-.el7 base k
perl-Try-Tiny noarch 0.12-.el7 base k Transaction Summary
=================================================================================================================================================
Install Packages (+ Dependent packages) Total size: 1.3 M
Total download size: k
Installed size: 2.0 M
Downloading packages:
(/): perl-Class-Load-0.20-.el7.noarch.rpm | kB ::
(/): perl-Config-Tiny-2.14-.el7.noarch.rpm | kB ::
(/): perl-Data-OptList-0.107-.el7.noarch.rpm | kB ::
(/): perl-List-MoreUtils-0.33-.el7.x86_64.rpm | kB ::
warning: /var/cache/yum/x86_64//epel/packages/perl-Email-Date-Format-1.002-.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: N
OKEYPublic key for perl-Email-Date-Format-1.002-.el7.noarch.rpm is not installed
(/): perl-Email-Date-Format-1.002-.el7.noarch.rpm | kB ::
(/): perl-Log-Dispatch-2.41-.el7..noarch.rpm | kB ::
(/): perl-MIME-Lite-3.030-.el7.noarch.rpm | kB ::
(/): perl-MIME-Types-1.38-.el7.noarch.rpm | kB ::
(/): perl-Module-Implementation-0.06-.el7.noarch.rpm | kB ::
(/): perl-Module-Runtime-0.013-.el7.noarch.rpm | kB ::
(/): perl-Net-SMTP-SSL-1.01-.el7.noarch.rpm | 9.1 kB ::
(/): perl-MailTools-2.12-.el7.noarch.rpm | kB ::
(/): perl-Package-DeprecationManager-0.13-.el7.noarch.rpm | kB ::
(/): perl-Package-Stash-0.34-.el7.noarch.rpm | kB ::
(/): perl-Params-Util-1.07-.el7.x86_64.rpm | kB ::
(/): perl-Package-Stash-XS-0.26-.el7.x86_64.rpm | kB ::
(/): perl-Params-Validate-1.08-.el7.x86_64.rpm | kB ::
(/): perl-Sub-Install-0.926-.el7.noarch.rpm | kB ::
(/): perl-Parallel-ForkManager-1.18-.el7.noarch.rpm | kB ::
(/): perl-Try-Tiny-0.12-.el7.noarch.rpm | kB ::
(/): perl-Mail-Sendmail-0.79-.el7.noarch.rpm | kB ::
(/): perl-Mail-Sender-0.8.-.el7.noarch.rpm | kB ::
-------------------------------------------------------------------------------------------------------------------------------------------------
Total kB/s | kB ::
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
Userid : "Fedora EPEL (7) <epel@fedoraproject.org>"
Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
Package : epel-release--.noarch (@extras)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : perl-Sub-Install-0.926-.el7.noarch /
Installing : perl-Try-Tiny-0.12-.el7.noarch /
Installing : perl-Params-Util-1.07-.el7.x86_64 /
Installing : perl-Module-Runtime-0.013-.el7.noarch /
Installing : perl-Module-Implementation-0.06-.el7.noarch /
Installing : perl-Params-Validate-1.08-.el7.x86_64 /
Installing : perl-Data-OptList-0.107-.el7.noarch /
Installing : perl-Email-Date-Format-1.002-.el7.noarch /
Installing : perl-Net-SMTP-SSL-1.01-.el7.noarch /
Installing : perl-MailTools-2.12-.el7.noarch /
Installing : perl-Package-Stash-XS-0.26-.el7.x86_64 /
Installing : perl-MIME-Types-1.38-.el7.noarch /
Installing : perl-MIME-Lite-3.030-.el7.noarch /
Installing : perl-List-MoreUtils-0.33-.el7.x86_64 /
Installing : perl-Package-DeprecationManager-0.13-.el7.noarch /
Installing : perl-Package-Stash-0.34-.el7.noarch /
Installing : perl-Class-Load-0.20-.el7.noarch /
Installing : perl-Config-Tiny-2.14-.el7.noarch /
Installing : perl-Mail-Sender-0.8.-.el7.noarch /
Installing : perl-Parallel-ForkManager-1.18-.el7.noarch /
Installing : perl-Mail-Sendmail-0.79-.el7.noarch /
Installing : perl-Log-Dispatch-2.41-.el7..noarch /
Installing : mha4mysql-node-0.56-.el6.noarch /
Installing : mha4mysql-manager-0.56-.el6.noarch /
Verifying : mha4mysql-manager-0.56-.el6.noarch /
Verifying : mha4mysql-node-0.56-.el6.noarch /
Verifying : perl-Module-Runtime-0.013-.el7.noarch /
Verifying : perl-Mail-Sendmail-0.79-.el7.noarch /
Verifying : perl-MailTools-2.12-.el7.noarch /
Verifying : perl-Params-Util-1.07-.el7.x86_64 /
Verifying : perl-Try-Tiny-0.12-.el7.noarch /
Verifying : perl-Parallel-ForkManager-1.18-.el7.noarch /
Verifying : perl-Mail-Sender-0.8.-.el7.noarch /
Verifying : perl-Class-Load-0.20-.el7.noarch /
Verifying : perl-Config-Tiny-2.14-.el7.noarch /
Verifying : perl-List-MoreUtils-0.33-.el7.x86_64 /
Verifying : perl-Package-DeprecationManager-0.13-.el7.noarch /
Verifying : perl-MIME-Types-1.38-.el7.noarch /
Verifying : perl-Package-Stash-0.34-.el7.noarch /
Verifying : perl-Package-Stash-XS-0.26-.el7.x86_64 /
Verifying : perl-MIME-Lite-3.030-.el7.noarch /
Verifying : perl-Params-Validate-1.08-.el7.x86_64 /
Verifying : perl-Net-SMTP-SSL-1.01-.el7.noarch /
Verifying : perl-Log-Dispatch-2.41-.el7..noarch /
Verifying : perl-Sub-Install-0.926-.el7.noarch /
Verifying : perl-Module-Implementation-0.06-.el7.noarch /
Verifying : perl-Data-OptList-0.107-.el7.noarch /
Verifying : perl-Email-Date-Format-1.002-.el7.noarch / Installed:
mha4mysql-manager.noarch :0.56-.el6 mha4mysql-node.noarch :0.56-.el6 Dependency Installed:
perl-Class-Load.noarch :0.20-.el7 perl-Config-Tiny.noarch :2.14-.el7 perl-Data-OptList.noarch :0.107-.el7
perl-Email-Date-Format.noarch :1.002-.el7 perl-List-MoreUtils.x86_64 :0.33-.el7 perl-Log-Dispatch.noarch :2.41-.el7.
perl-MIME-Lite.noarch :3.030-.el7 perl-MIME-Types.noarch :1.38-.el7 perl-Mail-Sender.noarch :0.8.-.el7
perl-Mail-Sendmail.noarch :0.79-.el7 perl-MailTools.noarch :2.12-.el7 perl-Module-Implementation.noarch :0.06-.el7
perl-Module-Runtime.noarch :0.013-.el7 perl-Net-SMTP-SSL.noarch :1.01-.el7 perl-Package-DeprecationManager.noarch :0.13-.el7
perl-Package-Stash.noarch :0.34-.el7 perl-Package-Stash-XS.x86_64 :0.26-.el7 perl-Parallel-ForkManager.noarch :1.18-.el7
perl-Params-Util.x86_64 :1.07-.el7 perl-Params-Validate.x86_64 :1.08-.el7 perl-Sub-Install.noarch :0.926-.el7
perl-Try-Tiny.noarch :0.12-.el7 Complete!
[root@node104.yinzhengjie.org.cn ~]#
在管理节点上安装两个包:mha4mysql-manager和mha4mysql-node
[root@node102.yinzhengjie.org.cn ~]# ll
total
-rw-r--r-- root root Nov : mha4mysql-node-0.56-.el6.noarch.rpm
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# yum -y install mha4mysql-node-0.56-.el6.noarch.rpm
Loaded plugins: fastestmirror
Examining mha4mysql-node-0.56-.el6.noarch.rpm: mha4mysql-node-0.56-.el6.noarch
Marking mha4mysql-node-0.56-.el6.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mha4mysql-node.noarch :0.56-.el6 will be installed
--> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================
Installing:
mha4mysql-node noarch 0.56-.el6 /mha4mysql-node-0.56-.el6.noarch k Transaction Summary
=================================================================================================================================================
Install Package Total size: k
Installed size: k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mha4mysql-node-0.56-.el6.noarch /
Verifying : mha4mysql-node-0.56-.el6.noarch / Installed:
mha4mysql-node.noarch :0.56-.el6 Complete!
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# yum -y install mha4mysql-node-0.56-0.el6.noarch.rpm
[root@node103.yinzhengjie.org.cn ~]# ll
total
-rw-r--r-- root root Nov : mha4mysql-node-0.56-.el6.noarch.rpm
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# yum -y install mha4mysql-node-0.56-.el6.noarch.rpm
Loaded plugins: fastestmirror
Examining mha4mysql-node-0.56-.el6.noarch.rpm: mha4mysql-node-0.56-.el6.noarch
Marking mha4mysql-node-0.56-.el6.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mha4mysql-node.noarch :0.56-.el6 will be installed
--> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================
Installing:
mha4mysql-node noarch 0.56-.el6 /mha4mysql-node-0.56-.el6.noarch k Transaction Summary
=================================================================================================================================================
Install Package Total size: k
Installed size: k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mha4mysql-node-0.56-.el6.noarch /
Verifying : mha4mysql-node-0.56-.el6.noarch / Installed:
mha4mysql-node.noarch :0.56-.el6 Complete!
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# yum -y install mha4mysql-node-0.56-0.el6.noarch.rpm
5>.在管理节点建立配置文件(文件夹自定义即可)
[root@node104.yinzhengjie.org.cn ~]# mkdir /etc/mha #创建存放MHA配置文件
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# vim /etc/mha/cluster01.conf
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# cat /etc/mha/cluster01.conf
[server default]
user=mhauser #管理节点的用户
password=yinzhengjie #管理节点的密码
manager_workdir=/data/mastermha/cluster01/ #在本地的工作目录会自动生成
manager_log=/data/mastermha/cluster01/manager.log #指定日志存放
remote_workdir=/data/mastermha/cluster01/ #在远程主机的工作目录
master_binlog_dir=/data/mysql/logbin #如果你将MySQL数据库二进制日志分开存储,这里一定要配置master的二进制日志存储目录,否则下面会检查失败的 ssh_user=root #ssh登录用户,就是我们上面配置免密码登录的账号
repl_user=copy #MySQL复制用户的账号,这个用户应该在master和slave节点应该都存在,否则下面检查会失败
repl_password=yinzhengjie #MySQL复制用户的密码
ping_interval= #指定间隔时间ping [server1] #监控服务器列表,
hostname=172.30.1.102 #指定主机IP地址
candidate_master= #如果配置该项表示它们有资格被选取为主服务器的,如果不配置表示无权限成为master,一般用于一主多从架构,将服务器性能较好的配置该参数,性能较差的就不要配置该参数即可,由于我这里试验总共就2台,因此我都给它们配置上啦! [server2]
hostname=172.30.1.103
candidate_master=
[root@node104.yinzhengjie.org.cn ~]#
6>.MHA验证和启动
[root@node104.yinzhengjie.org.cn ~]# rpm -ql mha4mysql-manager
/usr/bin/masterha_check_repl
/usr/bin/masterha_check_ssh
/usr/bin/masterha_check_status
/usr/bin/masterha_conf_host
/usr/bin/masterha_manager
/usr/bin/masterha_master_monitor
/usr/bin/masterha_master_switch
/usr/bin/masterha_secondary_check
/usr/bin/masterha_stop
/usr/share/man/man1/masterha_check_repl..gz
/usr/share/man/man1/masterha_check_ssh..gz
/usr/share/man/man1/masterha_check_status..gz
/usr/share/man/man1/masterha_conf_host..gz
/usr/share/man/man1/masterha_manager..gz
/usr/share/man/man1/masterha_master_monitor..gz
/usr/share/man/man1/masterha_master_switch..gz
/usr/share/man/man1/masterha_secondary_check..gz
/usr/share/man/man1/masterha_stop..gz
/usr/share/perl5/vendor_perl/MHA/Config.pm
/usr/share/perl5/vendor_perl/MHA/DBHelper.pm
/usr/share/perl5/vendor_perl/MHA/FileStatus.pm
/usr/share/perl5/vendor_perl/MHA/HealthCheck.pm
/usr/share/perl5/vendor_perl/MHA/ManagerAdmin.pm
/usr/share/perl5/vendor_perl/MHA/ManagerAdminWrapper.pm
/usr/share/perl5/vendor_perl/MHA/ManagerConst.pm
/usr/share/perl5/vendor_perl/MHA/ManagerUtil.pm
/usr/share/perl5/vendor_perl/MHA/MasterFailover.pm
/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm
/usr/share/perl5/vendor_perl/MHA/MasterRotate.pm
/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm
/usr/share/perl5/vendor_perl/MHA/Server.pm
/usr/share/perl5/vendor_perl/MHA/ServerManager.pm
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# rpm -ql mha4mysql-manager
[root@node104.yinzhengjie.org.cn ~]# masterha_check_ssh --conf=/etc/mha/cluster01.conf #测试SSH协议是否正常访问个节点,从下面的输出可以看出来是来验证上面配置免密码登录是否成功啦!
Tue Nov :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Tue Nov :: - [info] Reading application default configuration from /etc/mha/cluster01.conf..
Tue Nov :: - [info] Reading server configuration from /etc/mha/cluster01.conf..
Tue Nov :: - [info] Starting SSH connection tests..
Tue Nov :: - [debug]
Tue Nov :: - [debug] Connecting via SSH from root@172.30.1.102(172.30.1.102:) to root@172.30.1.103(172.30.1.103:)..
Warning: Permanently added '172.30.1.103' (ECDSA) to the list of known hosts.
Tue Nov :: - [debug] ok.
Tue Nov :: - [debug]
Tue Nov :: - [debug] Connecting via SSH from root@172.30.1.103(172.30.1.103:) to root@172.30.1.102(172.30.1.102:)..
Tue Nov :: - [debug] ok.
Tue Nov :: - [info] All SSH connection tests passed successfully.
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# masterha_check_ssh --conf=/etc/mha/cluster01.conf
[root@node104.yinzhengjie.org.cn ~]# masterha_check_repl --conf=/etc/mha/cluster01.conf #检查主从复制情况是否正常
Tue Nov :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Tue Nov :: - [info] Reading application default configuration from /etc/mha/cluster01.conf..
Tue Nov :: - [info] Reading server configuration from /etc/mha/cluster01.conf..
Tue Nov :: - [info] MHA::MasterMonitor version 0.56.
Tue Nov :: - [info] GTID failover mode =
Tue Nov :: - [info] Dead Servers:
Tue Nov :: - [info] Alive Servers:
Tue Nov :: - [info] 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:)
Tue Nov :: - [info] Alive Slaves:
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:) Version=5.5.-MariaDB (oldest major version between slaves) log-bin:enabled
Tue Nov :: - [info] Replicating from 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Tue Nov :: - [info] Current Alive Master: 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Checking slave configurations..
Tue Nov :: - [info] Checking replication filtering settings..
Tue Nov :: - [info] binlog_do_db= , binlog_ignore_db=
Tue Nov :: - [info] Replication filtering check ok.
Tue Nov :: - [info] GTID (with auto-pos) is not supported
Tue Nov :: - [info] Starting SSH connection tests..
Tue Nov :: - [info] All SSH connection tests passed successfully.
Tue Nov :: - [info] Checking MHA Node version..
Tue Nov :: - [info] Version check ok.
Tue Nov :: - [info] Checking SSH publickey authentication settings on the current master..
Tue Nov :: - [info] HealthCheck: SSH to 172.30.1.102 is reachable.
Tue Nov :: - [info] Master MHA Node version is 0.56.
Tue Nov :: - [info] Checking recovery script configurations on 172.30.1.102(172.30.1.102:)..
Tue Nov :: - [info] Executing command: save_binary_logs --command=test --start_pos= --binlog_dir=/data/mysql/logbin --output_fil
e=/data/mastermha/cluster01//save_binary_logs_test --manager_version=0.56 --start_file=master-102.000004 Tue Nov 12 08:43:16 2019 - [info] Connecting to root@172.30.1.102(172.30.1.102:22)..
Creating /data/mastermha/cluster01 if not exists.. Creating directory /data/mastermha/cluster01.. done.
ok.
Checking output directory is accessible or not..
ok.
Binlog found at /data/mysql/logbin, up to master-102.000004
Tue Nov :: - [info] Binlog setting check done.
Tue Nov :: - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Tue Nov :: - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='mhauser' --slave_host=172.30.1.103 --s
lave_ip=172.30.1.103 --slave_port= --workdir=/data/mastermha/cluster01/ --target_version=5.5.-MariaDB --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxxTue Nov :: - [info] Connecting to root@172.30.1.103(172.30.1.103:)..
Creating directory /data/mastermha/cluster01/.. done.
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to relay-log-103.000008
Temporary relay log file is /var/lib/mysql/relay-log-103.000008
Testing mysql connection and privileges.. done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Tue Nov :: - [info] Slaves settings check done.
Tue Nov :: - [info]
172.30.1.102(172.30.1.102:) (current master)
+--172.30.1.103(172.30.1.103:) Tue Nov :: - [info] Checking replication health on 172.30.1.103..
Tue Nov :: - [info] ok.
Tue Nov :: - [warning] master_ip_failover_script is not defined.
Tue Nov :: - [warning] shutdown_script is not defined.
Tue Nov :: - [info] Got exit code (Not master dead). MySQL Replication Health is OK.
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# masterha_check_repl --conf=/etc/mha/cluster01.conf
[root@node104.yinzhengjie.org.cn ~]# masterha_manager --conf=/etc/mha/cluster01.conf #注意这是一个性检查,当出现故障时他会监控到与此同时结束该进程。不推荐直接这样使用,因为所有的监控信息都在当前终端显示,当网络故障的话就凉凉啦~
Tue Nov :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Tue Nov :: - [info] Reading application default configuration from /etc/mha/cluster01.conf..
Tue Nov :: - [info] Reading server configuration from /etc/mha/cluster01.conf..
[root@node104.yinzhengjie.org.cn ~]# ll /data/mastermha/cluster01/ #这个目录是我们上面启动MHA服务时自动创建出来的,我们无需手动创建
total
-rw-r--r-- root root Nov : cluster01.master_status.health #这是健康检查的配置文件
-rw-r--r-- root root Nov : manager.log
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# cat /data/mastermha/cluster01/manager.log #查看排错日志
Tue Nov :: - [info] MHA::MasterMonitor version 0.56.
Tue Nov :: - [info] GTID failover mode =
Tue Nov :: - [info] Dead Servers:
Tue Nov :: - [info] Alive Servers:
Tue Nov :: - [info] 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:)
Tue Nov :: - [info] Alive Slaves:
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:) Version=5.5.-MariaDB (oldest major version between slaves) log-bin:enabled
Tue Nov :: - [info] Replicating from 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Tue Nov :: - [info] Current Alive Master: 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Checking slave configurations..
Tue Nov :: - [info] Checking replication filtering settings..
Tue Nov :: - [info] binlog_do_db= , binlog_ignore_db=
Tue Nov :: - [info] Replication filtering check ok.
Tue Nov :: - [info] GTID (with auto-pos) is not supported
Tue Nov :: - [info] Starting SSH connection tests..
Tue Nov :: - [info] All SSH connection tests passed successfully.
Tue Nov :: - [info] Checking MHA Node version..
Tue Nov :: - [info] Version check ok.
Tue Nov :: - [info] Checking SSH publickey authentication settings on the current master..
Tue Nov :: - [info] HealthCheck: SSH to 172.30.1.102 is reachable.
Tue Nov :: - [info] Master MHA Node version is 0.56.
Tue Nov :: - [info] Checking recovery script configurations on 172.30.1.102(172.30.1.102:)..
Tue Nov :: - [info] Executing command: save_binary_logs --command=test --start_pos= --binlog_dir=/data/mysql/logbin --output_fil
e=/data/mastermha/cluster01//save_binary_logs_test --manager_version=0.56 --start_file=master-102.000004 Tue Nov 12 08:48:43 2019 - [info] Connecting to root@172.30.1.102(172.30.1.102:22)..
Creating /data/mastermha/cluster01 if not exists.. ok.
Checking output directory is accessible or not..
ok.
Binlog found at /data/mysql/logbin, up to master-102.000004
Tue Nov :: - [info] Binlog setting check done.
Tue Nov :: - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Tue Nov :: - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='mhauser' --slave_host=172.30.1.103 --s
lave_ip=172.30.1.103 --slave_port= --workdir=/data/mastermha/cluster01/ --target_version=5.5.-MariaDB --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxxTue Nov :: - [info] Connecting to root@172.30.1.103(172.30.1.103:)..
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to relay-log-103.000008
Temporary relay log file is /var/lib/mysql/relay-log-103.000008
Testing mysql connection and privileges.. done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Tue Nov :: - [info] Slaves settings check done.
Tue Nov :: - [info]
172.30.1.102(172.30.1.102:) (current master)
+--172.30.1.103(172.30.1.103:) Tue Nov :: - [warning] master_ip_failover_script is not defined.
Tue Nov :: - [warning] shutdown_script is not defined.
Tue Nov :: - [info] Set master ping interval seconds.
Tue Nov :: - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from
two or more routes.Tue Nov :: - [info] Starting ping health check on 172.30.1.102(172.30.1.102:)..
Tue Nov :: - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# cat /data/mastermha/cluster01/manager.log #查看排错日志
7>.将master节点服务器重启,观察MHA管理端
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN *: *:*
LISTEN *: *:*
LISTEN ::: :::*
[root@node102.yinzhengjie.org.cn ~]#
[root@node102.yinzhengjie.org.cn ~]# reboot Connection closed by foreign host. Disconnected from remote host(node102.yinzhengjie.org.cn) at ::. Type `help' to learn how to use Xshell prompt.
[c:\~]$
[root@node102.yinzhengjie.org.cn ~]# reboot
[root@node104.yinzhengjie.org.cn ~]# masterha_manager --conf=/etc/mha/cluster01.conf #注意,这个终端我们在上一步已经启动了,只不过重启后,发现多出来一些信息且自动终止了当前命令~生产环境建议该命令和"nohup"一起使用!
Tue Nov :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Tue Nov :: - [info] Reading application default configuration from /etc/mha/cluster01.conf..
Tue Nov :: - [info] Reading server configuration from /etc/mha/cluster01.conf..
ssh: connect to host 172.30.1.102 port : Connection refused
Tue Nov :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Tue Nov :: - [info] Reading application default configuration from /etc/mha/cluster01.conf..
Tue Nov :: - [info] Reading server configuration from /etc/mha/cluster01.conf..
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# cat /data/mastermha/cluster01/manager.log #查看日志信息,我们可以看到master的切换过程
Tue Nov :: - [info] MHA::MasterMonitor version 0.56.
Tue Nov :: - [info] GTID failover mode =
Tue Nov :: - [info] Dead Servers:
Tue Nov :: - [info] Alive Servers:
Tue Nov :: - [info] 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:)
Tue Nov :: - [info] Alive Slaves:
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:) Version=5.5.-MariaDB (oldest major version between slaves) log-bin:enabled
Tue Nov :: - [info] Replicating from 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Tue Nov :: - [info] Current Alive Master: 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Checking slave configurations..
Tue Nov :: - [info] Checking replication filtering settings..
Tue Nov :: - [info] binlog_do_db= , binlog_ignore_db=
Tue Nov :: - [info] Replication filtering check ok.
Tue Nov :: - [info] GTID (with auto-pos) is not supported
Tue Nov :: - [info] Starting SSH connection tests..
Tue Nov :: - [info] All SSH connection tests passed successfully.
Tue Nov :: - [info] Checking MHA Node version..
Tue Nov :: - [info] Version check ok.
Tue Nov :: - [info] Checking SSH publickey authentication settings on the current master..
Tue Nov :: - [info] HealthCheck: SSH to 172.30.1.102 is reachable.
Tue Nov :: - [info] Master MHA Node version is 0.56.
Tue Nov :: - [info] Checking recovery script configurations on 172.30.1.102(172.30.1.102:)..
Tue Nov :: - [info] Executing command: save_binary_logs --command=test --start_pos= --binlog_dir=/data/mysql/logbin --output_fil
e=/data/mastermha/cluster01//save_binary_logs_test --manager_version=0.56 --start_file=master-102.000004 Tue Nov 12 08:48:43 2019 - [info] Connecting to root@172.30.1.102(172.30.1.102:22)..
Creating /data/mastermha/cluster01 if not exists.. ok.
Checking output directory is accessible or not..
ok.
Binlog found at /data/mysql/logbin, up to master-102.000004
Tue Nov :: - [info] Binlog setting check done.
Tue Nov :: - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Tue Nov :: - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='mhauser' --slave_host=172.30.1.103 --s
lave_ip=172.30.1.103 --slave_port= --workdir=/data/mastermha/cluster01/ --target_version=5.5.-MariaDB --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxxTue Nov :: - [info] Connecting to root@172.30.1.103(172.30.1.103:)..
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to relay-log-103.000008
Temporary relay log file is /var/lib/mysql/relay-log-103.000008
Testing mysql connection and privileges.. done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Tue Nov :: - [info] Slaves settings check done.
Tue Nov :: - [info]
172.30.1.102(172.30.1.102:) (current master)
+--172.30.1.103(172.30.1.103:) Tue Nov :: - [warning] master_ip_failover_script is not defined.
Tue Nov :: - [warning] shutdown_script is not defined.
Tue Nov :: - [info] Set master ping interval seconds.
Tue Nov :: - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from
two or more routes.Tue Nov :: - [info] Starting ping health check on 172.30.1.102(172.30.1.102:)..
Tue Nov :: - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..
Tue Nov :: - [warning] Got error on MySQL select ping: (MySQL server has gone away)
Tue Nov :: - [info] Executing SSH check script: save_binary_logs --command=test --start_pos= --binlog_dir=/data/mysql/logbin --out
put_file=/data/mastermha/cluster01//save_binary_logs_test --manager_version=0.56 --binlog_prefix=master-102Tue Nov 12 08:59:45 2019 - [warning] HealthCheck: SSH to 172.30.1.102 is NOT reachable.
Tue Nov :: - [warning] Got error on MySQL connect: (Can't connect to MySQL server on '172.30.1.102' (4))
Tue Nov :: - [warning] Connection failed time(s)..
Tue Nov :: - [warning] Got error on MySQL connect: (Can't connect to MySQL server on '172.30.1.102' (4))
Tue Nov :: - [warning] Connection failed time(s)..
Tue Nov :: - [warning] Got error on MySQL connect: (Can't connect to MySQL server on '172.30.1.102' (4))
Tue Nov :: - [warning] Connection failed time(s)..
Tue Nov :: - [warning] Master is not reachable from health checker!
Tue Nov :: - [warning] Master 172.30.1.102(172.30.1.102:) is not reachable!
Tue Nov :: - [warning] SSH is NOT reachable.
Tue Nov :: - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and /etc/mha/cluster
.conf again, and trying to connect to all servers to check server status..Tue Nov :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Tue Nov :: - [info] Reading application default configuration from /etc/mha/cluster01.conf..
Tue Nov :: - [info] Reading server configuration from /etc/mha/cluster01.conf..
Tue Nov :: - [info] GTID failover mode =
Tue Nov :: - [info] Dead Servers:
Tue Nov :: - [info] 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Alive Servers:
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:)
Tue Nov :: - [info] Alive Slaves:
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:) Version=5.5.-MariaDB (oldest major version between slaves) log-bin:enabled
Tue Nov :: - [info] Replicating from 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Tue Nov :: - [info] Checking slave configurations..
Tue Nov :: - [info] Checking replication filtering settings..
Tue Nov :: - [info] Replication filtering check ok.
Tue Nov :: - [info] Master is down!
Tue Nov :: - [info] Terminating monitoring script.
Tue Nov :: - [info] Got exit code (Master dead).
Tue Nov :: - [info] MHA::MasterFailover version 0.56.
Tue Nov :: - [info] Starting master failover.
Tue Nov :: - [info]
Tue Nov :: - [info] * Phase : Configuration Check Phase..
Tue Nov :: - [info]
Tue Nov :: - [info] GTID failover mode =
Tue Nov :: - [info] Dead Servers:
Tue Nov :: - [info] 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Checking master reachability via MySQL(double check)...
Tue Nov :: - [info] ok.
Tue Nov :: - [info] Alive Servers:
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:)
Tue Nov :: - [info] Alive Slaves:
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:) Version=5.5.-MariaDB (oldest major version between slaves) log-bin:enabled
Tue Nov :: - [info] Replicating from 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Tue Nov :: - [info] Starting Non-GTID based failover.
Tue Nov :: - [info]
Tue Nov :: - [info] ** Phase : Configuration Check Phase completed.
Tue Nov :: - [info]
Tue Nov :: - [info] * Phase : Dead Master Shutdown Phase..
Tue Nov :: - [info]
Tue Nov :: - [info] Forcing shutdown so that applications never connect to the current master..
Tue Nov :: - [warning] master_ip_failover_script is not set. Skipping invalidating dead master IP address.
Tue Nov :: - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Tue Nov :: - [info] * Phase : Dead Master Shutdown Phase completed.
Tue Nov :: - [info]
Tue Nov :: - [info] * Phase : Master Recovery Phase..
Tue Nov :: - [info]
Tue Nov :: - [info] * Phase 3.1: Getting Latest Slaves Phase..
Tue Nov :: - [info]
Tue Nov :: - [info] The latest binary log file/position on all slaves is master-102.000004:
Tue Nov :: - [info] Latest slaves (Slaves that received relay log files to the latest):
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:) Version=5.5.-MariaDB (oldest major version between slaves) log-bin:enabled
Tue Nov :: - [info] Replicating from 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Tue Nov :: - [info] The oldest binary log file/position on all slaves is master-102.000004:
Tue Nov :: - [info] Oldest slaves:
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:) Version=5.5.-MariaDB (oldest major version between slaves) log-bin:enabled
Tue Nov :: - [info] Replicating from 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Tue Nov :: - [info]
Tue Nov :: - [info] * Phase 3.2: Saving Dead Master's Binlog Phase..
Tue Nov :: - [info]
Tue Nov :: - [warning] Dead Master is not SSH reachable. Could not save it's binlogs. Transactions that were not sent to the latest
slave (Read_Master_Log_Pos to the tail of the dead master's binlog) were lost.Tue Nov 12 08:59:53 2019 - [info]
Tue Nov :: - [info] * Phase 3.3: Determining New Master Phase..
Tue Nov :: - [info]
Tue Nov :: - [info] Finding the latest slave that has all relay logs for recovering other slaves..
Tue Nov :: - [info] All slaves received relay logs to the same position. No need to resync each other.
Tue Nov :: - [info] Searching new master from slaves..
Tue Nov :: - [info] Candidate masters from the configuration file:
Tue Nov :: - [info] 172.30.1.103(172.30.1.103:) Version=5.5.-MariaDB (oldest major version between slaves) log-bin:enabled
Tue Nov :: - [info] Replicating from 172.30.1.102(172.30.1.102:)
Tue Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Tue Nov :: - [info] Non-candidate masters:
Tue Nov :: - [info] Searching from candidate_master slaves which have received the latest relay log events..
Tue Nov :: - [info] New master is 172.30.1.103(172.30.1.103:)
Tue Nov :: - [info] Starting master failover..
Tue Nov :: - [info]
From:
172.30.1.102(172.30.1.102:) (current master)
+--172.30.1.103(172.30.1.103:) To:
172.30.1.103(172.30.1.103:) (new master)
Tue Nov :: - [info]
Tue Nov :: - [info] * Phase 3.3: New Master Diff Log Generation Phase..
Tue Nov :: - [info]
Tue Nov :: - [info] This server has all relay logs. No need to generate diff files from the latest slave.
Tue Nov :: - [info]
Tue Nov :: - [info] * Phase 3.4: Master Log Apply Phase..
Tue Nov :: - [info]
Tue Nov :: - [info] *NOTICE: If any error happens from this phase, manual recovery is needed.
Tue Nov :: - [info] Starting recovery on 172.30.1.103(172.30.1.103:)..
Tue Nov :: - [info] This server has all relay logs. Waiting all logs to be applied..
Tue Nov :: - [info] done.
Tue Nov :: - [info] All relay logs were successfully applied.
Tue Nov :: - [info] Getting new master's binlog name and position..
Tue Nov :: - [info] master-103.000001:
Tue Nov :: - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='172.30
.1.103', MASTER_PORT=3306, MASTER_LOG_FILE='master-103.000001', MASTER_LOG_POS=403, MASTER_USER='copy', MASTER_PASSWORD='xxx';Tue Nov 12 08:59:53 2019 - [warning] master_ip_failover_script is not set. Skipping taking over new master IP address.
Tue Nov :: - [info] Setting read_only= on 172.30.1.103(172.30.1.103:)..
Tue Nov :: - [info] ok.
Tue Nov :: - [info] ** Finished master recovery successfully.
Tue Nov :: - [info] * Phase : Master Recovery Phase completed.
Tue Nov :: - [info]
Tue Nov :: - [info] * Phase : Slaves Recovery Phase..
Tue Nov :: - [info]
Tue Nov :: - [info] * Phase 4.1: Starting Parallel Slave Diff Log Generation Phase..
Tue Nov :: - [info]
Tue Nov :: - [info] Generating relay diff files from the latest slave succeeded.
Tue Nov :: - [info]
Tue Nov :: - [info] * Phase 4.2: Starting Parallel Slave Log Apply Phase..
Tue Nov :: - [info]
Tue Nov :: - [info] All new slave servers recovered successfully.
Tue Nov :: - [info]
Tue Nov :: - [info] * Phase : New master cleanup phase..
Tue Nov :: - [info]
Tue Nov :: - [info] Resetting slave info on the new master..
Tue Nov :: - [info] 172.30.1.103: Resetting slave info succeeded.
Tue Nov :: - [info] Master failover to 172.30.1.103(172.30.1.103:) completed successfully.
Tue Nov :: - [info] ----- Failover Report ----- cluster01: MySQL Master failover 172.30.1.102(172.30.1.102:) to 172.30.1.103(172.30.1.103:) succeeded Master 172.30.1.102(172.30.1.102:) is down! Check MHA Manager logs at node104.yinzhengjie.org.cn:/data/mastermha/cluster01/manager.log for details. Started automated(non-interactive) failover.
The latest slave 172.30.1.103(172.30.1.103:) has all relay logs for recovery.
Selected 172.30.1.103(172.30.1.103:) as a new master.
172.30.1.103(172.30.1.103:): OK: Applying all logs succeeded.
Generating relay diff files from the latest slave succeeded.
172.30.1.103(172.30.1.103:): Resetting slave info succeeded.
Master failover to 172.30.1.103(172.30.1.103:) completed successfully.
[root@node104.yinzhengjie.org.cn ~]#
[root@node104.yinzhengjie.org.cn ~]# cat /data/mastermha/cluster01/manager.log #查看日志信息,我们可以看到master的切换过程
[root@node103.yinzhengjie.org.cn ~]# cat /etc/my.cnf
[mysqld]
server-id =
binlog_format = row
read-only = on
relay_log = relay-log-
relay_log_index = relay-log-.index
log_bin = /data/mysql/logbin/master-
skip_name_resolve =
relay_log_purge =
character-set-server = utf8mb4
default_storage_engine = InnoDB
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock [mysqld_safe]
log-error = /var/log/mariadb/mariadb.log
pid-file = /var/run/mariadb/mariadb.pid !includedir /etc/my.cnf.d
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is
Server version: 5.5.-MariaDB MariaDB Server Copyright (c) , , Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
MariaDB [(none)]> SHOW SLAVE STATUS\G #由于当前节点已经被MHA切换为master,因此它就没有slave配置了
Empty set (0.00 sec) MariaDB [(none)]>
MariaDB [(none)]> SHOW VARIABLES LIKE 'read_only'; #尽管我们配置"read_only"功能,但是切换master后MHA会自动将其关闭!
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| read_only | OFF |
+---------------+-------+
row in set (0.01 sec) MariaDB [(none)]>
MariaDB [(none)]> QUIT
Bye
[root@node103.yinzhengjie.org.cn ~]#
[root@node103.yinzhengjie.org.cn ~]#
查看slave节点的复制信息
8>.温馨提示
虽说我们实现了master自动切换,但ProxySQL调度器依然需要我们手动去修改一下master节点,不过相对来说要简单的多。