mysql 主从复制-双主(互为主从)
程序员文章站
2024-03-08 15:03:16
...
MySQL双主架构
主机名 | ip | 用途 |
---|---|---|
mysql-server1 | 192.168.10.11 | 主1 |
mysql-server2 | 192.168.10.12 | 主2 |
ps. 要求:
1、主从版本一致
2、主从数据一致
yum 方式安装mysql
# 两台服务器均安装mysql
[aaa@qq.com ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
[aaa@qq.com ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
[aaa@qq.com ~]# yum -y install yum-utils #安装yum工具包
[aaa@qq.com ~]# vim /etc/yum.repos.d/mysql-community.repo #修改如下
[aaa@qq.com ~]# yum install -y mysql-community-server
启动服务
[aaa@qq.com ~]# systemctl start mysqld
设置开机启动
[aaa@qq.com ~]# systemctl enable mysqld
修改密码:
略。。。
配置主从
# 两台均配置,注意不一样的地方
[aaa@qq.com ~]# vim /etc/my.cnf # 在[mysqld]添加
log-bin=mysql-bin #开启二进制日志
log-bin-index=binlog.index
server-id=1 #设置server-id
# auto_increment_increment=2 # 自增减步长
# auto_increment_offset=2 # 自增减开始
[aaa@qq.com ~]# systemctl restart mysqld
# 进入数据库,创建replication账户
mysql> CREATE USER 'repl'@'192.168.10.12' IDENTIFIED BY '123456';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.10.12';
mysql> flush privileges;
# 记录master 状态
mysql> show master status\G
File: mysql-bin.000002
Position: 567
Binlog_Do_DB:
Binlog_Ignore_DB:
# 配置从库
CHANGE MASTER TO MASTER_HOST='192.168.10.12',
MASTER_USER='repl',
MASTER_PASSWORD='123456',
MASTER_LOG_FILE='mysql-bin.000002',
MASTER_LOG_POS=567;
# 两服务器均配置成功后
mysql> start slave;
mysql> show slave status\G
下一篇: Centos7.5下HDP集群搭建(三)