需要注意的是,Arbiter服务器只有在主从服务器是偶数个时才能用
像普通的mongod服务器一样,使用如下命令启动Arbiter服务器
mongd --port 27021 --dbpath data5 --replSet rs0
然后通过mongo连接到主服务器,执行如下命令,将2721加入到复本集中
rs.addArb("tom-Inspiron-3521:27021");
执行rs.status()得到如下结果:
rs0:PRIMARY> rs.status(); { "set" : "rs0", "date" : ISODate("2014-11-19T16:29:53Z"), "myState" : 1, "members" : [ { "_id" : 0, "name" : "tom-Inspiron-3521:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", //主服务器 "uptime" : 180, "optime" : Timestamp(1416414576, 1), "optimeDate" : ISODate("2014-11-19T16:29:36Z"), "self" : true }, { "_id" : 1, "name" : "tom-Inspiron-3521:27018", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", //从服务器 "uptime" : 156, "optime" : Timestamp(1416414576, 1), "optimeDate" : ISODate("2014-11-19T16:29:36Z"), "lastHeartbeat" : ISODate("2014-11-19T16:29:51Z"), "lastHeartbeatRecv" : ISODate("2014-11-19T16:29:51Z"), "pingMs" : 0, "syncingTo" : "tom-Inspiron-3521:27017" }, { "_id" : 2, "name" : "tom-Inspiron-3521:27021", "health" : 1, "state" : 7, "stateStr" : "ARBITER", //仲裁服务器 "uptime" : 17, "lastHeartbeat" : ISODate("2014-11-19T16:29:52Z"), "lastHeartbeatRecv" : ISODate("2014-11-19T16:29:51Z"), "pingMs" : 0 //没有syncingTo信息,也就是说,Arbiter不与主服务器做数据同步 } ], "ok" : 1 }
当对Arbiter做查询时,得到的结果是
rs0:ARBITER> db.bar.find(); error: { "$err" : "not master or secondary; cannot currently read from this replSet member", "code" : 13436 }