加入收藏 | 设为首页 | 会员中心 | 我要投稿 广西网 (https://www.guangxiwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

怎么用xtrabackup工具创建slave细节

发布时间:2021-12-26 13:03:08 所属栏目:编程 来源:互联网
导读:这篇文章主要为大家展示了怎么用xtrabackup工具创建slave节点,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下怎么用xtrabackup工具创建slave节点这篇文章吧。 xtrabackup安装和备份方法等请先参考我的另一篇博客
这篇文章主要为大家展示了“怎么用xtrabackup工具创建slave节点”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“怎么用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节点完整备份数据
 
 
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端
scp -r /alidata1/mysqlbackup/mysql_full root@192.168.3.173:/alidata1/mysqldata/mysqlbackup
2.在slave端解压备份集
tar -xzvf xtra_fullbak_2017-02-20.tar
3.准备数据,执行innobackupex命令附加--apply-log参数
innobackupex --apply-log /alidata1/mysqldata/mysqlbackup/mysql_full
三.创建复制环境专用账户并赋予权限
 
 
create user repl@'192.168.3.173';
grant replication slave on *.* to repl identified by 'replmysql';
四.配置slave节点的初始化参数
 
从master端拷贝到slave端,还是用scp命令;
在slave端修改初始化文件,把server_id修改为一个非0的值
启动数据库
 
 
mysqld_safe --defaults-file=/etc/my.cnf &
五.配置slave节点复制环境
 
查看xtrabackup_binlog_info文件里的数据
 
 
[root@mysqltest mysql_full]# more xtrabackup_binlog_info
mysql-bin.000016        1884
执行change masger命令
 
 
change master to
master_host='192.168.3.171',
master_port=3306,
master_user='repl',
master_password='replmysql',
master_log_file='mysql-bin.000016',
master_log_pos=1884;
执行start slave命令
 
 
mysql > start slave;
六.检查
 
 
(root@localhost) [(none)]> show slave status G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.3.171
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000016
          Read_Master_Log_Pos: 3631
               Relay_Log_File: mysqltest-relay-bin.000002
                Relay_Log_Pos: 2067
        Relay_Master_Log_File: mysql-bin.000016
             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: 3631
              Relay_Log_Space: 2278
              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: 2
                  Master_UUID: 659e33c7-f1ef-11e6-8e3e-00163e3225da
             Master_Info_File: /alidata1/mysqldata/3306/data/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)
七.测试
在master端创建一个表
 
 
(root@localhost) [(none)]> use gldb
Database changed
(root@localhost) [gldb]> create table gl (abcd varchar(20));
Query OK, 0 rows affected (0.51 sec)
在slave端查询是否通过成功
 
 
(root@localhost) [(none)]> use gldb;
Database changed
(root@localhost) [gldb]> show create table gl;
+-------+--------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------------+
| gl | CREATE TABLE `gl` (
  `abcd` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+--------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
同步成功~~~
 
以上是“怎么用xtrabackup工具创建slave节点”这篇文章的所有内容,感谢各位的阅读!

(编辑:广西网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!