演示环境:
操作系统版本:linux-7.3-x86_64
数据库版本:mysql-5.7.19-x86_64
master主服务器: 192.168.56.13
slave从服务器: 192.168.56.14
--192.168.56.13 master 操作 --用户innobackupex 全量备份, 拖到slave(192.168.56.14)上。 [root@single-instance innobackupex_dir]# innobackupex --defaults-file=/etc/my.cnf --user=bkpuser --password=S3cret2233$ /mysql/innobackupex_dir/ --全量备份的打包 full_bak_20180419.tar.gz [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 * --master的备份传送到slave主机上 [root@single-instance innobackupex_dir]# scp full_bak_20180419.tar.gz [email protected]:/mysql/innobackupex_dir/ --创建复制用户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 操作 --解压缩 [root@oracle11g innobackupex_dir]# tar xivfz full_bak_20180419.tar.gz -C /var/lib/mysql/ --赋权限(因root用户导入的) [root@oracle11g innobackupex_dir]# chown -R mysql:mysql /var/lib/mysql/ --恢复一致性 [root@oracle11g mysql]# innobackupex --apply-log /var/lib/mysql --附:遇到的问题 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. --转移 ib_logfile1 文件 [root@oracle11g mysql]# mv ib_logfile1 /mysql/innobackupex_dir/ --拷贝 master的 my.cnf 到 slave中 [root@oracle11g mysql]# scp [email protected]:/etc/my.cnf /etc/my.cnf --修改my.cnf的server-id为222 [root@oracle11g mysql]# vi /etc/my.cnf server-id=222 port = 3307 --查看备份集信息 [root@oracle11g mysql]# more xtrabackup_binlog_info my-bin.000010 154 --创建复制 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) --查看复制信息 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) ------验证 --master库建立表 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库查看表存在,复制成功 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) --查看进程 --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查看slave信息 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) --起停的操作及状态 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)