主机名 | 系统型号 | IP地址 | 需要安装的软件 |
作用 |
master |
CentOS 7 64 位 | 192.168.115.130 | mysql 5.7、MHA node | 作为主机 |
mha | CentOS 7 64 位 | 192.168.115.128 |
MHA node 和 manager 组件 | 作为管理机 |
slave | CentOS 7 64 位 | 192.168.115.131 | mysql 5.7、MHA node | 作为从机 |
slave2 | CentOS 7 64 位 | 192.168.115.132 | mysql 5.7、MHA node | 作为从机 |
[root@slave ~]# ssh-keygen 生成密钥
[root@slave ~]# ssh-copy-id 192.168.115.128 将密钥上传给其他三台机器
vim /etc/hosts 写入内容,每个虚拟机都要写入
vim /etc/my.cnf 进入配置文件
主机
server-id=20
log-bin=master-bin
log-slave-updates=true
从机
server-id=30
log-bin=master-bin
relay-log=relay-log-bin
relay-log-index=relay-log-bin.index
主机
[root@master ~]# mysql -e "grant replication slave on *.* to 'myslave'@'192168.115.%' identified by '123.com';"
[root@master ~]# mysql -e "grant replication slave on *.* to 'myslave'@'192.168.115.%' identified by '123.com';"
[root@master ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.%' identified by '123.com';"
[root@master ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.128' identified by '123.com';"
[root@master ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.131' identified by '123.com';"
[root@master ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.132' identified by '123.com';"
从机1
[root@slave ~]# mysql -e "grant replication slave on *.* to 'myslave'@'192.168.115.%' identified by '123.com';"
[root@slave ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.%' identified by '123.com';"
[root@slave ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.130' identified by '123.com';"
[root@slave ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.132' identified by '123.com';"
[root@slave ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.128' identified by '123.com';"
从机2
[root@slave2 ~]# mysql -e "grant replication slave on *.* to 'myslave'@'192.168.115.%' identified by '123.com';"
[root@slave2 ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.%' identified by '123.com';"
[root@slave2 ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.128' identified by '123.com';"
[root@slave2 ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.130' identified by '123.com';"
[root@slave2 ~]# mysql -e "grant all privileges on *.* to 'mha'@'192.168.115.131' identified by '123.com';"
[root@master ~]# yum install epel-release -y
[root@master ~]# yum -y install perl-DBD-MySQL perl-ExtUtils-MakeMaker perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes perl-CPAN
准备一个node压缩包,解压并编译安装
[root@master ~]# tar xf mha4mysql-node-0.57.tar.gz
[root@master ~]# cd mha4mysql-node-0.57/
[root@master mha4mysql-node-0.57]# perl Makefile.PL && make && make install
[root@master mha4mysql-node-0.57]# cd /usr/local/bin
看到可执行文件 即为成功
[root@mha ~]# tar xf mha4mysql-manager-0.57.tar.gz
[root@mha ~]# cd mha4mysql-manager-0.57/
[root@mha mha4mysql-manager-0.57]# perl Makefile.PL && make && make install
[root@mha mha4mysql-manager-0.57]# cp samples/scripts/master_ip_failover /usr/local/bin/
[root@mha mha4mysql-manager-0.57]# cp samples/scripts/master_ip_online_change /usr/local/bin/
mkdir /etc/masterha
vim /etc/masterha/app1.cnf
#!/usr/bin/envperl
use strict;
use warnings FATAL => 'all';
use Getopt::Long;
my (
$command, $ssh_user,
$orig_master_host, $orig_master_ip,
$orig_master_port,
$new_master_host, $new_master_ip,
$new_master_port
);
#############################添加内容部分#########################################
my $vip = '192.168.115.200'; #指定vip的地址
my $brdc = '192.168.115.255'; #指定vip的广播地址
my $ifdev = 'ens33'; #指定vip绑定的网卡
my $key = '1'; #指定vip绑定的虚拟网卡序列号
my $ssh_start_vip = "/sbin/ifconfig ens33:$key $vip"; #代表此变量值为ifconfig ens33:1 192.168.184.200
1,1 顶端
[root@mha ~]# mkdir /etc/masterha
[root@mha ~]# vim /etc/masterha/app1.cnf
[server default]
managera_log=/var/log/masterha/app1/manager.log
manager_workdir=/var/log/masterha/app1
master_binlog_dir=/var/lib/mysql
master_ip_failover_script=/usr/local/bin/master_ip_failover
master_ip_online_change_script=/usr/local/bin/master_ip_online_change
password=manager
ping_interval=1
remote_workdir=/tmp
repl_password=123.com
repl_user=myslave
secondary_check_script=/usr/local/bin/masterha_secondary_check -s 192.168.115.131 -s 192.168.115.132
shutdown_script=""
ssh_user=root
user=mha
[server1]
hostname=192.168.115.130
port=3306
[server2]
candidate_master=1
check_repl_delay=0
hostname=192.168.115.131
port=3306
[server3]
hostname=192.168.115.132
port=3306
[root@mha bin]# masterha_check_ssh --conf=/etc/masterha/app1.cnf
[root@mha bin]# 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 &
[root@mha etc]# cd /var/log/masterha/app1/
[root@mha app1]# less manager.log
从下面的日志信息中可用看出,主机130已经停止,从机131成为新的主机