Simulating MongoDB shards on a single machine

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.