mongo-副本集
1. 启动2222和3333,互为副本集
D:\mongodb>mongod --dbpath=d:\mongodb\db --port 2222 --replSet neu/127.0.0.1:3333
E:\mongodb>mongod --dbpath=e:\mongodb\db --port 3333 --replSet neu/127.0.0.1:2222
2. 副本集初始化
C:\>mongo 127.0.0.1:2222/admin
MongoDB shell version: 1.8.3
connecting to: 127.0.0.1:2222/admin
neu:PRIMARY> db.runCommand(
... {
... "replSetInitiate":
... {"_id":"neu",
... "members":[{"_id":1,"host":"127.0.0.1:2222"},{"_id":2,"host":"127.0.0.1:3333"}]
... }
... }
... )
3. 启动仲裁
F:\mongodb>mongod --dbpath=f:\mongodb\db --port 4444 --replSet neu/127.0.0.1:2222
4. 配置仲裁
C:\>mongo 127.0.0.1:2222/admin
MongoDB shell version: 1.8.3
connecting to: 127.0.0.1:2222/admin
neu:PRIMARY> rs.addArb("127.0.0.1:4444")
5. 查看配置结果
neu:PRIMARY> rs.status()
{
"set" : "neu",
"date" : ISODate("2012-10-31T03:40:38Z"),
"myState" : 1,
"members" : [
{
"_id" : 1,
"name" : "127.0.0.1:2222",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"optime" : {
"t" : 1350971304000,
"i" : 1
},
"optimeDate" : ISODate("2012-10-23T05:48:24Z"),
"self" : true
},
{
"_id" : 2,
"name" : "127.0.0.1:3333",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 472,
"optime" : {
"t" : 1350971304000,
"i" : 1
},
"optimeDate" : ISODate("2012-10-23T05:48:24Z"),
"lastHeartbeat" : ISODate("2012-10-31T03:40:36Z")
},
{
"_id" : 3,
"name" : "127.0.0.1:4444",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 62,
"optime" : {
"t" : 0,
"i" : 0
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2012-10-31T03:40:38Z")
}
],
"ok" : 1
}