目录
一、概述
1.概念
2.组成
3.特点
4.工作原理
二、案例介绍
1.192.168.42.3
2.192.168.42.4
3.192.168.42.5
4.192.168.42.6
三、实际构建MHA
1.ssh免密登录
1.1 所有节点配置hosts
1.2 192.168.42.3
1.3 192.168.42.4
1.4 192.168.42.5
1.5 192.168.42.6
1.6 测试
2.主从复制
2.1 master
2.2 slave(两个都要配)
2.3 验证
3.MHA安装
3.1 所有节点安装perl环境
3.2 node
3.2.1 所有节点安装node
3.2.2 验证
3.3 manager
3.3.1 安装
3.3.2 脚本说明
3.3.3 配置文件建立
3.3.4 目录创建
3.3.5 测试MHA
3.3.6 启动命令
3.3.7 启动时masterIP异常
4.测试
5.故障恢复
用作manager(MHA),即mgt
用作master
用作slave1
用作slave2
注:192.168.42.4 | 5 | 6,为node
vim /etc/hosts
192.168.42.3 mgt
192.168.42.4 master
192.168.42.5 slave1
192.168.42.6 slave2
ssh-keygen
for i in 4 5 6;do ssh-copy-id [email protected].$i;done
ssh-keygen
for i in 3 5 6;do ssh-copy-id [email protected].$i;done
ssh-keygen
for i in 4 3 6;do ssh-copy-id [email protected].$i;done
ssh-keygen
for i in 4 5 3;do ssh-copy-id [email protected].$i;done
for i in 3 4 5;do ssh 192.168.42.$i hostname;done
vim /etc/my.cnf
[mysqld]
server-id = 20
log-bin = master-bin
log-slave-updates = true
systemctl restart mariadb
mysql -e "grant replication slave on *.* to 'myslave'@'192.168.42.%' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.42.%' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.42.3' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.42.5' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.42.6' identified by '123.com';"
mysql -e "show master status";
vim /etc/my.cnf
server-id=30
log-bin=master-bin
relay-log=relay-log-bin
relay-log-index=relay-log-bin.index
systemctl restart mariadb
mysql -e "grant replication slave on *.* to 'myslave'@'192.168.42.%' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.42.%' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.42.3' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.42.5' identified by '123.com';"
mysql -e "grant all privileges on *.* to 'mha'@'192.168.42.6' identified by '123.com';"
mysql -e "change master to master_host='192.168.42.4',master_user='myslave',master_password='123.com',master_log_file='master-bin.000003',master_log_pos=1002;"
mysql -e "slave start;"
master
mysql -e "create database ea;"
slave1
mysql -e "show databases;"
slave2
mysql -e "show databases;"
yum install epel-release -y
yum -y install perl-DBD-MySQL perl-ExtUtils-MakeMaker perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes perl-CPAN
tar xf mha4mysql-node-0.57.tar.gz
cd mha4mysql-node-0.57
perl Makefile.PL && make && make install
cd /usr/local/bin
看到脚本就OK
tar xf mha4mysql-manager-0.57.tar.gz
cd /root/mha4mysql-manager-0.57
perl Makefile.PL && make && make install
cp samples/scripts/master_ip_failover /usr/local/bin/
cp samples/scripts/master_ip_online_change /usr/local/bin/
master_ip_failover 自动切换时 VIP 管理的脚本
master_ip_online_change 在线切换时 vip 的管理
power_manager 故障发生后关闭主机的脚本
send_report 因故障切换后发送报警的脚本
mkdir /etc/masterha
vim /etc/masterha/app1.cnf
mkdir /var/log/masterha/app1
vim /usr/local/bin/master_ip_failover
masterha_check_ssh --conf=/etc/masterha/app1.cnf
masterha_check_repl --conf=/etc/masterha/app1.cnf
nohup masterha_manager --conf=/etc/masterha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/masterha/app1/manager.log 2>&1 &
需要工程手动配置VIP
停用master的mariadb服务
systemctl stop mariadb
切换到slave1上
ip a
成功。
修改app1.cnf启动配置:添加master主机配置信息
分别在slave上重新指定master主机及binlog日志同步信息