mysql主主复制配置:

HOSTNAME IPADDR PORT
节点1:my-prod01.oracle.com 192.168.10.97 3306
节点2:my-prod02.oracle.com 192.168.10.5 3306

1、修改my.cnf文件
节点1:
[mysqld]
server_id = 1
datadir = /data/mysql_3306/data
port = 3306
socket = /data/mysql_3306/run/mysql.sock
log-error=/data/mysql_3306/logs/mysqlerror.log
log-bin = /data/mysql_3306/logs/binlog
relay-log = /data/mysql_3306/logs/relaylog
binlog_format = row
skip-name-resolve
sync_binlog = 1
log_slave_updates = 1
read_only = 0

auto-increment-increment = 2

auto-increment-offset = 1

节点2:
[mysqld]
server_id = 2
datadir = /data/mysql_3306/data
port = 3306
socket = /data/mysql_3306/run/mysql.sock
log-error=/data/mysql_3306/logs/mysqlerror.log
log-bin = /data/mysql_3306/logs/binlog
relay-log = /data/mysql_3306/logs/relaylog
binlog_format = row
skip-name-resolve
sync_binlog = 1
log_slave_updates = 1
read_only = 0

auto-increment-increment = 2
auto-increment-offset = 2

#双主复制模式
auto_increment_offset表示自增长字段从哪个数开始,取值范围是1 .. 65535
auto_increment_increment表示自增长字段每次递增的量,其默认值是1,取值范围是1 .. 65535
在主主同步配置时,需要将两台服务器的auto_increment_increment增长量都配置为2,而要把auto_increment_offset分别配置为1和2.
这样避免两台服务器同时做更新时自增长字段的值之间发生冲突

mkdir -p /data/mysql_3306/data/logs/binlog
mkdir -p /data/mysql_3306/data/logs/relaylog

创建复制权限用户:
节点1:
mysql> GRANT replication slave ON *.* TO 'replicator'@'192.168.10.5' identified by 'replicator';
mysql> flush privileges;
mysql> show master status \G
*************************** 1. row ***************************
             File: binlog.000001
         Position: 120
     Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 
1 row in set (0.00 sec)
mysql> unlock tables;
Query OK, 0 rows affected (0.03 sec)

节点2:
mysql> GRANT replication slave ON *.* TO 'replicator'@'192.168.10.97' identified by 'replicator';
mysql> flush privileges;
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)

mysql> show master status \G
*************************** 1. row ***************************
             File: binlog.000001
         Position: 120
     Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 
1 row in set (0.00 sec)
mysql> unlock tables;
Query OK, 0 rows affected (0.03 sec)

互为master:
节点1:
change master to master_host='192.168.10.5', master_port=3306, master_user='replicator',master_password='replicator', master_log_file='binlog.000001',master_log_pos=120;

mysql> start slave;
Query OK, 0 rows affected (0.02 sec)
mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.10.5
                  Master_User: replicator
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000001
          Read_Master_Log_Pos: 120
               Relay_Log_File: binlog.000002
                Relay_Log_Pos: 280
        Relay_Master_Log_File: binlog.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 120
              Relay_Log_Space: 444
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 2
                  Master_UUID: 98b6f1e4-7026-11e7-b381-e8611f1a5e44
             Master_Info_File: /data/mysql_3306/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
1 row in set (0.00 sec)

节点2:
change master to master_host='192.168.10.97', master_port=3306, master_user='replicator',master_password='replicator', master_log_file='binlog.000001',master_log_pos=120;

mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.10.97
                  Master_User: replicator
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000001
          Read_Master_Log_Pos: 120
               Relay_Log_File: binlog.000002
                Relay_Log_Pos: 280
        Relay_Master_Log_File: binlog.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 120
              Relay_Log_Space: 444
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 1
                  Master_UUID: cd2fab5f-7025-11e7-b37c-e8611f1a5ff8
             Master_Info_File: /data/mysql_3306/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
1 row in set (0.00 sec)

MySQL主主模式的更多相关文章

  1. MYSQL的主从和主主复制模式

    一.复制介绍 MySQL支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维护文件的一个索引以跟踪日志循环.这些日志可以记录 ...

  2. Mysql主从同步(1) - 概念和原理介绍 以及 主从/主主模式 部署记录

    Mysql复制概念Mysql内建的复制功能是构建大型高性能应用程序的基础, 将Mysql数据分布到多个系统上,这种分布机制是通过将Mysql某一台主机数据复制到其它主机(slaves)上,并重新执行一 ...

  3. 通过keepalived搭建MySQL双主模式的高可用集群系统

    1. 配置MySQL双主模式 1.修改my.cnf配置文件 默认情况下,MySQL的配置文件是/etc/my.cnf,在配置文件的[mysqld]段添加如下内容: server-id=1 log-bi ...

  4. [转帖]【MySQL+keepalived】用keepalived实现MySQL主主模式的高可用

    [MySQL+keepalived]用keepalived实现MySQL主主模式的高可用 https://www.jianshu.com/p/8694d07595bc 一.实验说明 MySQL主主模式 ...

  5. mysql双主模式方案

    MySQL双主(主主)架构方案   在企业中,数据库高可用一直是企业的重中之重,中小企业很多都是使用mysql主从方案,一主多从,读写分离等,但是单主存在单点故障,从库切换成主库需要作改动.因此,如果 ...

  6. MySQL主主模式+Keepalived高可用

    今天闲来无事,打算搭建一个MySQL的高可用架构,采用的是MySQL的主主结构,再外加Keepalived,对外统一提供虚IP.先来说说背景吧,现在的项目为了高可用性,都是避免单节点的存在的,比如,我 ...

  7. MySQL集群搭建(2)-主主从模式

    1 环境准备 上次我们搭建了主备架构,如下所示 这次我们的搭建目标是 具体配置信息 IP 系统 端口 MySQL版本 节点 读写 说明 192.168.41.83 Centos6.8 3306 5.7 ...

  8. MySQL复制环境(主从/主主)部署总结性梳理

    Mysql复制概念说明Mysql内建的复制功能是构建大型,高性能应用程序的基础.将Mysql的数据分布到多个系统上去,这种分布的机制,是通过将Mysql的某一台主机的数据复制到其它主机(slaves) ...

  9. MySQL双主(主主)架构方案

    在企业中,数据库高可用一直是企业的重中之重,中小企业很多都是使用mysql主从方案,一主多从,读写分离等,但是单主存在单点故障,从库切换成主库需要作改动.因此,如果是双主或者多主,就会增加mysql入 ...

随机推荐

  1. Markdown在线编辑及预览

    推荐一款不错的Markdown语法手册,最可贵的是支持在线编辑预览: Cmd Markdown简介 Cmd Markdown语法手册及在线编辑 补充一些使用技巧: MarkDown实现段首缩进:「Ma ...

  2. ssm中web配置各框架的配置文件路径方式

    一.在web文件中配置 使用逗号隔开 二.在applicationContext.xml文件中配置或引用 以下是引用方式 注: <import />标签要放在所有bean配置的最前面.  

  3. 企业微信的corpsecret在哪里?

      问题: 查看“企业微信”的官方开发文档,在“获取access_token”部分提到,使用GET请求方法,访问 https://qyapi.weixin.qq.com/cgi-bin/gettoke ...

  4. muduo

    https://blog.csdn.net/zxm342698145/article/details/80689016 https://blog.csdn.net/u010087886/article ...

  5. 神经网络训练技巧:训练参数初始化、Drop out及Batch Normalization

    参数初始化: xavier初始化: https://blog.csdn.net/VictoriaW/article/details/73000632 条件:优秀的初始化应该使得各层的激活值和梯度的方差 ...

  6. 4--面试总结-promise

    promise异步原理: 定义:promise是异步编程的解决方案,可以解决异步回调地狱的问题: 原理:三种状态两种结果的一个状态机:三种状态(pending,fulfilled,rejected)两 ...

  7. bzoj2802 [Poi2012]Warehouse Store 贪心+堆

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=2802 题解 我一开始想到了一个比较麻烦的做法. 把每一天按照 \(b_i\) 从小到大排序,\ ...

  8. 绑定class -vue

    1.值为对象 :class = "{ 'text-red': isActive }" data () { return { isActive : true } } :class = ...

  9. BZOJ2160 拉拉队排练 PAM

    题意简述 询问一个串中所有奇回文按照长度降序排列,前k个奇回文的长度乘积. 做法 回文自动机(PAM)模板题. 维护每个回文自动机的结点回文串出现次数,跳fail得到每个长度的出现次数,双关键字排序后 ...

  10. SpringToolSuit(STS)添加了Lombok后仍然报错

    参见这篇博客 https://blog.csdn.net/qq_27442469/article/details/90612918 上面步骤做完后,在项目右键->Maven->Update ...