Mysql's master-slave replication function (create a slave library with innobackupex backup)


Demo environment:

OS version: linux-7.3-x86_64

Database version: mysql-5.7.19-x86_64


master master server: 192.168.56.13
slave slave server: 192.168.56.14


--192.168.56.13 master operation

--User innobackupex full backup, drag it to the slave (192.168.56.14).
[root@single-instance innobackupex_dir]# innobackupex --defaults-file=/etc/my.cnf   --user=bkpuser --password=S3cret2233$  /mysql/innobackupex_dir/

--Package full_bak_20180419.tar.gz for full backup
[root@single-instance 2018-04-19_20-50-29]# pwd
/mysql/innobackupex_dir/2018-04-19_20-50-29

[root@single-instance 2018-04-19_20-50-29]# tar -zcvf /mysql/innobackupex_dir/full_bak_20180419.tar.gz *


--The master's backup is sent to the slave host
[root@single-instance innobackupex_dir]# scp full_bak_20180419.tar.gz [email protected]:/mysql/innobackupex_dir/



--create replication user repl
mysql> CREATE USER 'repl'@'192.168.56.%' IDENTIFIED BY 'replPwd8!';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.56.%';
Query OK, 0 rows affected (0.01 sec)




--192.168.56.14 slave operation

--unzip
[root @ oracle11g innobackupex_dir] # tar xivfz full_bak_20180419.tar.gz -C / var / lib / mysql /

-- Grant permissions (imported by root user)
[root@oracle11g innobackupex_dir]# chown -R mysql:mysql /var/lib/mysql/

-- restore consistency
[root@oracle11g mysql]# innobackupex --apply-log /var/lib/mysql

--Attachment: Problems encountered
InnoDB: Log file ./ib_logfile1 is of different size 50331648 bytes than other log files 9437184 bytes!
InnoDB: Plugin initialization aborted with error Generic error
xtrabackup: innodb_init(): Error occured.
--transfer ib_logfile1 file
[root@oracle11g mysql]# mv ib_logfile1 /mysql/innobackupex_dir/



--Copy master's my.cnf to slave
[root@oracle11g mysql]# scp [email protected]:/etc/my.cnf  /etc/my.cnf

--Modify the server-id of my.cnf to 222
[root@oracle11g mysql]# vi /etc/my.cnf
server-id=222
port = 3307

--View backup set information
[root@oracle11g mysql]# more xtrabackup_binlog_info
my-bin.000010   154



--create copy
mysql> change master to
    -> master_host='192.168.56.13',
    -> master_port=3306,
    -> master_user='repl',
    -> master_password='replPwd8!',
    -> master_log_file='my-bin.000010',
    -> master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.01 sec)

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



-- View replication information
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.56.13
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: my-bin.000010
          Read_Master_Log_Pos: 1644
               Relay_Log_File: oracle11g-relay-bin.000002
                Relay_Log_Pos: 1807
        Relay_Master_Log_File: my-bin.000010
             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: 1644
              Relay_Log_Space: 2018
              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: 111
                  Master_UUID: 76db50ab-417e-11e8-a7fe-0800273fd2bf
             Master_Info_File: /var/lib/mysql/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: 0
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)





------verify

--master library build table

mysql> use flydb
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
mysql> create table hahaha_repl_t(a int);
Query OK, 0 rows affected (0.02 sec)

mysql> insert into hahaha_repl_t values(1);
Query OK, 1 row affected (0.01 sec)



--slave library to check the existence of the table, the replication is successful

mysql> use flydb
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
mysql> select * from hahaha_repl_t;
+------+
| a    |
+------+
|    1 |
+------+
1 row in set (0.00 sec)








-- view process
--master
mysql> show processlist\G
*************************** 1. row ***************************
     Id: 43
   User: root
   Host: localhost
     db: flydb
Command: Query
   Time: 0
  State: starting
   Info: show processlist
*************************** 2. row ***************************
     Id: 57
   User: repl
   Host: 192.168.56.14:35774
     db: NULL
Command: Binlog Dump
   Time: 390
  State: Master has sent all binlog to slave; waiting for more updates
   Info: NULL
2 rows in set (0.00 sec)



--slave
mysql> show processlist\G
*************************** 1. row ***************************
     Id: 3
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 3297
  State: Waiting for master to send event
   Info: NULL
*************************** 2. row ***************************
     Id: 4
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 240
  State: Slave has read all relay log; waiting for more updates
   Info: NULL
*************************** 3. row ***************************
     Id: 5
   User: root
   Host: localhost
     db: flydb
Command: Query
   Time: 0
  State: starting
   Info: show processlist
3 rows in set (0.00 sec)




--master view slave information
mysql> show slave hosts;
+-----------+------+------+-----------+--------------------------------------+
| Server_id | Host | Port | Master_id | Slave_UUID                           |
+-----------+------+------+-----------+--------------------------------------+
|       222 |      | 3307 |       111 | cb27a082-45dd-11e8-99bd-0800275968d4 |
+-----------+------+------+-----------+--------------------------------------+
1 row in set (0.00 sec)





--Start-stop operation and status
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: 192.168.56.13
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: my-bin.000010
          Read_Master_Log_Pos: 2084
               Relay_Log_File: oracle11g-relay-bin.000002
                Relay_Log_Pos: 2247
        Relay_Master_Log_File: my-bin.000010
             Slave_IO_Running: No
            Slave_SQL_Running: No
              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: 2084
              Relay_Log_Space: 2458
              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: NULL
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: 111
                  Master_UUID: 76db50ab-417e-11e8-a7fe-0800273fd2bf
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           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
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)

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

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.56.13
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: my-bin.000010
          Read_Master_Log_Pos: 2084
               Relay_Log_File: oracle11g-relay-bin.000002
                Relay_Log_Pos: 2247
        Relay_Master_Log_File: my-bin.000010
             Slave_IO_Running: Yes
            Slave_SQL_Running: No
              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: 2084
              Relay_Log_Space: 2832
              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: NULL
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: 111
                  Master_UUID: 76db50ab-417e-11e8-a7fe-0800273fd2bf
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State:
           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
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)



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

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.56.13
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: my-bin.000010
          Read_Master_Log_Pos: 2084
               Relay_Log_File: oracle11g-relay-bin.000003
                Relay_Log_Pos: 317
        Relay_Master_Log_File: my-bin.000010
             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: 2084
              Relay_Log_Space: 2621
              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: 111
                  Master_UUID: 76db50ab-417e-11e8-a7fe-0800273fd2bf
             Master_Info_File: /var/lib/mysql/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: 0
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324849687&siteId=291194637