First select a directory in which to create the following 2 folders: Data and log
Create 9 folders under Data:
The first 3 is the configuration server folder, according to the official website requirements, a cluster requires 3 Config server
Rs-a-n and Rs-b-n are two replica set (replica sets), and our goal is to give them to the cluster.
I. Initializing a replica set
Initialize Mongod:
Initializes the replica set, which forms two replica sets Shard-a and Shard-b, as shown in SHARD-A initialization: (Wonder is my hostname)
Similarly, Shard-b can also be initialized. Use Rs.status () to view the status of the replica set:
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": +, "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": at, "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}
two. Start the configuration server :
Three. Start MONGOs, configure the cluster
Start MONGOs and pass the config server information into
Add Shard to MONGOs:
To view MONGOs clusters:
Simulating MongoDB shards on a single machine