标签:
首先选择一个目录在其中建立以下2个文件夹:data和log
在data下建立9个文件夹:
其中前3个为配置服务器所在文件夹,按照官网要求,一个集群需要3个config server
rs-a-n和rs-b-n为两个replica set(副本集) ,我们的目的就是将它们给集群了。
一.初始化副本集
初始化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的集群:
标签:
原文地址:http://www.cnblogs.com/WonderHow/p/4703277.html