溫馨提示×

溫馨提示×

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

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

怎么用xtrabackup工具創(chuàng)建slave節(jié)點

發(fā)布時間:2021-11-06 09:40:52 來源:億速云 閱讀:157 作者:小新 欄目:MySQL數(shù)據(jù)庫

這篇文章主要為大家展示了“怎么用xtrabackup工具創(chuàng)建slave節(jié)點”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學習一下“怎么用xtrabackup工具創(chuàng)建slave節(jié)點”這篇文章吧。


xtrabackup安裝和備份方法等請先參考我的另一篇博客 http://blog.itpub.net/20893244/viewspace-2133530/
環(huán)境:
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工具創(chuàng)建slave節(jié)點需要七步驟,我們一步一步操作

一.在master節(jié)點完整備份數(shù)據(jù)

  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.準備數(shù)據(jù),執(zhí)行innobackupex命令附加--apply-log參數(shù)
  1. innobackupex --apply-log /alidata1/mysqldata/mysqlbackup/mysql_full

三.創(chuàng)建復制環(huán)境專用賬戶并賦予權(quán)限

  1. create user repl@'192.168.3.173';

  2. grant replication slave on *.* to repl identified by 'replmysql';

四.配置slave節(jié)點的初始化參數(shù)

從master端拷貝到slave端,還是用scp命令;
在slave端修改初始化文件,把server_id修改為一個非0的值
啟動數(shù)據(jù)庫

  1. mysqld_safe --defaults-file=/etc/my.cnf &

五.配置slave節(jié)點復制環(huán)境

查看xtrabackup_binlog_info文件里的數(shù)據(jù)

  1. [root@mysqltest mysql_full]# more xtrabackup_binlog_info

  2. mysql-bin.000016        1884

執(zhí)行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;

執(zhí)行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端創(chuàng)建一個表

  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)

同步成功~~~

以上是“怎么用xtrabackup工具創(chuàng)建slave節(jié)點”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

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

AI