用xtrabackup工具建立slave節點

甲骨文技術支援發表於2017-02-21

xtrabackup安裝和備份方法等請先參考我的另一篇部落格 http://blog.itpub.net/20893244/viewspace-2133530/
環境:
master ip:192.168.3.171
slave    ip: 192.168.3.173
mysql版本:
(root@localhost) [gldb]> select version();
+------------+
| version()  |
+------------+
| 5.7.17-log |
+------------+
1 row in set (0.00 sec)

用xtrabackup工具建立slave節點需要七步驟,我們一步一步操作

一.在master節點完整備份資料

  1. innobackupex --defaults-file=/etc/my.cnf --host=oracle11gtest --user=xtrabk --parallel=4 --password=onlybackupgl --extra-lsndir=/alidata1/mysqlbackup/mysql_full --stream=tar /tmp | gzip > /alidata1/mysqlbackup/mysql_full/xtra_fullbak_2017-02-20.tar.gz
二.複製和準備備份集

1.把備份集複製到slave端

  1. scp -r /alidata1/mysqlbackup/mysql_full root@192.168.3.173:/alidata1/mysqldata/mysqlbackup
2.在slave端解壓備份集

  1. tar -xzvf xtra_fullbak_2017-02-20.tar
3.準備資料,執行innobackupex命令附加--apply-log引數

  1. innobackupex --apply-log /alidata1/mysqldata/mysqlbackup/mysql_full
三.建立複製環境專用賬戶並賦予許可權

  1. create user repl@'192.168.3.173';
  2. grant replication slave on *.* to repl identified by 'replmysql';
四.配置slave節點的初始化引數

從master端複製到slave端,還是用scp命令;
在slave端修改初始化檔案,把server_id修改為一個非0的值
啟動資料庫

  1. mysqld_safe --defaults-file=/etc/my.cnf &
五.配置slave節點複製環境

檢視xtrabackup_binlog_info檔案裡的資料

  1. [root@mysqltest mysql_full]# more xtrabackup_binlog_info
  2. mysql-bin.000016 1884
執行change masger命令

  1. change master to
  2. master_host='192.168.3.171',
  3. master_port=3306,
  4. master_user='repl',
  5. master_password='replmysql',
  6. master_log_file='mysql-bin.000016',
  7. master_log_pos=1884;
執行start slave命令

  1. mysql > start slave;
六.檢查

  1. (root@localhost) [(none)]> show slave status \G;
  2. *************************** 1. row ***************************
  3.                Slave_IO_State: Waiting for master to send event
  4.                   Master_Host: 192.168.3.171
  5.                   Master_User: repl
  6.                   Master_Port: 3306
  7.                 Connect_Retry: 60
  8.               Master_Log_File: mysql-bin.000016
  9.           Read_Master_Log_Pos: 3631
  10.                Relay_Log_File: mysqltest-relay-bin.000002
  11.                 Relay_Log_Pos: 2067
  12.         Relay_Master_Log_File: mysql-bin.000016
  13.              Slave_IO_Running: Yes
  14.             Slave_SQL_Running: Yes
  15.               Replicate_Do_DB:
  16.           Replicate_Ignore_DB:
  17.            Replicate_Do_Table:
  18.        Replicate_Ignore_Table:
  19.       Replicate_Wild_Do_Table:
  20.   Replicate_Wild_Ignore_Table:
  21.                    Last_Errno: 0
  22.                    Last_Error:
  23.                  Skip_Counter: 0
  24.           Exec_Master_Log_Pos: 3631
  25.               Relay_Log_Space: 2278
  26.               Until_Condition: None
  27.                Until_Log_File:
  28.                 Until_Log_Pos: 0
  29.            Master_SSL_Allowed: No
  30.            Master_SSL_CA_File:
  31.            Master_SSL_CA_Path:
  32.               Master_SSL_Cert:
  33.             Master_SSL_Cipher:
  34.                Master_SSL_Key:
  35.         Seconds_Behind_Master: 0
  36. Master_SSL_Verify_Server_Cert: No
  37.                 Last_IO_Errno: 0
  38.                 Last_IO_Error:
  39.                Last_SQL_Errno: 0
  40.                Last_SQL_Error:
  41.   Replicate_Ignore_Server_Ids:
  42.              Master_Server_Id: 2
  43.                   Master_UUID: 659e33c7-f1ef-11e6-8e3e-00163e3225da
  44.              Master_Info_File: /alidata1/mysqldata/3306/data/master.info
  45.                     SQL_Delay: 0
  46.           SQL_Remaining_Delay: NULL
  47.       Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
  48.            Master_Retry_Count: 86400
  49.                   Master_Bind:
  50.       Last_IO_Error_Timestamp:
  51.      Last_SQL_Error_Timestamp:
  52.                Master_SSL_Crl:
  53.            Master_SSL_Crlpath:
  54.            Retrieved_Gtid_Set:
  55.             Executed_Gtid_Set:
  56.                 Auto_Position: 0
  57.          Replicate_Rewrite_DB:
  58.                  Channel_Name:
  59.            Master_TLS_Version:
  60. 1 row in set (0.00 sec)
七.測試
在master端建立一個表

  1. (root@localhost) [(none)]> use gldb
  2. Database changed
  3. (root@localhost) [gldb]> create table gl (abcd varchar(20));
  4. Query OK, 0 rows affected (0.51 sec)
在slave端查詢是否透過成功

  1. (root@localhost) [(none)]> use gldb;
  2. Database changed
  3. (root@localhost) [gldb]> show create table gl;
  4. +-------+--------------------------------------------------------------------------------------------+
  5. | Table | Create Table |
  6. +-------+--------------------------------------------------------------------------------------------+
  7. | gl | CREATE TABLE `gl` (
  8.   `abcd` varchar(20) DEFAULT NULL
  9. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
  10. +-------+--------------------------------------------------------------------------------------------+
  11. 1 row in set (0.00 sec)
同步成功~~~


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20893244/viewspace-2134070/,如需轉載,請註明出處,否則將追究法律責任。

相關文章