转载

用xtrabackup工具创建slave节点


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)
同步成功~~~


正文到此结束
Loading...