Mongodb – Sharding the Existing MongoDB

mongodbnosql

I've got 3 dedicated non-virtual servers (srv1-3). On one of them (srv1) i've got MongoDB in production, that already have got really big amount of data. At the present time there is no sharding or replica processes, it's just a standalone server.

So, I want this server (srv1) to be as a shrad and config server at the same time. The second server (srv2) is going to be a second shard. And the third one (srv3) is going to be a replica server.

I guess, that I have to run the mongod process on srv1 in two instances: one is the regular in --fork, and the second is --configsrv localhost:27019 (and previously create a separate directory for the config server, like /data/confDB).

After that, I should add sh.addShard("srv1:27017") and sh.addShard("srv2:27017") in mongo console and then just sh.enableSharding(myDBname).

Is that correct? Or it's necessary to create an additional server, that will be the config server?

Best Answer

So, I want this server (srv1) to be as a shrad and config server at the same time. The second server (srv2) is going to be a second shard. And the third one (srv3) is going to be a replica server.

Is that correct? Or it's necessary to create an additional server, that will be the config server?

Yes, you can, As per MongoDB documentation here Changed in version 3.4. Replica Set Config Servers.

Starting in MongoDB 3.2, config servers for sharded clusters can be deployed as a replica set (CSRS) instead of three mirrored config servers (SCCC). Using a replica set for the config servers improves consistency across the config servers, since MongoDB can take advantage of the standard replica set read and write protocols for the config data. In addition, using a replica set for config servers allows a sharded cluster to have more than 3 config servers since a replica set can have up to 50 members. To deploy config servers as a replica set, the config servers must run the WiredTiger storage engine.

In version 3.4, MongoDB removes support for SCCC config servers.

The following restrictions apply to a replica set configuration when used for config servers:

  • Must have zero arbiters.
  • Must have no delayed members.
  • Must build indexes (i.e. no member should have buildIndexes setting set to false).

Examples

The following command adds a replica set as a shard:

use admin
db.runCommand( { addShard: "repl0/mongodb3.example.net:27327"} )

WARNING Do not use localhost for the hostname unless your config server is also running on localhost.