搜索
首页数据库mysql教程使用innobackupex基于从库搭建mysql主从架构



       MySQL的主从搭建大家有很多种方式,传统的mysqldump方式是很多人的选择之一。但对于较大的数据库则该方式并非理想的选择。使用Xtrabackup可以快速轻松的构建或修复mysql主从架构。本文描述了基于现有的从库来快速搭建主从,即作为原主库的一个新从库。该方式的好处是对主库无需备份期间导致的相关性能压力。搭建过程中使用了快速流备份方式来加速主从构建以及描述了加速流式备份的几个参数,供大家参考。


    有关流式备份可以参考:Xtrabackup 流备份与恢复


1、备份从库
###远程备份期间使用了等效性验证,因此应先作相应配置,这里我们使用的是mysql用户

$ innobackupex --user=root --password=xxx --slave-info --safe-slave-backup 
\--compress-threads=3 --parallel=3 --stream=xbstream \--compress /log | ssh -p50021 mysql@172.16.16.10 "xbstream -x -C /log/recover"



###备份期间使用了safe-slave-backup参数,可以看到SQL thread被停止,完成后被启动

$ 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 has read all relay log; waiting for the slave I/O thread to update it



###复制my.cnf文件到新从库

$ scp -P50021 /etc/my.cnf mysql@172.16.16.10:/log/recover



2、主库授予新从库复制账户

master@MySQL> grant replication slave,replication client on *.* to repl@'172.16.%.%' identified by 'repl';



3、新从库prepare        
###由于使用了流式压缩备份,因此需要先解压
###下载地址 
http://www.php.cn/

# 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、准备从库配置文件my.cnf
###根据需要修改相应参数,这里的修改如下,

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、启动从库及修改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://www.php.cn/
    -> 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、基于从库备份相关参数及加速流备份参数

The --slave-info option This option is useful when 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 file
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 file.



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 are
no open temporary tables, the backup will take place, otherwise the SQL thread will be started and stopped until there
are no open temporary tables. The backup will fail if Slave_open_temp_tables does not become zero after
--safe-slave-backup-timeout seconds (defaults to 300 seconds). The slave SQL thread will be restarted
when the backup finishes.
Using this option is 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方式是一种相对粗糙的压缩方式,压缩为.gp文件,没有gzip压缩比高


--compress-threads
     

   This option specifies the number of worker threads that will be used
        for parallel compression. It is 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        
   xtrabackup child process should use to back up files concurrently.        
   The option accepts an integer argument. It is 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 be used to process the backup files.


以上就是使用innobackupex基于从库搭建mysql主从架构的内容,更多相关内容请关注PHP中文网(www.php.cn)!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
MySQL的角色:Web应用程序中的数据库MySQL的角色:Web应用程序中的数据库Apr 17, 2025 am 12:23 AM

MySQL在Web应用中的主要作用是存储和管理数据。1.MySQL高效处理用户信息、产品目录和交易记录等数据。2.通过SQL查询,开发者能从数据库提取信息生成动态内容。3.MySQL基于客户端-服务器模型工作,确保查询速度可接受。

mysql:构建您的第一个数据库mysql:构建您的第一个数据库Apr 17, 2025 am 12:22 AM

构建MySQL数据库的步骤包括:1.创建数据库和表,2.插入数据,3.进行查询。首先,使用CREATEDATABASE和CREATETABLE语句创建数据库和表,然后用INSERTINTO语句插入数据,最后用SELECT语句查询数据。

MySQL:一种对数据存储的初学者友好方法MySQL:一种对数据存储的初学者友好方法Apr 17, 2025 am 12:21 AM

MySQL适合初学者,因为它易用且功能强大。1.MySQL是关系型数据库,使用SQL进行CRUD操作。2.安装简单,需配置root用户密码。3.使用INSERT、UPDATE、DELETE、SELECT进行数据操作。4.复杂查询可使用ORDERBY、WHERE和JOIN。5.调试需检查语法,使用EXPLAIN分析查询。6.优化建议包括使用索引、选择合适数据类型和良好编程习惯。

MySQL初学者友好吗?评估学习曲线MySQL初学者友好吗?评估学习曲线Apr 17, 2025 am 12:19 AM

MySQL适合初学者,因为:1)易于安装和配置,2)有丰富的学习资源,3)SQL语法直观,4)工具支持强大。尽管如此,初学者需克服数据库设计、查询优化、安全管理和数据备份等挑战。

SQL是一种编程语言吗?澄清术语SQL是一种编程语言吗?澄清术语Apr 17, 2025 am 12:17 AM

是的,sqlisaprogramminglanguges pecialized fordatamanage.1)它具有焦点,focusingonwhattoachieveratherthanhow.2)sqlisessential forquerying forquerying,插入,更新,更新,和detletingdatainrelationalDatabases.3)

解释酸的特性(原子,一致性,隔离,耐用性)。解释酸的特性(原子,一致性,隔离,耐用性)。Apr 16, 2025 am 12:20 AM

ACID属性包括原子性、一致性、隔离性和持久性,是数据库设计的基石。1.原子性确保事务要么完全成功,要么完全失败。2.一致性保证数据库在事务前后保持一致状态。3.隔离性确保事务之间互不干扰。4.持久性确保事务提交后数据永久保存。

MySQL:数据库管理系统与编程语言MySQL:数据库管理系统与编程语言Apr 16, 2025 am 12:19 AM

MySQL既是数据库管理系统(DBMS),也与编程语言紧密相关。1)作为DBMS,MySQL用于存储、组织和检索数据,优化索引可提高查询性能。2)通过SQL与编程语言结合,嵌入在如Python中,使用ORM工具如SQLAlchemy可简化操作。3)性能优化包括索引、查询、缓存、分库分表和事务管理。

mySQL:使用SQL命令管理数据mySQL:使用SQL命令管理数据Apr 16, 2025 am 12:19 AM

MySQL使用SQL命令管理数据。1.基本命令包括SELECT、INSERT、UPDATE和DELETE。2.高级用法涉及JOIN、子查询和聚合函数。3.常见错误有语法、逻辑和性能问题。4.优化技巧包括使用索引、避免SELECT*和使用LIMIT。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
1 个月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它们
1 个月前By尊渡假赌尊渡假赌尊渡假赌

热工具

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境