使用 Tu_MySQL 的 Percona Toolkit 插件检查 MySQL 从机延迟
不久前,我对 pt-online-schema-change 的插件接口进行了一些更改,它允许编写自定义复制检查。在添加此功能时,我还向 pt-table-checksum 添加了 --plugin 选项。这是在 Percona Toolkit 2.2.8 中发布的。
通过这些添加,我花了一些时间编写了一个插件,允许 Percona Toolkit 工具使用 Tungsten Replicator 来检查从机延迟,您可以在 https://github.com/grypyrg/percona- 找到代码toolkit-plugin-tungsten-replicator
该插件使用 perl JSON::XS 模块 ( perl-JSON-XS rpm 包,http://search.cpan.org/dist/ JSON-XS/XS.pm ),确保它可用,否则插件将无法工作。
我们需要使用 --recursion-method=dsns 因为 Percona Toolkit 工具无法自动找到连接到主数据库的 tungsten 复制器从属。 (我确实在启动板上添加了一个蓝图,以使其成为可能 https://blueprints.launchpad.net/percona-toolkit/spec/plugin-custom-recursion-method )
dsns递归方法从您指定的数据库表中获取从属列表:
CREATE TABLE `percona`.`dsns` (`id` int(11) NOT NULL AUTO_INCREMENT,`parent_id` int(11) DEFAULT NULL,`dsn` varchar(255) NOT NULL,PRIMARY KEY (`id`));
` id ` int ( 11 ) NOT NULL AUTO_INCRMENT , `parent_id ` int ( 11 ) 默认为 NULL ,node1 mysql> select * from percona.dsns;+----+-----------+---------+| id | parent_id | dsn |+----+-----------+---------+|2 |NULL | h=node3 |+----+-----------+---------+ 登录后复制
主键 ( ` id ` ) ) ; ## CONFIGURATION# trepctl command to runmy $trepctl="/opt/tungsten/installs/cookbook/tungsten/tungsten-replicator/bin/trepctl";# what tungsten replicator service to checkmy $service="bravo";# what user does tungsten replicator use to perform the writes?# See Binlog Format for more informationmy $tungstenusername = 'tungsten'; 登录后复制 |
## CONFIGURATION # trepctl command to run my $trepctl = "/opt/tungsten/installs/cookbook/tungsten/tungsten-replicator/bin/trepctl" ; # what tungsten replicator service to check my $service = "bravo" ; # what user does tungsten replicator use to perform the writes? # See Binlog Format for more information my $tungstenusername = 'tungsten' ; |
node3
正在从主服务器复制: # pt-table-checksum - u checksum -- no - check - binlog - format -- recursion - method = dsn = D = percona , t = dsns -- plugin = / vagrant / pt - plugin - tungsten_replicator .pl -- databases app -- check - interval = 5 -- max - lag = 10 Created plugin from / vagrant / pt - plugin - tungsten_replicator .pl . PLUGIN get_slave_lag : Using Tungsten Replicator to check replication lag Tungsten Replicator status of host node3 is OFFLINE : NORMAL , waiting Tungsten Replicator status of host node3 is OFFLINE : NORMAL , waiting Replica node3 is stopped . Waiting . Tungsten Replicator status of host node3 is OFFLINE : NORMAL , waiting Replica lag is 125 seconds on node3 . Waiting . Replica lag is 119 seconds on node3 . Waiting . Checksumming app .large_table : 22 % 00 : 12 remain TS ERRORS DIFFS ROWS CHUNKS SKIPPED TIME TABLE 07 - 03T10 : 49 : 54 0 0 2097152 7 0 213.238 app .large_table
目前,使用 Percona Toolkit 无法为插件指定额外选项,因此仍然需要手动编辑 perl 文件来配置它。因此,在运行校验和之前,我们需要配置插件: node1 mysql>;从 percona .dsns 选择 * ;
# pt-table-checksum-u checksum--no-check-binlog-format--recursion-method=dsn=D=percona,t=dsns--plugin=/vagrant/pt-plugin-tungsten_replicator.pl--databases app--check-interval=5--max-lag=10Created plugin from /vagrant/pt-plugin-tungsten_replicator.pl.PLUGIN get_slave_lag: Using Tungsten Replicator to check replication lagTungsten Replicator status of host node3 is OFFLINE:NORMAL, waitingTungsten Replicator status of host node3 is OFFLINE:NORMAL, waitingReplica node3 is stopped.Waiting.Tungsten Replicator status of host node3 is OFFLINE:NORMAL, waitingReplica lag is 125 seconds on node3.Waiting.Replica lag is 119 seconds on node3.Waiting.Checksumming app.large_table:22% 00:12 remainTS ERRORSDIFFS ROWSCHUNKS SKIPPEDTIME TABLE07-03T10:49:54002097152 7 0 213.238 app.large_table
|编号 |父 ID | DSN | -- -- -- -- -- -- -- -- - -- -- -- -- -- - | 2 | 空| h = 节点3 | -- -- -- -- -- -- -- -- - -- -- -- -- -- -
运行校验和 在这里,我使用 pt-table-checksum 对表进行了校验和。在校验和过程中,我使从节点离线并再次将其重新上线: ## 配置 # trepctl 命令运行 my $trepctl = "/opt/tungsten/installs /cookbook/tungsten/tungsten-replicator/bin/trepctl" ; # 要检查什么钨复制器服务 my $service = "bravo" ; # tungstenreplicator 使用什么用户来执行写入? # 有关更多信息,请参阅 Binlog 格式 my $tungstenusername = 'tungsten' ;
# pt-table-checksum - u checksum -- 无 - 检查 - binlog - 格式 -- 递归 - method = dsn = D = percona , t = dsns -- plugin = / vagrant / pt - 插件 - tungsten_replicator .pl -- 数据库应用 -- 检查 - 间隔 = 5 -- max - lag = 10 已创建来自 /vagrant/pt-plugin-tungsten_replicator.pl 的插件。 PLUGIN get_slave_lag :使用 Tungsten Replicator 检查复制延迟 主机节点 3 的 Tungsten Replicator 状态为离线:正常,等待 主机节点 3 的 Tungsten Replicator 状态为离线:正常,等待 副本节点 3 已停止。 等待 。 主机节点 3 的 Tungsten Replicator 状态为 OFFLINE:NORMAL,正在等待 节点 3 上的副本延迟为 125 秒。 等待 。 Node3 上的副本延迟为 119 秒。 等待 。 校验和应用程序 .large_table : 22 % 00 : 12 剩余 TS 错误 差异 行 跳过块 时间表 07 - 03T10 : 49 : 54 0 0 2097152 7 0 213.238应用程序 .large_table
I recommend to change the check-interval higher than the default 1 second as running trepctl takes a while. This could slow down the process quite a lot.
Making Schema Changes
The plugin also works with pt-online-schema-change :
# pt-online-schema-change-u schemachange--recursion-method=dsn=D=percona,t=dsns--plugin=/vagrant/pt-plugin-tungsten_replicator.pl--check-interval=5--max-lag=10--alter "add index (column1) "--execute D=app,t=large_tableCreated plugin from /vagrant/pt-plugin-tungsten_replicator.pl.Found 1 slaves:node3Will check slave lag on:node3PLUGIN get_slave_lag: Using Tungsten Replicator to check replication lagOperation, tries, wait:copy_rows, 10, 0.25create_triggers, 10, 1drop_triggers, 10, 1swap_tables, 10, 1update_foreign_keys, 10, 1Altering `app`.`large_table`...Creating new table...Created new table app._large_table_new OK.Waiting forever for new table `app`.`_large_table_new` to replicate to node3...Altering new table...Altered `app`.`_large_table_new` OK.2014-07-03T13:02:33 Creating triggers...2014-07-03T13:02:33 Created triggers OK.2014-07-03T13:02:33 Copying approximately 8774670 rows...Copying `app`.`large_table`:26% 01:21 remainCopying `app`.`large_table`:50% 00:59 remainReplica lag is 12 seconds on node3.Waiting.Replica lag is 12 seconds on node3.Waiting.Copying `app`.`large_table`:53% 02:22 remainCopying `app`.`large_table`:82% 00:39 remain2014-07-03T13:06:06 Copied rows OK.2014-07-03T13:06:06 Swapping tables...2014-07-03T13:06:06 Swapped original and new tables OK.2014-07-03T13:06:06 Dropping old table...2014-07-03T13:06:06 Dropped old table `app`.`_large_table_old` OK.2014-07-03T13:06:06 Dropping triggers...2014-07-03T13:06:06 Dropped triggers OK.Successfully altered `app`.`large_table`.
# pt-online-schema-change - u schemachange -- recursion - method = dsn = D = percona , t = dsns -- plugin = / vagrant / pt - plugin - tungsten_replicator .pl -- check - interval = 5 -- max - lag = 10 -- alter "add index (column1) " -- execute D = app , t = large_table Created plugin from / vagrant / pt - plugin - tungsten_replicator .pl . Found 1 slaves : node3 Will check slave lag on : node3 PLUGIN get_slave_lag : Using Tungsten Replicator to check replication lag Operation , tries , wait : copy_rows , 10 , 0.25 create_triggers , 10 , 1 drop_triggers , 10 , 1 swap_tables , 10 , 1 update_foreign_keys , 10 , 1 Altering ` app ` . ` large_table ` . . . Creating new table . . . Created new table app ._large_table_new OK . Waiting forever for new table ` app ` . ` _large_table_new ` to replicate to node3 . . . Altering new table . . . Altered ` app ` . ` _large_table_new ` OK . 2014 - 07 - 03T13 : 02 : 33 Creating triggers . . . 2014 - 07 - 03T13 : 02 : 33 Created triggers OK . 2014 - 07 - 03T13 : 02 : 33 Copying approximately 8774670 rows . . . Copying ` app ` . ` large_table ` : 26 % 01 : 21 remain Copying ` app ` . ` large_table ` : 50 % 00 : 59 remain Replica lag is 12 seconds on node3 . Waiting . Replica lag is 12 seconds on node3 . Waiting . Copying ` app ` . ` large_table ` : 53 % 02 : 22 remain Copying ` app ` . ` large_table ` : 82 % 00 : 39 remain 2014 - 07 - 03T13 : 06 : 06 Copied rows OK . 2014 - 07 - 03T13 : 06 : 06 Swapping tables . . . 2014 - 07 - 03T13 : 06 : 06 Swapped original and new tables OK . 2014 - 07 - 03T13 : 06 : 06 Dropping old table . . . 2014 - 07 - 03T13 : 06 : 06 Dropped old table ` app ` . ` _large_table_old ` OK . 2014 - 07 - 03T13 : 06 : 06 Dropping triggers . . . 2014 - 07 - 03T13 : 06 : 06 Dropped triggers OK . Successfully altered ` app ` . ` large_table ` . |
As you can see, there was some slave lag during the schema changes.
Binlog Format & pt-online-schema-change
pt-online-schema-change uses triggers in order to do the schema changes. Tungsten Replicator has some limitations with different binary log formats and triggers ( https://code.google.com/p/tungsten-replicator/wiki/TRCAdministration#Triggers_and_Row_Replication ).
In Tungsten Replicator, ROW based binlog events will be converted to SQL statements, which causes triggers to be executed on the slave as well, this does not happen with traditional replication.
Different settings:
- STATEMENT based binary logging works by default
- ROW based binary logging works, the plugin recreates the triggers and uses the technique documented at https://code.google.com/p/tungsten-replicator/wiki/TRCAdministration#Triggers_and_Row_Replication
- MIXED binary logging does not work, as there is currently no way to determine whether an event was written to the binary log in statement or row based format, so it’s not possible to know if triggers should be run or not. The tool will exit and and error will be returned:
Error creating --plugin: The master it's binlog_format=MIXED,pt-online-schema change does not work well withTungsten Replicator and binlog_format=MIXED.
登录后复制Error creating -- plugin : The master it ' s binlog_format = MIXED ,
pt - online - schema change does not work well with
Tungsten Replicator and binlog_format = MIXED .
binlog_format 可以在每个会话的基础上覆盖,确保使用 pt-online-schema-change 时不会发生这种情况。
Continent 网站上的文档已经提到了如何将数据与 pt-table-checksum 进行比较。
我相信这个插件是一个很好的补充。 Percona Toolkit 中监控复制延迟的功能现在可以与 Tungsten Replicator 一起使用,因此您可以控制使用这些工具时可以容忍的复制延迟程度。

热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

全表扫描在MySQL中可能比使用索引更快,具体情况包括:1)数据量较小时;2)查询返回大量数据时;3)索引列不具备高选择性时;4)复杂查询时。通过分析查询计划、优化索引、避免过度索引和定期维护表,可以在实际应用中做出最优选择。

InnoDB的全文搜索功能非常强大,能够显着提高数据库查询效率和处理大量文本数据的能力。 1)InnoDB通过倒排索引实现全文搜索,支持基本和高级搜索查询。 2)使用MATCH和AGAINST关键字进行搜索,支持布尔模式和短语搜索。 3)优化方法包括使用分词技术、定期重建索引和调整缓存大小,以提升性能和准确性。

是的,可以在 Windows 7 上安装 MySQL,虽然微软已停止支持 Windows 7,但 MySQL 仍兼容它。不过,安装过程中需要注意以下几点:下载适用于 Windows 的 MySQL 安装程序。选择合适的 MySQL 版本(社区版或企业版)。安装过程中选择适当的安装目录和字符集。设置 root 用户密码,并妥善保管。连接数据库进行测试。注意 Windows 7 上的兼容性问题和安全性问题,建议升级到受支持的操作系统。

聚集索引和非聚集索引的区别在于:1.聚集索引将数据行存储在索引结构中,适合按主键查询和范围查询。2.非聚集索引存储索引键值和数据行的指针,适用于非主键列查询。

MySQL是一个开源的关系型数据库管理系统。1)创建数据库和表:使用CREATEDATABASE和CREATETABLE命令。2)基本操作:INSERT、UPDATE、DELETE和SELECT。3)高级操作:JOIN、子查询和事务处理。4)调试技巧:检查语法、数据类型和权限。5)优化建议:使用索引、避免SELECT*和使用事务。

MySQL 数据库中,用户和数据库的关系通过权限和表定义。用户拥有用户名和密码,用于访问数据库。权限通过 GRANT 命令授予,而表由 CREATE TABLE 命令创建。要建立用户和数据库之间的关系,需创建数据库、创建用户,然后授予权限。

MySQL支持四种索引类型:B-Tree、Hash、Full-text和Spatial。1.B-Tree索引适用于等值查找、范围查询和排序。2.Hash索引适用于等值查找,但不支持范围查询和排序。3.Full-text索引用于全文搜索,适合处理大量文本数据。4.Spatial索引用于地理空间数据查询,适用于GIS应用。

MySQL 和 MariaDB 可以共存,但需要谨慎配置。关键在于为每个数据库分配不同的端口号和数据目录,并调整内存分配和缓存大小等参数。连接池、应用程序配置和版本差异也需要考虑,需要仔细测试和规划以避免陷阱。在资源有限的情况下,同时运行两个数据库可能会导致性能问题。
