mysql双机热备以及使用keepalived实现mysql双主高可用

本文介绍了如何在CentOS7环境下配置MySQL双主热备,并利用keepalived实现数据库IP漂移,确保高可用性。步骤包括安装MySQL,配置主主同步,设置用户权限,启动并检查同步状态,最后通过keepalived进行故障转移和健康检查。
摘要由CSDN通过智能技术生成

注:以下环境需要mysql初始环境相同,至少数据库及表结构一样,否则会出现后续无法同步数据的现象,但是依据下面部署完成后再建库和导表均可同步至另一台服务器。
环境描述:

OS:CentOS7.5_X64

MySQL-VIP:172.24.46.23(虚拟ip)

MySQL-master1:172.24.46.19

MySQL-master2:172.24.46.17

1、配置两台Mysql主主同步

[root@master ~]# yum install mysql-server mysql -y
[root@master ~]# service mysqld start
[root@master ~]# mysqladmin -u root password 123.com
[root@master ~]# vi /etc/my.cnf #开启二进制日志,设置id

[mysqld]
#backup这台设置2
server-id = 1
log-bin = mysql-bin
#忽略写入binlog日志的库
binlog-ignore-db = mysql,information_schema
#字段变化增量值
auto-increment-increment = 2
#初始字段ID为1
auto-increment-offset = 1
#忽略所有复制产生的错误
slave-skip-errors = all

[root@master ~]# service mysqld restart
如果是Centos7,则卸载mariadb,安装mysql,参考文章:https://blog.51cto.com/sf1314/2073389

安装mysql,参考文章:

mysql5.6.37 https://blog.51cto.com/sf1314/2058754

#mysql -uroot -p’密码’

先查看下log bin日志和pos值位置
show master status;
172.24.46.19上:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201123161007166.png#pic_center在这里插入图片描述

172.24.46.17上:
在这里插入图片描述

172.24.46.19上:

CREATE USER ‘replication’@‘172.24.46.17’ IDENTIFIED WITH mysql_native_password BY ‘Abc.123456’;
(建议使用这一条,下面的创建用户命令在使用过程中出现过报错:error connecting to master ‘replication@172.24.46.19:3306’ - retry-time: 60 retries: 7 message: Authentication plugin ‘caching_sha2_password’ reported error: Authentication requires secure connection.)
CREATE USER ‘replication’@‘172.24.46.17’ IDENTIFIED BY ‘Abc.123456’;

mysql> CREATE USER 'replication'@'172.24.46.17' IDENTIFIED WITH mysql_native_password BY 'Abc.123456';
mysql> grant ALL PRIVILEGES on *.* to 'replication'@'172.24.46.17' with grant option;
mysql> grant system_user on *.* to 'root';
mysql> flush  privileges;
mysql> change  master to master_host='172.24.46.17',master_user
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值