Using Innobackupex to build MySQL master-slave architecture from libraries

Source: Internet
Author: User

??

MySQL's master-slave building There are many ways, the traditional mysqldump way is one of many people's choice. However, this approach is not an ideal choice for larger databases. Use Xtrabackup to quickly and easily build or repair MySQL master-slave architectures. This article describes how to build a master-slave based on the existing library, which is a new library from the original repository. The benefit of this approach is that the correlation can be stressful for the main library without the backup period. The fast-flow backup method is used to speed up the master-slave construction and describe the parameters of the accelerated streaming backup for reference.


for a streaming backup, refer to: Xtrabackup Stream Backup and recovery


1. Backup from Library
# # #远程备份期间使用了等效性验证, so you should configure it first, here we use the MySQL user
$ Innobackupex--user=root--password=xxx--slave-info--safe-slave-backup \
--compress-threads=3--parallel=3--stream=xbstream \
--compress/log | ssh-p50021 [email protected] "Xbstream-x-c/log/recover"


# # #备份期间使用了safe-slave-backup parameter, you can see that SQL thread is stopped and is started after completion
$ mysql-uroot-p-E "show slave status \g" |egrep ' slave_io_running| Slave_sql_running '
Enter Password:
Slave_io_running:yes
Slave_sql_running:no
Slave_sql_running_state:slave have read all relay log; Waiting for the slave I/O thread to update it


# # #复制my. cnf files to new Slave library
$ scp-p50021/etc/my.cnf [email protected]:/log/recover


2, the main library to grant a new copy from the library account
[Email protected]> grant Replication Slave,replication Client on * * to [e-mail protected] ' 172.16.%.% ' identified by ' re PL ';


3, new from the library prepare
# # #由于使用了流式压缩备份, so you need to unpack first
# # http://www.quicklz.com/
# TAR-XVF Qpress-11-linux-x64.tar
Qpress
# CP qpress/usr/bin/
$ Innobackupex--decompress/log/recover # # #解压
$ Innobackupex--apply-log--use-memory=2g/log/recover # # #prepare备份


4. Prepare the my.cnf from the library configuration file
# # #根据需要修改相应参数, here are the changes below,
Skip-slave-start
DataDir =/log/recover
Port = 3307
server_id = 24
Socket =/tmp/mysql3307.sock
Pid-file=/log/recover/mysql3307.pid
Log_error=/log/recover/recover.err


5. Start from library and modify change master
# Chown-r Mysql:mysql/log/recover
#/app/soft/mysql/bin/mysqld_safe--DEFAULTS-FILE=/LOG/RECOVER/MY.CNF &

mysql> System More/log/recover/xtrabackup_slave_info
Change MASTER to master_log_file= ' mysql-bin.000658 ', master_log_pos=925384099
Mysql> Change MASTER to
Master_host= ' 172.16.16.10 ', # # # Author:leshami
-master_user= ' Repl ', # # # Blog: Http://blog.csdn.net/leshami
Master_password= ' Repl ',
master_port=3306,
Master_log_file= ' mysql-bin.000658 ',
master_log_pos=925384099;
Query OK, 0 rows affected, 2 warnings (0.31 sec)

mysql> start slave;
Query OK, 0 rows affected (0.02 sec)


6, based on the backup parameters from the library and the acceleration stream backup parameter

The--slave-info option is useful if backing up a replication slave server. It Prints the binary
Log position and name of the master server. It also writes this information to the Xtrabackup_slave_info le
As a change MASTER statement.
This is useful for setting up a new slave for this master can be set up by starting a slave server on this backup and
Issuing the statement saved in the Xtrabackup_slave_info le.


The--safe-slave-backup option in order to assure a consistent replication state, this option stops the slave
SQL thread and wait to start backing up until Slave_open_temp_tables in SHOW STATUS is zero. If there is
No open temporary tables, the backup would take place, otherwise the SQL thread would be started and stopped until there
is no open temporary tables. The backup would fail if Slave_open_temp_tables does not become zero after
--safe-slave-backup-timeout seconds (defaults to seconds). The slave SQL thread would be restarted
When the backup nishes.
Using This option was always recommended when taking backups from a slave server.


Warning:make sure your slave is a true replica of the master before using it as a source for backup. A Good tool
To validate a Slave is pt-table-checksum.


--compress
This option instructs Xtrabackup to compress backup copies of InnoDB
Data files. It is passed directly to the Xtrabackup child process.
# # #注compress方式是一种相对粗糙的压缩方式, compressed to. gp files, no gzip compression ratio


--compress-threads
This option specifies the number of workers threads that'll be used
for parallel compression. It's passed directly to the Xtrabackup
Child process. Try ' Xtrabackup--help ' for more details.


--decompress
Decompresses all files with the. qp extension in a backup previously
Made with the--compress option.


--parallel=number-of-threads
On backup, this option specifies the number of threads the
The Xtrabackup child process should the use-to-back up files concurrently.
The option accepts an integer argument. It's passed directly to
Xtrabackup ' s--parallel option. See the Xtrabackup documentation for
Details.

On--decrypt or--decompress it specifies the number of parallel
Forks that should is used to process the backup files.

Using Innobackupex to build MySQL master-slave architecture from libraries

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.