我在 EC2 上设置了 mongodb 的主/从复制。但我看不到复制发生。当我在 master 上“显示 dbs”时,它会显示所有预期的 dbs。
但是当我在副本上做同样的事情时,它没有显示任何数据库。
请帮我解决问题。
在 ubuntu 12.04 ec2 实例上
dpkg -l | grep mongo
ii mongodb-10gen 2.4.5 An object/document-oriented database
rs.config()
{
"_id" : "ittw",
"version" : 1,
"members" : [
{
"_id" : 0,
"host" : "ip-10-304-48-93:27017"
}
]
}
rs.config()
{
"_id" : "ittw",
"version" : 2,
"members" : [
{
"_id" : 0,
"host" : "domU-17-31-19-16-88-5F:27017"
},
{
"_id" : 1,
"host" : "ec2-50-321-52-908.compute-1.amazonaws.com:27017"
}
]
}
rs.status() // replica
{
"set" : "ittw",
"date" : ISODate("2013-08-12T06:55:57Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "$ip:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 356039,
"optime" : Timestamp(1375934685, 1),
"optimeDate" : ISODate("2013-08-08T04:04:45Z"),
"self" : true
}
],
"ok" : 1
}
rs.status() //Master
{
"set" : "ittw",
"date" : ISODate("2013-08-12T06:57:19Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "PRI_IP:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 356543,
"optime" : Timestamp(1376289725, 1),
"optimeDate" : ISODate("2013-08-12T06:42:05Z"),
"self" : true
},
{
"_id" : 1,
"name" : "REP_IP:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 355869,
"optime" : Timestamp(1375934685, 1),
"optimeDate" : ISODate("2013-08-08T04:04:45Z"),
"lastHeartbeat" : ISODate("2013-08-12T06:57:17Z"),
"lastHeartbeatRecv" : ISODate("1970-01-01T00:00:00Z"),
"pingMs" : 1
}
],
"ok" : 1
}
我在 REPLIC 日志中看到以下几行:
Mon Aug 12 07:29:53.889 [initandlisten] connection accepted from $PRIMARY_IP:51376 #11921 (1 connection now open)
Mon Aug 12 07:30:23.922 [conn11921] end connection $PRIMARY_IP:51376 (0 connections now open)
Mon Aug 12 07:30:23.925 [initandlisten] connection accepted from $PRIMARY_IP:51377 #11922 (1 connection now open)
Mon Aug 12 07:30:53.958 [conn11922] end connection $PRIMARY_IP:51377 (0 connections now open)
编辑:在做 rs.initiate() 和 rs.add() 之后
rs.status()
{
"set" : "ittw",
"date" : ISODate("2013-08-12T18:25:20Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "PRIMARY_IP:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1225,
"optime" : Timestamp(1376331887, 1),
"optimeDate" : ISODate("2013-08-12T18:24:47Z"),
"self" : true
},
{
"_id" : 1,
"name" : "SECONDARY_IP:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 33,
"optime" : Timestamp(1376331887, 1),
"optimeDate" : ISODate("2013-08-12T18:24:47Z"),
"lastHeartbeat" : ISODate("2013-08-12T18:25:20Z"),
"lastHeartbeatRecv" : ISODate("2013-08-12T18:25:20Z"),
"pingMs" : 10,
"syncingTo" : "ip-10-190-185-227:27017"
}
],
"ok" : 1
}