数据库运维
记录DBA学习成长历程

MySQL MHA高可用架构部署

1主2从,master:db01 slave:db02 db03 
MHA 高可用方案软件构成
Manager软件:选择一个从节点安装
Node软件:所有节点都要安装

准备环境

1主2从GTID

配置关键程序软连接

ln -s /app/mysql/bin/mysqlbinlog /usr/bin/mysqlbinlog
ln -s /app/mysql/bin/mysql /usr/bin/mysql

配置各节点互信

db01:
rm -rf /root/.ssh 
ssh-keygen
cd /root/.ssh 
mv id_rsa.pub authorized_keys
scp -r /root/.ssh 10.0.0.201:/root 
scp -r /root/.ssh 10.0.0.203:/root 
各节点验证
db01:
ssh 10.0.0.200 date
ssh 10.0.0.201 date
ssh 10.0.0.203 date
db02:
ssh 10.0.0.200 date
ssh 10.0.0.201 date
ssh 10.0.0.203 date
db03:
ssh 10.0.0.200 date
ssh 10.0.0.201 date
ssh 10.0.0.203 date

安装node软件(db01,db02,db03)

安装Node软件依赖包
yum install perl-DBD-MySQL -y
rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm

Manager软件安装(db03)

安装Manager软件依赖包
yum install -y perl-Config-Tiny epel-release perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes
rpm -ivh mha4mysql-manager-0.56-0.el6.noarch.rpm

在db01主库中创建mha需要的用户

grant all privileges on *.* to mha@'10.0.0.%' identified by 'mha';
在三台服务器上查询是否有这个用户:
select user,host from mysql.user;

配置文件准备(db03)

创建配置文件目录
mkdir -p /etc/mha
创建日志目录
mkdir -p /var/log/mha/app1
编辑mha配置文件
vim /etc/mha/app1.cnf
[server default]
manager_log=/var/log/mha/app1/manager 
manager_workdir=/var/log/mha/app1 
master_binlog_dir=/data/msyql/binlog 
user=mha 
password=mha 
ping_interval=2 //探测节点状态的时间间隔
repl_password=123
repl_user=repl
ssh_user=root 
[server1] 
hostname=10.0.0.200
port=3306 
[server2] 
hostname=10.0.0.201
port=3306
[server3]
hostname=10.0.0.203
port=3306

验证SSH互信状态(db03)

masterha_check_ssh --conf=/etc/mha/app1.cnf

主从状态检查(db03)

masterha_check_repl --conf=/etc/mha/app1.cnf 
注意:三台服务器关闭防火墙

开启MHA(db03)

nohup masterha_manager --conf=/etc/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null> /var/log/mha/app1/manager.log 2>&1 &

查看MHA状态

[root@db03 ~]# masterha_check_status --conf=/etc/mha/app1.cnf
app1 (pid:2890) is running(0:PING_OK), master:10.0.0.200
[root@db03 ~]# mysql -umha -pmha -h 10.0.0.200 -e "show variables like 'server_id'"
[root@db03 ~]# mysql -umha -pmha -h 10.0.0.201 -e "show variables like 'server_id'" 
[root@db03 ~]# mysql -umha -pmha -h 10.0.0.203 -e "show variables like 'server_id'"
赞(0)
MySQL学习笔记 » MySQL MHA高可用架构部署