Skip to content

MongoDB Sharding-04-Setting up a Sharded Cluster

    1. Log into mongos Console
    [[email protected] tom]# mongo
    MongoDB shell version: 2.6.3
    connecting to: test
    mongos>
    
    2. List all Databases
    mongos> show dbs
    admin	(empty)
    config	0.016GB
    
    3. Switch to config database
    mongos> use config
    switched to db config
    
    4. List all Collections
    mongos> show collections
    changelog
    chunks
    databases
    lockpings
    locks
    mongos
    settings
    shards
    system.indexes
    version
    
    5. Add the Three Shards on Mongos
    mongos> sh.addShard("ReplicaSetNew1/localhost.localdomain:27011")
    { "shardAdded" : "ReplicaSetNew1", "ok" : 1 }
    mongos> sh.addShard("ReplicaSetNew2/localhost.localdomain:27021")
    { "shardAdded" : "ReplicaSetNew2", "ok" : 1 }
    mongos> sh.addShard("ReplicaSetNew3/localhost.localdomain:27031")
    { "shardAdded" : "ReplicaSetNew3", "ok" : 1 }
    
    6. Check Status of the sharded cluster
    mongos> sh.status()
    --- Sharding Status ---
    sharding version: {
    "_id" : 1,
    "version" : 4,
    "minCompatibleVersion" : 4,
    "currentVersion" : 5,
    "clusterId" : ObjectId("53bdcc24ecb20b84c96f5914")
    }
    shards:
    { "_id" : "ReplicaSetNew1", "host" : "ReplicaSetNew1/localhost.localdomain:27011,localhost.localdomain:27012,lo calhost.localdomain:27013" }
    { "_id" : "ReplicaSetNew2", "host" : "ReplicaSetNew2/localhost.localdomain:27021,localhost.localdomain:27022,lo calhost.localdomain:27023" }
    { "_id" : "ReplicaSetNew3", "host" : "ReplicaSetNew3/localhost.localdomain:27031,localhost.localdomain:27032,lo calhost.localdomain:27033" }
    databases:
    { "_id" : "admin", "partitioned" : false, "primary" : "config" } mongos>

    Also See:

    Leave a Reply