目录
高可用集群MHA
环境准备
设置服务器免密通联
修改主机名和hosts文件(四台)
四台服务器相同操作
四台服务器相同操作-关闭防火墙
四台服务器-免密配置-生成密钥
四台服务器-免密配置-复制密钥
测试是否免密登陆其他主机
master操作-主从复制配置
slave1从库操作
slave2操作
manager操作
对各个节点进行检测
检查管理的MySQL复制集群的连接配置参数是否OK
MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是一套优秀的作为MySQL高可用性环境下故障切换和主从提升的高可用软件。在MySQL故障切换过程中,MHA能做到在0~30秒之内自动完成数据库的故障切换操作,并且在进行故障切换的过程中,MHA能在最大程度上保证数据的一致性,以达到真正意义上的高可用。
环境准备 CentOS Linux release 7.5.1804 (Core)
角色 节点 ip 说明
manager node1 192.168.1.85 管理
master node2 192.168.1.86 主
slave1 node3 192.168.1.87 从
slave2 node4 192.168.1.88 从
[root@localhost1 ~]# hostname node1
[root@localhost2 ~]# hostname node2
[root@localhost3 ~]# hostname node3
[root@localhost4~]# hostname node4
[root@localhost ~]# vim /etc/hosts
192.168.1.85 node1
192.168.1.86 node2
192.168.1.87 node3
192.168.1.88 node4
[root@node1 ~]# systemctl stop firewalld;setenforce 0
[root@node2 ~]# systemctl stop firewalld;setenforce 0
[root@node3 ~]# systemctl stop firewalld;setenforce 0
[root@node4 ~]# systemctl stop firewalld;setenforce 0
[root@node1 ~]# ssh-keygen -t rsa
[root@node2 ~]# ssh-keygen -t rsa
[root@node3 ~]# ssh-keygen -t rsa
[root@node4 ~]# ssh-keygen -t rsa
[root@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node1
[root@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node1
[root@node3 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node1
[root@node4 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node1
[root@node1 ~]# cat /root/.ssh/authorized_keysau
[root@node1 ~]# scp .ssh/authorized_keys root@node2:.ssh/
[root@node1 ~]# scp .ssh/authorized_keys root@node3:.ssh/
[root@node1 ~]# scp .ssh/authorized_keys root@node4:.ssh/
[root@node1 ~]# ssh node2
[root@node1 ~]# ssh node3
[root@node1 ~]# ssh node4
[root@node2 ~]# yum -y install epel-release
[root@node2 ~]# yum -y install mariadb mariadb-server
[root@node2 ~]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm
root@node2 ~]# vim /etc/my.cnf #修改配置文件
[mysqld]
server-id = 1
log-bin = master-log
relay-log = relay-log
skip_name_resolve
[root@node2 ~]# systemctl start mariadb 启动mariadb服务
[root@node2 ~]# mysql进入mariadb
#授权用户给从库使用
MariaDB [(none)]> grant replication slave on *.* to slave@'%' identified by '123';
#授权用户给manager管理master使用
MariaDB [(none)]> grant all on *.* to mha@'%' identified by '123';
MariaDB [(none)]> show master status;
+-------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-log.000003 | 529 | |
| +-------------------+----------+--------------+------------------+
1 row in set (0.00 sec) 每个master-log值都不一样 按照自己那个值
[root@node3 ~]# yum -y install mariadb mariadb-server epel-release
[root@node3 ~]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm
[root@node3 ~]# vim /etc/my.cnf
[mysqld]
server-id = 2
relay-log = relay-log
log-bin = master-log
read_only = ON
relay_log_purge = 0
skip_name_resolve
log_slave_updates = 1
[root@node2 ~]# systemctl start mariadb 启动mariadb服务
[root@node2 ~]#mysql
MariaDB [(none)]> change master to master_host='主库IP',master_user='slave',master_password='123',master_log_file='master-log.000003',master_log_pos=529;
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status \G
授权管理manager
grant all on *.* to mha@'%' identified by '123';
grant all on *.* to slave@'%' identified by '123';
[root@node4 ~]# yum -y install mariadb mariadb-server epel-release
[root@node4 ~]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm
[root@node3 ~]# vim /etc/my.cnf 配置文件修改
server-id = 3
[mysqld]
relay-log = relay-log
log-bin = master-log
read_only = ON
relay_log_purge = 0
skip_name_resolve
log_slave_updates = 1
[root@node2 ~]# systemctl start mariadb 启动mariadb服务
[root@node2 ~]#mysql
MariaDB [(none)]> change master to master_host='主库IP',master_user='slave',master_password='123',master_log_file='master-log.000003',master_log_pos=529;
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status \G
授权管理manager
grant all on *.* to mha@'%' identified by '123';
grant all on *.* to slave@'%' identified by '123';
[root@node1 ~]# yum -y install mariadb mariadb-server epel-release
[root@node1 ~]#根据需要获取对应版本的安装包,再进行安装。
yum -y install mha4mysql-node-0.56-0.el6.noarch.rpm mha4mysql-manager-0.56-0.el6.noarch.rpm
创建manager配置文件
[root@node1 ~]# mkdir /etc/mha_master
[root@node1 ~]# vim /etc/mha_master/mha.cnf
[server default]
user=mha
password=123
manager_workdir=/etc/mha_master/app1
manager_log=/etc/mha_master/manager.log
remote_workdir=/mydata/mha_master/app1
ssh_user=root
repl_user=slave
repl_password=123
ping_interval=1
[server1] hostname=192.168.174.131
ssh_port=22
candidate_master=1
[server2] hostname=192.168.174.132
ssh_port=22
candidate_master=1
[server3] hostname=192.168.174.133
ssh_port=22
candidate_master=1
:wq保存退出
[root@node1 ~]# masterha_check_ssh --conf=/etc/mha_master/mha.cnf
[root@node1 ~]# masterha_check_repl --conf=/etc/mha_master/mha.cnf
最后一步出现错误通常是授权问题,在三个主从服务器中进入mysql 从新授权即可。