[MongoDB] Build a mongodb sharding cluster on the windows platform (2). mongodb Cluster

Source: Internet
Author: User
Tags mongodb sharding

[MongoDB] Build a mongodb sharding cluster on the windows platform (2). mongodb Cluster

In the previous blog, we talked about the main principles of Mongodb sharding clusters. In this blog, we will mainly describe how to build a sharded cluster. There are two steps to configure a sharding cluster: first, start all the required mongod and mongos processes. The second step is to start a mongos to communicate with the cluster. Next we will describe the cluster building process step by step.


Figure 1-1 components in the MongoDB sharding Cluster


Figure 1-2 Process Overview composed of instance sharding Clusters


Note: The above two pictures are taken from Kyle Banker's Translation of MongoDB practice by Ding Xuefeng

2.1 create a partition directory

Note: This is similar to creating a replica set, For details, see blog: http://blog.csdn.net/sxb0841901116/article/details/40596361


2.2 start replica set

Run the following command to start two replica sets:

mongod --shardsvr --replSet shard-a --dbpath "D:\Program Files\mongodb\data\slide\data\rs-a-1" --port 3000 --logpath "D:\Program Files\mongodb\data\slide\log\rs-a-1.log" --nojournalmongod --shardsvr --replSet shard-a --dbpath "D:\Program Files\mongodb\data\slide\data\rs-a-2" --port 3001 --logpath "D:\Program Files\mongodb\data\slide\log\rs-a-2.log" --nojournalmongod --shardsvr --replSet shard-a --dbpath "D:\Program Files\mongodb\data\slide\data\rs-a-3" --port 3002 --logpath "D:\Program Files\mongodb\data\slide\log\rs-a-3.log" --nojournalmongod --shardsvr --replSet shard-b --dbpath "D:\Program Files\mongodb\data\slide\data\rs-b-1" --port 30100 --logpath "D:\Program Files\mongodb\data\slide\log\rs-b-1.log" --nojournalmongod --shardsvr --replSet shard-b --dbpath "D:\Program Files\mongodb\data\slide\data\rs-b-2" --port 30101 --logpath "D:\Program Files\mongodb\data\slide\log\rs-b-2.log" --nojournalmongod --shardsvr --replSet shard-b --dbpath "D:\Program Files\mongodb\data\slide\data\rs-b-3" --port 30102 --logpath "D:\Program Files\mongodb\data\slide\log\rs-b-3.log" --nojournal

After the operation is successful, the following six black windows will appear:


2.3 start replica set

Start shard-a in the first replica set:

 

You can use the rs. status () command to view the status of the first replica set.

Start the second replica set shard-B:

 

2.4 create a configuration server directory




2.5 run the following command to start the configuration server:
mongod --configsvr --dbpath "D:\Program Files\mongodb\data\slide\data\config-1" --port 27019 --logpath "D:\Program Files\mongodb\data\slide\log\config-1.log" --nojournalmongod --configsvr --dbpath "D:\Program Files\mongodb\data\slide\data\config-2" --port 27020 --logpath "D:\Program Files\mongodb\data\slide\log\config-2.log" --nojournalmongod --configsvr --dbpath "D:\Program Files\mongodb\data\slide\data\config-3" --port 27021 --logpath "D:\Program Files\mongodb\data\slide\log\config-3.log" --nojournal

Use shell to connect to or view the log file to ensure that each configuration server is started and running properly, and verify that each process is listening to the configured port. You can view the logs of each configuration server.

 

View the running process in the task management window:


2.6 start Mongos

You must use the configdb option to start mongos. It accepts a list of configuration server addresses separated by commas:

 

Mongos --configdb WIN--20141018KO:27019,WIN--20141018KO:27020,WIN--20141018KO:27021 --logpath "D:\Program Files\mongodb\data\slide\log\mongos.log" --port 40000

2. Configure the Cluster

Log on to mongos and view the available commands:

 

 

Add the shard-a and shard-B parts to the sharding cluster:

 

 

You can view the sharded cluster in either of the following ways:

 

 



How can I save the mongodb cluster after it is configured? Can it be used after it is started up next time? Windows Environment

It could have been.
In replica set mode, cluster parameters are written inside each node.
For the sharding mode, the Cluster Parameters are written in the configuration server.

How can mongodb deploy an extension cluster with keyfile, one route, three configurations, and three shards?

On the node where the slice is configured
Mongod -- port 27017 -- fork -- logpath ar/log/mongo_shard1.log -- dbpath/data0/mongo/shard1 -- shardsvr
Mongod -- port 27018 -- fork -- logpath ar/log/mongo_shard2.log -- dbpath/data0/mongo/shard2 -- shardsvr
Mongod -- port 27217 -- fork -- logpath ar/log/mongo_config.log -- dbpath/data0/mongo/config -- configsvr
Configure routes
Mongos -- port 27417 -- fork -- logpath ar/log/mongos. log -- configdb 127.0.0.1: 27217 -- chunkSize 1
Configure shard on the client
Mongo -- port 27417
MongoDB shell version: 1.6.5
Connecting to: 127.0.0.1: 27417/test
> Use admin;
Switched to db admin
> Db. runCommand ({addshard: "127.0.0.1: 27017 "})
{"ShardAdded": "shard0000", "OK": 1}
> Db. runCommand ({addshard: "127.0.0.1: 27018 "})
{"ShardAdded": "shard0001", "OK": 1}

Next we enable Sharding for DataBase "foo" and set the shard key of Collection "col" to "{_ id: 1}" to test the Sharding function:
> Db. runCommand ({enablesharding: 'foo '});
{"OK": 1}
> Db. runCommand ({shardcollection: "foo. col", key: {_ id: 1 }});
{"Collectionsharded": "foo. col", "OK": 1}

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.