时间:2021-07-01 10:21:17 帮助过:2人阅读
初始化mongod:
初始化副本集,这里形成两个副本集shard-a和shard-b,图示为shard-a初始化:(Wonder为我的主机名)
同理,shard-b也可以初始化。使用rs.status()可以查看副本集的状态:
shard-a:PRIMARY> rs.status() { "set" : "shard-a", "date" : ISODate("2015-08-04T12:11:31.793Z"), "myState" : 1, "members" : [ { "_id" : 0, "name" : "Wonder:30000", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 650, "optime" : Timestamp(1438690267, 1), "optimeDate" : ISODate("2015-08-04T12:11:07Z"), "electionTime" : Timestamp(1438689898, 2), "electionDate" : ISODate("2015-08-04T12:04:58Z"), "configVersion" : 3, "self" : true }, { "_id" : 1, "name" : "Wonder:30001", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 43, "optime" : Timestamp(1438690267, 1), "optimeDate" : ISODate("2015-08-04T12:11:07Z"), "lastHeartbeat" : ISODate("2015-08-04T12:11:29.800Z"), "lastHeartbeatRecv" : ISODate("2015-08-04T12:11:30.115Z" ), "pingMs" : 0, "syncingTo" : "Wonder:30000", "configVersion" : 3 }, { "_id" : 2, "name" : "Wonder:30002", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 23, "optime" : Timestamp(1438690267, 1), "optimeDate" : ISODate("2015-08-04T12:11:07Z"), "lastHeartbeat" : ISODate("2015-08-04T12:11:29.800Z"), "lastHeartbeatRecv" : ISODate("2015-08-04T12:11:29.804Z" ), "pingMs" : 0, "configVersion" : 3 } ], "ok" : 1 }
二.启动配置服务器:
三.启动mongos,配置集群
启动mongos,将config server的信息传入
将shard加入mongos:
查看mongos的集群:
在一台机器上模拟mongodb分片
标签: