MySQL5.5 主主集群配置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36294875/article/details/80332845
  • MySQL主主集群的复制,虽然不可以分担写操作,但是可以分担读操作,接下来配置双主集群

    master1: 172.25.23.100 server60.com mysql5.5编译安装
    master2: 172.25.23.14 server14.com mysql5.5编译安装

  • 修改master的配置文件如下

server-id       = 10
log-bin=mysql-bin
log-bin-index=mysql-bin.index
relay-log = relay-mysql
relay-log-index = relay-mysql.index
auto-increment-increment = 2
auto-increment-offset = 1
innodb_file_per_table = 1
datadir= /mysql/mydata
  • 修改从服务器的配置文件如下
server-id       = 20
log-bin = mysql-bin
relay-log=relay-log
relay-log-index=relay-log.index
innodb_file_per_table = 1
datadir= /mysql/mydata
auto-increment-increment = 2
auto-increment-offset = 2
  • 然后启动两个节点
  • 查看两个主节点的日志信息状态
  • master 1
    这里写图片描述
  • master 2
    这里写图片描述

  • 然后授权用户双方用户

  • master 1:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'172.25.23.%' IDENTIFIED BY 'replpass';
Query OK, 0 rows affected (0.00 sec)
  • master 2:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'172.25.23.%' IDENTIFIED BY 'replpass';
Query OK, 0 rows affected (0.01 sec)
  • 分别指定对方为master节点
  • master 1
mysql> CHANGE MASTER TO MASTER_HOST='172.25.23.14',MASTER_USER='repluser',MASTER_PASSWORD='replpass',MASTER_PORT=3306,MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=1573,MASTER_CONNECT_RETRY=10;
Query OK, 0 rows affected (0.55 sec)
  • master 2
mysql> CHANGE MASTER TO MASTER_HOST='172.25.23.100',MASTER_USER='repluser',MASTER_PASSWORD='replpass',MASTER_PORT=3306,MASTER_LOG_FILE='mysql-bin.000001',MASTER_LOG_POS=1578,MASTER_CONNECT_RETRY=10;
Query OK, 0 rows affected (0.00 sec)
  • 双主模型,本质上就是互为master的主从架构,接下来启用从节点
  • master 1
mysql> start slave;
  • master 2
mysql> START SLAVE;
Query OK, 0 rows affected (0.00 sec)
  • 并且在两个节点上面创建数据库,查看是否进行了同步
  • master 1
mysql> create database testmaster1;
Query OK, 1 row affected (0.05 sec)
  • 查看master 2已经进行了同步
    这里写图片描述
  • master 2上面创建testmaster2
mysql> CREATE database testmaster2;
Query OK, 1 row affected (0.06 sec)
  • master上面查看是否发生改变
    这里写图片描述
阅读更多

没有更多推荐了,返回首页