1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| config = { _id: 'mongo1', members: [ {_id: 0, host: '192.168.0.104:27017', priority:1}, #主mongo {_id: 1, host: '192.168.0.107:27017'} #其他 mongo ] } rs.initiate(config) rs.conf() rs.status() # 返回结果 { "set" : "mongo1", "date" : ISODate("2016-10-11T08:14:16.365Z"), "myState" : 1, "members" : [ { "_id" : 0, "name" : "192.168.0.104:27017", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 1713, "optime" : Timestamp(1476173146, 1), "optimeDate" : ISODate("2016-10-11T08:05:46Z"), "electionTime" : Timestamp(1476172001, 1), "electionDate" : ISODate("2016-10-11T07:46:41Z"), "configVersion" : 84486, "self" : true }, { "_id" : 1, "name" : "192.168.0.107:27017", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 1656, "optime" : Timestamp(1476173146, 1), "optimeDate" : ISODate("2016-10-11T08:05:46Z"), "lastHeartbeat" : ISODate("2016-10-11T08:14:15.569Z"), "lastHeartbeatRecv" : ISODate("2016-10-11T08:14:14.929Z"), "pingMs" : 0, "syncingTo" : "192.168.0.104:27017", "configVersion" : 84486 } ], "ok" : 1 } # 如果配置有误 health:0 显示为0 # 重新配置加 force:true rs.reconfig(config, {force: true})
|