共計(jì) 3386 個(gè)字符,預(yù)計(jì)需要花費(fèi) 9 分鐘才能閱讀完成。
這篇文章給大家分享的是有關(guān) MySQL 5.5 如何使用 Xtrabackup 在線搭建復(fù)制環(huán)境的內(nèi)容。丸趣 TV 小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨丸趣 TV 小編過來看看吧。
– 編輯 Master 的配置文件
[root@localhost install]# vim /etc/my.cnf
# Log
server-id = 100
log-bin = /log/binlog/mysql-bin
– 在 Slave 安裝好 MySQL 軟件,安裝流程可以參考源碼安裝文章
http://blog.itpub.net/26506993/viewspace-2072859/
– 在 Master 節(jié)點(diǎn),使用 Xtrabackup 創(chuàng)建完整備份
關(guān)于 Xtrabackup,可參考
http://blog.itpub.net/26506993/viewspace-2087734/
http://blog.itpub.net/26506993/viewspace-2088737/
[root@localhost backup]# /install/percona/percona-xtrabackup-2.4.2-Linux-x86_64/bin/innobackupex –defaults-file=/etc/my.cnf –stream=tar /tmp –user system –password Mysql#2015 | gzip –
/backup/xtra/xtra_fullbackup_20160501.tar.gz
– 拷貝備份到 Slave 節(jié)點(diǎn)
[root@localhost backup]# scp /backup/xtra/xtra_fullbackup_20160501.tar.gz root@192.168.78.137:/backup/20160501
解壓備份到數(shù)據(jù)文件目錄
[root@localhost 5505]# tar xivfz xtra_fullbackup_20160501.tar.gz -C /mysql_data/5505
在 Slave 節(jié)點(diǎn)上面需要安裝 Xtraback
– 使用 Xtrabackup 準(zhǔn)備數(shù)據(jù)、應(yīng)用日志,使數(shù)據(jù)文件達(dá)到一致性的狀態(tài)
[root@localhost bin]# ./innobackupex –defaults-file=/mysql_data/cnf/my.cnf –apply-log /mysql_data/5505
…..
InnoDB: Doing recovery: scanned up to log sequence number 68405269 (0%)
InnoDB: Doing recovery: scanned up to log sequence number 68405269 (0%)
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: xtrabackup: Last MySQL binlog file position 414, file name /log/binlog/mysql-bin.000012
InnoDB: Removed temporary tablespace data file: ibtmp1
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file ./ibtmp1 size to 12 MB. Physically writing the file full; Please wait …
InnoDB: File ./ibtmp1 size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: 5.7.11 started; log sequence number 68405269
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown…
InnoDB: Shutdown completed; log sequence number 68405621
160430 23:51:25 completed OK!
– 在 Master 數(shù)據(jù)庫上面創(chuàng)建復(fù)制專用賬戶
mysql grant replication slave on *.* to repl @ 192.168.78.% identified by Mysql#2015
Query OK, 0 rows affected (0.04 sec)
– 配置 Slave 的配置文件
[root@localhost 5505]# vim /mysql_data/cnf/my.cnf
# Log
server-id = 200
log-bin = /mysql_log/binlog/mysql-bin
relay-log = /mysql_log/binlog/product-relay-bin
relay-log-index = /mysql_log/binlog/product-relay-index
binlog_cache_size = 32M
max_binlog_cache_size = 512M
max_binlog_size = 512M
binlog_format = MIXED
relay_log_recovery = 1
– 啟動(dòng) Slave 節(jié)點(diǎn)的 Mysql 服務(wù)
[root@localhost bin]# /data/bin/mysqld_safe –defaults-file=/mysql_data/cnf/my.cnf
– 配置 Slave 節(jié)點(diǎn)復(fù)制環(huán)境
查詢 Slave 節(jié)點(diǎn)連接 Master 節(jié)點(diǎn)的二進(jìn)制文件和位置
使用 Xtrabackup 備份時(shí),在 xtrabackup_binlog_info 文件中會(huì)保存這部分信息
[root@localhost 5505]# more xtrabackup_binlog_info
mysql-bin.000012 414
– 在 Slave 節(jié)點(diǎn)執(zhí)行 CHANGE MASTER 語句
mysql change master to
– master_host= 192.168.78.139 ,
– master_port=3306,
– master_user= repl ,
– master_password= Mysql#2015 ,
– master_log_file= mysql-bin.000012 ,
– master_log_pos=414;
Query OK, 0 rows affected (0.13 sec)
– 啟動(dòng)應(yīng)用線程
mysql start slave;
– 查看同步狀態(tài)
mysql show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.78.141
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000013
Read_Master_Log_Pos: 341
Relay_Log_File: product-relay-bin.000003
Relay_Log_Pos: 487
Relay_Master_Log_File: mysql-bin.000013
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
感謝各位的閱讀!關(guān)于“MySQL 5.5 如何使用 Xtrabackup 在線搭建復(fù)制環(huán)境”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!