mongoDB pair replication [ two master when remote unreachable ]

本文涉及的产品
云数据库 MongoDB,通用型 2核4GB
简介:
测试环境如图:
使用对外连接的网卡作为心跳网卡,VIP作为与外部应用服务器通信的端口。

mongoDB pair replication [ two master when remote unreachable ] - 德哥@Digoal - The Heart,The World.

当比较神奇的现象出现的时候,假设这两台服务器不通了,但是和外面的应用服务器已经交换机是通的。正常情况下mongoDB会选出新的primary(下面用iptables来模拟)
如下图,A机和B机都变成primary了,
在mongo shell中的表现:
A(原来的primary)机器:
经过一段时间之后(约20秒)
> db.isMaster()
{
        "ismaster" : 1,
        "remote" : "192.168.169.90:5281",
        "info" : "remote unreachable",
        "ok" : 1
}
B机器:
经过一段时间之后(约20秒)
> db.isMaster()
{
        "ismaster" : 1,
        "remote" : "192.168.169.90:5281",
        "info" : "remote unreachable",
        "ok" : 1
}
对于VIP的漂移来说,判断对方不可达了就启VIP。当然你可以选择另外的心跳(比如串口),这里是模拟两台都primary了后面会怎么样?
那么在交换机上192.168.169.99的mac地址会不断的被这两台mongodb服务器刷新成自己的MAC。
应用程序幸运的话可能会对两个数据库都有写入操作.
模拟:
A机器写入数据:
> db.tbl_test.insert({"id" : "a"})
> db.tbl_test.insert({"id" : "a"})
> db.tbl_test.insert({"id" : "a"})
> db.tbl_test.insert({"id" : "a"})
> db.tbl_test.insert({"id" : "a"})
> db.tbl_test.insert({"id" : "a"})
> db.tbl_test.insert({"id" : "a"})
B机器写入数据:
> db.tbl_test.insert({"id" : "b"})
> db.tbl_test.insert({"id" : "b"})
> db.tbl_test.insert({"id" : "b"})
> db.tbl_test.insert({"id" : "b"})
> db.tbl_test.insert({"id" : "b"})
> db.tbl_test.insert({"id" : "b"})
> db.tbl_test.insert({"id" : "b"})

 
mongoDB pair replication [ two master when remote unreachable ] - 德哥@Digoal - The Heart,The World.
 

假设A机器和B机器之间的网络恢复正常了,两台mongodb将重新协商谁将成为primary。(具体的选择算法参考mongoDB手册)
假设A又变成primary了。
来查询一下刚才插入的数据表:
> db.tbl_test.find()
{ "_id" : ObjectId("4d26c6127073f6939f0149e1"), "id" : "b" }
{ "_id" : ObjectId("4d26c6197073f6939f0149e2"), "id" : "b" }
{ "_id" : ObjectId("4d26c6197073f6939f0149e3"), "id" : "b" }
{ "_id" : ObjectId("4d26c6197073f6939f0149e4"), "id" : "b" }
{ "_id" : ObjectId("4d26c6197073f6939f0149e5"), "id" : "b" }
{ "_id" : ObjectId("4d26c61a7073f6939f0149e6"), "id" : "b" }
{ "_id" : ObjectId("4d26c61a7073f6939f0149e7"), "id" : "b" }
{ "_id" : ObjectId("4d26c60355fd2c402a5c025c"), "id" : "a" }
{ "_id" : ObjectId("4d26c61555fd2c402a5c025d"), "id" : "a" }
{ "_id" : ObjectId("4d26c61655fd2c402a5c025e"), "id" : "a" }
{ "_id" : ObjectId("4d26c61655fd2c402a5c025f"), "id" : "a" }
{ "_id" : ObjectId("4d26c61655fd2c402a5c0260"), "id" : "a" }
{ "_id" : ObjectId("4d26c61655fd2c402a5c0261"), "id" : "a" }
{ "_id" : ObjectId("4d26c61655fd2c402a5c0262"), "id" : "a" }
数据被合并了!

mongoDB pair replication [ two master when remote unreachable ] - 德哥@Digoal - The Heart,The World.
 
总结:
1. 选择好的心跳。加入更完善的判断。
相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。   相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
相关文章
|
20天前
|
物联网 编译器 C语言
Y1066 Ble Master Client 记录
Y1066 Ble Master Client 记录
27 1
|
分布式计算 Hadoop 程序员
Apache Hadoop 启动报错:masternode:ssh: connect to host master port 22: Connection timed out 总结
Apache Hadoop 启动报错:masternode:ssh: connect to host master port 22: Connection timed out 总结
314 0
Apache Hadoop 启动报错:masternode:ssh: connect to host master port 22: Connection timed out 总结
|
分布式计算 Hadoop 网络安全
三十一、 master: ssh: connect to host master port 22: No route to host
三十一、 master: ssh: connect to host master port 22: No route to host
三十一、 master: ssh: connect to host master port 22: No route to host
|
MySQL 关系型数据库
master/slave 相同server_id引起的同步失败
昨天在做MySQL SwitchOver遇到一个诡异的想象,切换前后的结构图如下: 当我把一切都切换好之后,应其他需求,重启了04上的mysql,然后show slave status\G发现报错: Last_IO_Error: Fatal error: The slav...
924 0
|
NoSQL 测试技术 数据库
|
MySQL 关系型数据库 RDS
Master-Slave Synchronization for MySQL
MySQL is the world's most popular open-source database.
2866 0