MySQL MHA集群

  运维

准备四台服务器
下载rpm安装包

https://github.com/yoshinorim/mha4mysql-manager/releases
https://github.com/yoshinorim/mha4mysql-node/releases

node01、node02、node03建立ssh互信
1、三台服务器分别执行

ssh-keygen -t rsa

2、node01上执行

ssh-copy-id -i ~/.ssh/id_rsa.pub root@k8s02
ssh-copy-id -i ~/.ssh/id_rsa.pub root@k8s03

3、node02上执行

ssh-copy-id -i ~/.ssh/id_rsa.pub root@k8s01
ssh-copy-id -i ~/.ssh/id_rsa.pub root@k8s03

4、node03上执行

ssh-copy-id -i ~/.ssh/id_rsa.pub root@k8s01
ssh-copy-id -i ~/.ssh/id_rsa.pub root@k8s02

node01、node02、node03上分别安装mysql5.7

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
flush privileges;

node01、node02、node03上分别创建复制账号

create user 'repl'@'172.16.0.%' identified by 'repl';
grant replication slave on *.* to 'repl'@'172.16.0.%';
flush privileges;

node01、node02、node03上分别创建管理账号

create user 'manager'@'172.16.0.%' identified by 'manager';
grant all privileges on *.* to 'manager'@'172.16.0.%';
flush privileges;

先决条件

log-bin=mysql-bin
binlog_format=row
log_slave_updates=1
gtid_mode=ON
enforce_gtid_consistency=ON

node01配置

innodb_file_per_table
log-bin=mysql-bin
read_only
server_id=0
skip_name_resolve=1
gtid_mode=ON
enforce_gtid_consistency=ON

node02配置

innodb_file_per_table
server_id=2
skip_name_resolve=1
read_only
relay_log_purge=0
log-bin=mysql-bin
log_slave_updates=1
gtid_mode=ON
enforce_gtid_consistency=ON

node03配置

innodb_file_per_table
server_id=3
skip_name_resolve=1
read_only
relay_log_purge=0
log-bin=mysql-bin
log_slave_updates=1
gtid_mode=ON
enforce_gtid_consistency=ON

修改server-id [端口号+主机ip尾号]

在两个从库分别配置主从同步

change master to master_host='172.16.0.5',master_port=3306,master_user='repl',master_password='repl',master_auto_position=1;
change master to master_host='172.16.0.16',master_port=3306,master_user='repl',master_password='repl',master_log_file='mysql-bin.000008',master_log_pos=518;

node01、node02、node03上分别安装hma数据节点
perl环境依赖

yum -y install perl-DBD-MySQL perl-CPAN*

manager节点执行

mkdir -p /etc/mastermha/{app1,scripts}
masterha_check_ssh --conf=/etc/mastermha/app1.cnf 
yum -y install mysql
ln -s /usr/local/mysql/bin/* /usr/local/bin/
masterha_check_repl --conf=/etc/mastermha/app1.cnf
nohup masterha_manager  --conf=/etc/mastermha/app1.cnf --remove_dead_master_conf --ignore_last_failover > /etc/mastermha/app1/manager.log < /dev/null 2>&1 &
masterha_check_status --conf=/etc/mastermha/app1.cnf
tail -n20 /etc/mastermha/app1/manager.log
masterha_stop --conf=/etc/mastermha/app1.cnf
ip addr add 172.16.0.100/24 dev ens192
masterha_master_switch --conf=/etc/mastermha/app1.cnf --master_state=alive --new_master_host=172.16.0.5 --orig_master_is_new_slave
rm -rf  /etc/mastermha/app1/app1.failover.complete
change master to master_auto_position=0;
change master to master_host='172.16.0.5',master_port=3306,master_user='repl',master_password='repl',master_auto_position=1;
start slave;

LEAVE A COMMENT

Captcha Code