美文网首页
MySQL分布式集群-4.主主复制

MySQL分布式集群-4.主主复制

作者: 笨鸡 | 来源:发表于2019-06-16 21:10 被阅读0次

1.双向主从模式配置

  • mysql-slave
vim /etc/my.cnf

server-id=2
log-bin=/var/lib/mysql/mysql-bin
-----------------------------------------------------------------

mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      247 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> stop slave;
1 row in set (0.00 sec)
  • mysql-master
mysql> change master to master_host='192.168.1.111',master_port=3306,master_user='repl',master_password='repl',master_log_file='mysql-bin.000001',master_log_pos=247; 
Query OK, 0 rows affected, 2 warnings (0.06 sec)

mysql> start slave;
Query OK, 0 rows affected (0.05 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.111
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 247
               Relay_Log_File: mysqld-relay-bin.000002
                Relay_Log_Pos: 283
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB:
          ...

2.master, slave数据库主键自增设置

  • mysql-master
vim /etc/my.cnf

auto_increment_increment=2
auto_increment_offset=1
------------------------------------------------------
[root@master ~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service

mysql> create table topic (id int not null auto_increment primary key);
Query OK, 0 rows affected (0.19 sec)

mysql> show create table topic\G
*************************** 1. row ***************************
       Table: topic
Create Table: CREATE TABLE `topic` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

mysql> insert into topic values(null);
Query OK, 1 row affected (0.04 sec)

mysql> select * from topic;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)

mysql> insert into topic values(null);
Query OK, 1 row affected (0.04 sec)

mysql> select * from topic;
+----+
| id |
+----+
|  1 |
|  3 |
+----+
2 rows in set (0.00 sec)
  • mysql-slave
vim /etc/my.cnf

auto_increment_increment=2
auto_increment_offset=2
------------------------------------------------------
[root@slave~]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service

mysql> insert into topic values(null);
Query OK, 1 row affected (0.04 sec)

mysql> select * from topic;
+----+
| id |
+----+
|  1 |
|  3 |
|  4 |
+----+
3 rows in set (0.00 sec)

相关文章

  • MySQL分布式集群-4.主主复制

    1.双向主从模式配置 mysql-slave mysql-master 2.master, slave数据库主键自...

  • 6. MySQL 主从架构

    7 MySQL 集群Cluster 7.1 主从复制 7.1.1 主从复制原理 主从复制过程: 主节点收到用户请求...

  • MySQL多主模型Galera Cluster

    简要介绍 Galera Cluster for MySQL是一套基于同步复制的多主MySQL集群解决方案,使用简单...

  • Mysql分布式集群(二)主主复制和高可用

    前言 构建一个Mysql分布式集群需要对数据库的原理有较深的认识,而深奥复杂的数据库原理往往让很多读者中途放弃。本...

  • Mysql分布式部署 - 主主复制

    1,概述 主主复制,即在两台MySQL主机内都可以变更数据,而且另外一台主机也会做出相应的变更。聪明的你也许已经想...

  • mysql 主主复制

    1.环境准备: 主机IP:192.168.1.4, 192.168.1.5 操作系统:centos 7.3 ...

  • MySQL 主主复制

    环境 服务器 两台 centos6.5 (ip:192.168.1.121、192.168.1.212) 软件 ...

  • 2019-10-12

    利用LVS+Keepalived搭建Mysql双主复制高可用负载均衡环境 应用背景: MySQL复制(主主,主从....

  • MySQL应用

    MySQL Replication: 1、主/从架构: 2、主主复制: 3、半同步复制 4、复制过滤器: 5、复制...

  • Docker 搭建MySql8.0主从集群

    概念 分布式的数据库集群可以大幅提升数据库性能,MySql的集群同步原理主要为: MySql从节点从主节点下载bi...

网友评论

      本文标题:MySQL分布式集群-4.主主复制

      本文链接:https://www.haomeiwen.com/subject/fwxnfctx.html