linux版本
CentOS Linux release 7.9.2009 (Core)
MHA版本
MHA 0.58
mysql版本
mysql8.0.16
MHA搭建
1.进入mysql服务,为所有节点创建mha管理用户
mysql -u root -p
create user 'mhaadmin'@'192.168.200.%' identified with mysql_native_password by 'Lunz2017';
2.为所建用户赋予权限
grant all on *.* to 'mhaadmin'@'192.168.200.%';
3.上传安装包依赖包,三台服务器均上传node文件夹,选择一台从服务器在上传manager文件夹,每台服务器需另上传mha4mysql-node-0.58-0.el7.centos.noarch.rpm和mha4mysql-manager-0.58-0.el7.centos.noarch.rpm两个安装包
将一台服务器的文件同步到另一台服务器(notes:需提前在目标服务器下新建文件夹存放同步的文件)
scp /mysqlsoft/node/* root@slave99:/mysqlsoft/node/
4.进入相关目录,安装对应目录下的相关包(涉及node和manager文件夹,按照顺序执行)
rpm -ivh /mysqlsoft/node/perl-*
rpm -ivh /mysqlsoft/mha4mysql-node-0.58-0.el7.centos.noarch.rpm (所有节点)
rpm -ivh /mysqlsoft/manager/perl-*
rpm -ivh /mysqlsoft/mha4mysql-manager-0.58-0.el7.centos.noarch.rpm (slave节点(manager))
链接:
链接:https://pan.baidu.com/s/1-yo1KjZZUvbHxrcI9Yl7-Q
提取码:fr50
5.建立免密登陆
在每个服务器上执行以下语句,然后按三个回车键即可
ssh-keygen -t rsa
6.将公钥进行互通,例:
在192.168.200.99服务器上,执行以下语句:
(从主机节点拷贝id-rsa.pub到从机192.168.200.98和192.168.200.94)
scp /root/.ssh/id_rsa.pub [email protected]:/root/id_rsa.pub
scp /root/.ssh/id_rsa.pub [email protected]:/root/id_rsa.pub
随后在从机192.168.200.98和192.168.200.94分别执行
cat /root/id_rsa.pub >> /root/.ssh/authorized_keys
(其他两台服务器操作一样)
(note:密码是111qqq.)
7.测试免密登陆是否成功,例:
在192.168.200.94服务器上验证与192.168.200.99服务器是否互通
8.修改/etc/my.cnf(均在mysqld里面追加)
vi /etc/my.cnf
#master(主节点)
relay-log = mysql-relay-log
skip_name_resolve
#slave(从节点)
relay-log = mysql-relay-log
read_only = ON
relay_log_purge = 0
skip_name_resolve
log_slave_updates = 1
9.创建mha相关目录
#manager
mkdir -p /etc/mha/app1
mkdir -p /mysqlsoft/mha/app1
#node
mkdir -p /etc/mha
10.创建mha配置文件(manager)
vi /etc/mha/mha.cnf
[server default]
user=mhaadmin
password=Lunz2017
manager_workdir=/etc/mha/app1
manager_log=/etc/mha/manager.log
remote_workdir=/mysqlsoft/mha/app1
ssh_user=root
repl_user=user_slave
repl_password=Lunz2017
ping_interval=1
master_binlog_dir=/mysqlsoft/mysql/data/
[server1]
hostname=192.168.200.94
ssh_port=22
candidate_master=1
[server2]
hostname=192.168.200.98
ssh_port=22
candidate_master=1
11.软连接(三台服务器都执行)
ln -s /mysqlsoft/mysql/bin/mysqlbinlog /usr/local/bin/mysqlbinlog
ln -s /mysqlsoft/mysql/bin/mysql /usr/local/bin/mysql
12.检查ssh
masterha_check_ssh -conf=/etc/mha/mha.cnf
13.检查状态
masterha_check_repl -conf=/etc/mha/mha.cnf
14.无问题则启动并记录日志(只在manager节点操作)
nohup masterha_manager -conf=/etc/mha/mha.cnf &> /etc/mha/manager.log &
(停止mha
masterha_stop -conf=/etc/mha/mha.cnf)