溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

mysql5.6 —>mysql5.7 GTID模式下多源復(fù)制之實(shí)戰(zhàn)案例

發(fā)布時(shí)間:2020-08-11 22:44:37 來源:ITPUB博客 閱讀:153 作者:西湖看海 欄目:MySQL數(shù)據(jù)庫
背景說明:公司有多個(gè)mysql實(shí)例,單實(shí)例多個(gè)數(shù)據(jù)庫,而且版本還是5.6,這給數(shù)據(jù)查詢分析增加了不少繁瑣的事情。所以推薦使用mysql5.6的實(shí)例多源復(fù)制到mysql5.7實(shí)例下方便數(shù)據(jù)的查詢、分析以及權(quán)限的管理


mysql5.6 —>mysql5.7 GTID模式下多源復(fù)制之實(shí)戰(zhàn)案例


環(huán)境說明:10.89.3.224  mysql5.6.39  master1
        10.89.3.225  mysql5.6.39  master2
        10.89.3.222  mysql5.7.21  slave
        OS:centos 7.4    mysql_port:3309

操作步驟
1、安裝mysql5.6 mysql5.7
    詳細(xì)過程不再重復(fù)、如有疑問歡迎參考我的博客
    http://blog.itpub.net/29987453/viewspace-2149405/


2、配置mysql master01配置
    1)配置10.89.3.224  mysql5.6.39  master1
    ##在一個(gè)復(fù)制組內(nèi)的serverid必須不一樣
    server-id = 123
    ##gtid 開啟gtid mysql5.6支持
    gtid_mode=on
    ##強(qiáng)制事務(wù)一致性,保證事務(wù)的安全
    enforce-gtid-consistency=on
    ##在從庫上記錄從主庫傳過來的日志數(shù)據(jù)
    log-slave-updates=1
    ##開啟binlog 必須的
    log_bin = master01-binlog      ##強(qiáng)烈建議設(shè)置row模式
    binlog_format = row
    ##binlog保存的日期
    expire_logs_days = 30
    #relay log在從服務(wù)器中記錄從主服務(wù)器傳過來的日志數(shù)據(jù)
    skip_slave_start=1
    ###設(shè)置master-info和relay-log 存放在table中
    master-info-repository = TABLE
    relay-log-info-repository = TABLE
    
    #指定復(fù)制的數(shù)據(jù)庫
    replicate-do-db=roket1,roket2
    ##指定忽略的數(shù)據(jù)庫(不需要復(fù)制的庫)
    replicate-ignore-               db=mysql,information_schema,performance_schema,test

    2)配置完之后重啟mysql server
    service mysqld restart
    3)登錄數(shù)據(jù)庫,創(chuàng)建主從同步賬號
    grant replication slave on *.* to 'repl'@'10.89.3.222' identified by '123456';
      flush privileges;
    4)重置binlog日志
    reset master;
    Query OK, 0 rows affected (0.01 sec)

    (root@localhost:mysql.sock) [(none)]>show binary logs;
    +------------------------+-----------+
    | Log_name               | File_size |
    +------------------------+-----------+
    | master01-binlog.000001 |       151 |
    +------------------------+-----------+

3、配置mysql master03配置
    1)配置10.89.3.225  mysql5.6.39  master2
    ##在一個(gè)復(fù)制組內(nèi)的serverid必須不一樣
    server-id = 234
    ##gtid 開啟gtid mysql5.6支持
    gtid_mode=on
    ##強(qiáng)制事務(wù)一致性,保證事務(wù)的安全
    enforce-gtid-consistency=on
    ##在從庫上記錄從主庫傳過來的日志數(shù)據(jù)
    log-slave-updates=1
    ##開啟binlog 必須的
    log_bin = master01-binlog      ##強(qiáng)烈建議設(shè)置row模式
    binlog_format = row
    ##binlog保存的日期
    expire_logs_days = 30
    #relay log在從服務(wù)器中記錄從主服務(wù)器傳過來的日志數(shù)據(jù)
    skip_slave_start=1
    ###設(shè)置master-info和relay-log 存放在table中
    master-info-repository = TABLE
    relay-log-info-repository = TABLE
    
    #指定復(fù)制的數(shù)據(jù)庫
    replicate-do-db=maya1,maya2
    ##指定忽略的數(shù)據(jù)庫(不需要復(fù)制的庫)
    replicate-ignore-               db=mysql,information_schema,performance_schema,test

    2)配置完之后重啟mysql server
    service mysqld restart
    3)登錄數(shù)據(jù)庫,創(chuàng)建主從同步賬號
    grant replication slave on *.* to 'repl'@'10.89.3.222' identified by '123456';
      flush privileges;
    4)重置binlog日志
    reset master;
    Query OK, 0 rows affected (0.01 sec)

    (root@localhost:mysql.sock) [(none)]>show binary logs;
    +------------------------+-----------+
    | Log_name               | File_size |
    +------------------------+-----------+
    | master01-binlog.000001 |       151 |
    +————————————+-----------+

4、配置slave數(shù)據(jù)庫
    1)配置配置10.89.3.222  mysql5.7.21  slave
    ##在一個(gè)復(fù)制組內(nèi)的serverid必須不一樣
    server-id = 234
    gtid_mode=on
    ##強(qiáng)制事務(wù)一致性,保證事務(wù)的安全
    enforce-gtid-consistency=on
    ##在從庫上記錄從主庫傳過來的日志數(shù)據(jù)
    log-slave-updates=1
    ##開啟binlog 必須的
    log_bin = master01-binlog      ##強(qiáng)烈建議設(shè)置row模式
    binlog_format = row
    ##binlog保存的日期
    expire_logs_days = 30
    #relay log在從服務(wù)器中記錄從主服務(wù)器傳過來的日志數(shù)據(jù)
    skip_slave_start=1
    ###設(shè)置master-info和relay-log 存放在table中
    master-info-repository = TABLE
    relay-log-info-repository = TABLE
    #配置只讀數(shù)據(jù)庫
    read_only=on

    4)重置binlog日志
    (root@localhost:mysql.sock) [(none)]>reset master;
    Query OK, 0 rows affected (0.02 sec)

    (root@localhost:mysql.sock) [(none)]>show binary logs;
    +---------------------+-----------+
    | Log_name            | File_size |
    +---------------------+-----------+
    | slave-binlog.000001 |       154 |
    +---------------------+-----------+
    1 row in set (0.00 sec)

    (root@localhost:mysql.sock) [(none)]>reset slave;
    Query OK, 0 rows affected (0.00 sec)
5、開啟主從復(fù)制
    1)關(guān)閉master1 和master2的防火墻
    2)開啟主從復(fù)制
    (root@localhost:mysql.sock) [(none)]>  CHANGE MASTER TO      MASTER_HOST = '10.89.3.225',  MASTER_PORT = 3309,   MASTER_USER = 'repl',   MASTER_PASSWORD = '123456',  MASTER_AUTO_POSITION = 1 FOR CHANNEL 'master2';
    Query OK, 0 rows affected, 2 warnings (0.02 sec)

    (root@localhost:mysql.sock) [(none)]>  CHANGE MASTER TO  MASTER_HOST = '10.89.3.224',  MASTER_PORT = 3309,   MASTER_USER = 'repl',   MASTER_PASSWORD = '123456',  MASTER_AUTO_POSITION = 1 FOR CHANNEL 'master1';
    Query OK, 0 rows affected, 2 warnings (0.02 sec)
    (root@localhost:mysql.sock) [(none)]>start slave;
    3)查看主從復(fù)制狀態(tài)
    (root@localhost:mysql.sock) [(none)]>show slave status for channel 'master1'\G
    *************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.89.3.224
                  Master_User: repl
                  Master_Port: 3309
                Connect_Retry: 60
              Master_Log_File: master01-binlog.000001
          Read_Master_Log_Pos: 151
               Relay_Log_File: mysql-relay-bin-master1.000002
                Relay_Log_Pos: 376
        Relay_Master_Log_File: master01-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: 151
              Relay_Log_Space: 591
              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: 123
                  Master_UUID: 3809e1da-25c0-11e8-93b1-080027857522
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           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: 1
         Replicate_Rewrite_DB:
                 Channel_Name: master1
           Master_TLS_Version:
1 row in set (0.00 sec)

(root@localhost:mysql.sock) [(none)]>show slave status for channel 'master2'\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.89.3.225
                  Master_User: repl
                  Master_Port: 3309
                Connect_Retry: 60
              Master_Log_File: master02-binlog.000001
          Read_Master_Log_Pos: 151
               Relay_Log_File: mysql-relay-bin-master2.000002
                Relay_Log_Pos: 376
        Relay_Master_Log_File: master02-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: 151
              Relay_Log_Space: 591
              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: 234
                  Master_UUID: ab8c56e0-25c0-11e8-93b4-0800278c8292
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           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: 1
         Replicate_Rewrite_DB:
                 Channel_Name: master2
           Master_TLS_Version:
1 row in set (0.00 sec)
    顯示 主從復(fù)制正常    
     Slave_IO_Running: Yes
           Slave_SQL_Running: Yes

6、測試核對數(shù)據(jù)
    1)登錄master1數(shù)據(jù)庫
    create database roket1;
    Query OK, 1 row affected (0.00 sec)

    (root@localhost:mysql.sock) [(none)]>create database roket2;
    Query OK, 1 row affected (0.01 sec)

    (root@localhost:mysql.sock) [(none)]>use roket1;
    Database changed
    (root@localhost:mysql.sock) [roket1]>create table t1(
        ->  id bigint not null auto_increment,
        ->  name varchar(20),
        ->  primary key(id)
        -> )engine=innodb;
    Query OK, 0 rows affected (0.02 sec)

    (root@localhost:mysql.sock) [roket1]>insert into t1 (name) values     (‘master1'),('master1'),('master1');
    Query OK, 3 rows affected (0.00 sec)
    Records: 3  Duplicates: 0  Warnings: 0
    (root@localhost:mysql.sock) [roket1]>select * from t1;
    +----+---------+
    | id | name    |
    +----+---------+
    |  1 | master1 |
    |  2 | master1 |
    |  3 | master1 |
+----+---------+

    2)登錄master2數(shù)據(jù)庫
    (root@localhost:mysql.sock) [(none)]>create database maya1;
    Query OK, 1 row affected (0.00 sec)

    (root@localhost:mysql.sock) [(none)]>create database maya2;
    Query OK, 1 row affected (0.00 sec)

    (root@localhost:mysql.sock) [(none)]>use maya1;
    Database changed
    (root@localhost:mysql.sock) [maya1]>create table t2(
        ->  id bigint not null auto_increment,
        ->  name varchar(20),
        ->  primary key(id)
        -> )engine=innodb;
    Query OK, 0 rows affected (0.02 sec)

        (root@localhost:mysql.sock) [maya1]>insert into t2 (name) values     ('master2'),('master2'),('master2') ;
    Query OK, 3 rows affected (0.00 sec)
    Records: 3  Duplicates: 0  Warnings: 0
    (root@localhost:mysql.sock) [maya1]>select * from t2;
    +----+---------+
    | id | name    |
    +----+---------+
    |  1 | master2 |
    |  2 | master2 |
    |  3 | master2 |
    +----+---------+
    3 rows in set (0.00 sec)

    3)登錄主庫
    (root@localhost:mysql.sock) [(none)]>show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | maya1               |
    | maya2              |
    | mysql              |
    | performance_schema |
    | roket1             |
    | roket2             |
    | sys                |

    (root@localhost:mysql.sock) [(none)]>
(root@localhost:mysql.sock) [(none)]>use roket1
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
(root@localhost:mysql.sock) [roket1]>show tables;
+------------------+
| Tables_in_roket1 |
+------------------+
| t1               |
+------------------+
1 row in set (0.00 sec)

(root@localhost:mysql.sock) [roket1]>select * from t1;
+----+---------+
| id | name    |
+----+---------+
|  1 | master1 |
|  2 | master1 |
|  3 | master1 |
+----+---------+
3 rows in set (0.00 sec)
(root@localhost:mysql.sock) [maya1]>use maya1
Database changed
(root@localhost:mysql.sock) [maya1]>select * from t2;
+----+---------+
| id | name    |
+----+---------+
|  1 | master2 |
|  2 | master2 |
|  3 | master2 |
+----+---------+
3 rows in set (0.00 sec)

經(jīng)核對、master1、master2的實(shí)例的數(shù)據(jù)已經(jīng)正常同步到slave,多源復(fù)制搞定
    
    總結(jié):1、首先為mysql5.7多源復(fù)制點(diǎn)歌贊
         2、解決了公司業(yè)務(wù)的需要多實(shí)例的情況下,統(tǒng)一分析數(shù)據(jù)、查詢權(quán)限控制等眾多問題
        3、解決了多實(shí)例備份麻煩的問題
        


    

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI