- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章使用Rotate Master实现MySQL 多主复制的实现方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
当然,5.6的GUID功能的出现也带来了multi-master的无限可能,不过这个已经是题外话了。 本文主要介绍一种非实时的适用于各版本MySQL的multi-master方法。 内容简介: 最初的思路来源于一位国外DBA的blog : http://thenoyes.com/littlenoise/?p=117 基本原理就是通过SP记录当前 master-log的name和pos记录到表中,然后读取下一个master记录,执行stop slave / change master / start slave。以此循环反复。 个人对他的方法进行了改进,增加了以下功能: 1. master可以根据业务流量设置权重值 2. 各个master-slave运行情况的监控 3. 各个master可以实时退出多主的架构 具体操作过程: 1. 创建保存各个master信息的表 。
复制代码代码如下
use mysql; CREATE TABLE `rotate_master` ( `id` int(11) NOT NULL AUTO_INCREMENT, `master_host` varchar(255) DEFAULT NULL comment 'master地址', `master_port` int(10) unsigned DEFAULT NULL comment 'master端口' , `master_log_file` varchar(255) DEFAULT NULL ‘上次停止时的master-log文件', `master_log_pos` int(10) unsigned DEFAULT NULL comment '上次停止时的master-log-pos', `IS_Slave_Running` varchar(10) DEFAULT NULL comment '上次停止时主从是否有异常', `in_use` tinyint(1) DEFAULT '0' comment '是否是当前正在同步的数据行', `weight` int(11) NOT NULL DEFAULT '1' comment '该master的权重,即重复执行多少个时间片', `repeated_times` int(11) NOT NULL DEFAULT '0' comment '当前已经重复执行的时间片数', `LastExecuteTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '上次执行的时间', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 。
新增加一个master : 。
复制代码代码如下
insert into `rotate_master` (`master_host`,`master_port`,`master_log_file`,`master_log_pos`,`in_use`,`weight`) values -- 1号master,权重=1,并设置为当前master ('192.168.0.1',3307,'mysqlbinlog.000542',4,1,1), -- 2号master,权重=2 ('192.168.0.2',3306,'mysqlbinlog.000702',64762429,0,2), -- 3号master,权重=5 ('192.168.0.3',3306,'mysqlbinlog.000646',22157422,0,5) 。
手工把master 调整到当前的配置项: 。
复制代码代码如下
change master to master_host='192.168.0.1', master_port=3306,master_log_file='mysqlbinlog.000542',master_log_pos=4,master_user='repl',master_password='repl'; start slave; 。
创建rotate master SP: 注意:代码中用于连接master的用户名和密码是 : repl / repl ,请根据自己的情况修改。 。
复制代码代码如下
DELIMITER $$ DROP PROCEDURE IF EXISTS `mysql`.`rotate_master`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `rotate_master`() BEGIN DECLARE _info text; DECLARE _master_file varchar(255); DECLARE _master_pos int unsigned; DECLARE _master_host varchar(255); DECLARE _master_port int unsigned; DECLARE _is_slave_running varchar(10); DECLARE _id int; DECLARE _weight int; DECLARE _repeated_times int; select VARIABLE_VALUE from information_schema.GLOBAL_STATUS where VARIABLE_NAME = 'Slave_running' into _is_slave_running; STOP SLAVE; SELECT LOAD_FILE(@@relay_log_info_file) INTO _info; SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(_info, '\n', 3), '\n', -1), SUBSTRING_INDEX(SUBSTRING_INDEX(_info, '\n', 4), '\n', -1) INTO _master_file, _master_pos; UPDATE mysql.rotate_master SET `master_log_file` = _master_file, `master_log_pos` = _master_pos, id = LAST_INSERT_ID(id), `IS_Slave_Running` = _is_slave_running WHERE in_use = 1; select weight,repeated_times into _weight,_repeated_times from mysql.rotate_master where in_use =1; if(_weight <= _repeated_times) THEN SELECT id, master_host, master_port, master_log_file, master_log_pos INTO _id, _master_host, _master_port, _master_file, _master_pos FROM rotate_master ORDER BY id <= LAST_INSERT_ID(), id LIMIT 1; SET @sql := CONCAT( 'CHANGE MASTER TO master_host=', QUOTE(_master_host), ', master_port=', _master_port, ', master_log_file=', QUOTE(_master_file), ', master_log_pos=', _master_pos ', master_user="repl"', ', master_password="repl"' ); PREPARE myStmt FROM @sql; EXECUTE myStmt; UPDATE mysql.rotate_master SET in_use = 0,repeated_times=0 WHERE in_use = 1; UPDATE mysql.rotate_master SET in_use = 1,repeated_times=1 WHERE id = _id; ELSE UPDATE mysql.rotate_master SET `repeated_times`=`repeated_times`+1 WHERE in_use = 1; END IF; START SLAVE; END$$ DELIMITER ; 。
创建Event: 每2分钟运行一次,rotate_master() ,即时间片大小是2分钟 。
复制代码代码如下
DELIMITER $$ CREATE EVENT `rotate_master` ON SCHEDULE EVERY 120 SECOND STARTS '2011-10-13 14:09:40' ON COMPLETION NOT PRESERVE ENABLE DO CALL mysql.rotate_master()$$ DELIMITER ; 。
至此,多主复制已经搭建完成。 由于时间片长度是2分钟。 Master1 在执行 1*2 分钟后,stop slave,然后change master to Master2; Master2 在执行 2*2 分钟后,stop slave,然后change master to Master3; Master3 在执行 5*2 分钟后,stop slave,然后change master to Master2; 并以此循环往复。 如果希望把其中一个master移除多主复制,可以将他的配置项权重设置为0; 即: update rotate_master set weigh=0 where id = #ID# ,
最后此篇关于使用Rotate Master实现MySQL 多主复制的实现方法的文章就讲到这里了,如果你想了解更多关于使用Rotate Master实现MySQL 多主复制的实现方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我听说过两种数据库架构。 大师级 主从 master-master不是更适合现在的web吗,因为它就像Git一样,每个单元都有整套数据,如果一个宕机也无所谓。 主从让我想起了 SVN(我不喜欢它),你
我们当前将 MySQL 配置为支持故障转移:Site1 Site2。当它们被设置为主/主时。在给定时间点,应用程序服务器仅主动写入一个站点。我们想要设置一个新的故障转移站点。然后我们将拥有 Site
我听说过两种数据库架构。 大师-大师 主从 master-master 不是更适合当今的网络吗,因为它就像 Git,每个单元都有整套数据,如果其中一个发生故障,也没关系。 主从让我想起 SVN(我不喜
我正在创建一个标记为类别的表,其中主类别(父列)包含 0,子类别包含父类别的 ID。我听说这叫引用。我的问题:这张表的结构正确吗?或者是否有更好的方法,例如实现遍历树或类似方法? CREATE TAB
我正在阅读一份关于 C++ 与 C 的文档。该文档说与 C 相比,C++ 编写得非常紧凑。一个例子是,C 允许 main() 函数类型为 void。另一方面,C++ 不允许这样做,他给出了标准中的以下
C main函数和Java main函数有什么区别? int main( int argc, const char* argv[] ) 对比 public static void main(Strin
我一直摸不着头脑,但运气不好。设计器有一个包含 3 栏的站点、两个侧边栏和一个主要内容区域。 专为桌面设计,左栏、主要内容、右栏。但是,在较小的设备上,我们希望首先堆叠主要内容。 所以通常情况下,你可
我一直在阅读有关 Jenkins 主/从配置的信息,但我仍然有一些问题: 是不是真的没有像 Jenkins 主站那样安装和启动从站 Jenkins?我假设我会以相同的方式安装一个主 Jenkins 和
据我了解,Viemodel中MVVM背后的概念包括业务逻辑和/或诸如暴露于 View 的数据的主/明细关系之类的事物 因此,正如我发现的那样,有很多ORM生成器,例如模型的telerik a.o以及另
我们有一个群集,其中包含3个主分区,每个主分区有2个副本。主/副本分片的总文档数相同;但是,对于同一查询/文档,我们得到3个不同的分数。当我们将preference = primary添加为查询参数时
我有一个非常大/旧/长时间运行的项目,它使用相对于启动目录的路径访问文件资源(即应用程序仅在从特定目录启动时才工作)。当我需要调试程序时,我可以从 eclipse 启动它并使用“运行配置”->->“工
谁能向我解释一下为什么我在这段代码上遇到段错误?我一直试图弄清楚这一点,但在各种搜索中却一无所获。当我运行代码而不调用 main(argc, argv) 时,它会运行。 Slave 仅将 argv 中
使用 xcode 中的默认项目作为主从应用程序,如果我在折叠委托(delegate)中放置 print 调试语句,当我旋转设备时它似乎永远不会被触发(事实上我永远无法触发它)。 我编辑的代码位于 Ap
是否有任何产品可以使 mysql 主/从故障转移过程更容易?一些可以自动发生的事情,而不是手动修复它。 最佳答案 [...稍后...;) 你所说的“更容易”是什么?MySQL 有很多解决方案: MyS
我有两个 mysql 数据库。我想做主/主复制。 复制以一种方式进行。然而,反过来说却不然。该错误表明它无法与用户“test@IPADDRESS”连接。 如何将用户名更改为 repl?从未进行过测试,
我正在尝试在 MySQL 中运行以下查询: GRANT REPLICATION SLAVE ON *.* TO 'replication'@’10.141.2.%’ IDENTIFIED BY ‘sl
我正在尝试使用 Android 提供的主/详细流程模板创建一个应用程序,并且我正在尝试将多个操作栏菜单项添加到操作栏的主要部分和详细信息部分。这就是我要实现的目标: (来源:softwarecrew.
我正在寻找一个跨平台的 C++ master/worker 库或工作队列库。一般的想法是我的应用程序将创建某种任务或工作对象,将它们传递给工作主机或工作队列,这将依次在单独的线程或进程中执行工作。为了
我似乎看到很多人在他们的 MySQL 模式中任意分配大尺寸的主/外键字段,例如 INT(11) 甚至 WordPress 使用的 BIGINT(20)。 如果我错了,请纠正我,但即使是 INT(4)
如果我有一个可以与多个键相关联的用户,正确的表设置应该是: 一个表有两列,例如: UserName | Key 没有主键且用户可以有多行,或者: 具有匹配标识符的两个表 Table 1 Us
我是一名优秀的程序员,十分优秀!