|
A mongod process can become part of a sharded cluster without any change to that process or downtime. If you haven't done so yet, feel free to have a look at the Sharding Introduction to familiarize yourself with the components of a sharded cluster and at the Sample Configuration Sesssion to get to know the basic commands involved.
Adding the mongod process to a clusterIf you haven't changed the mongod default port, it would be using port 27017. You care about this now because a mongo shell will always try to connect to it by default. But in a sharded environment, you want your shell to connect to a mongos instead. If the port 27017 is taken by a mongod process, you'd need to bring up the mongos in a different port. Assuming that port is 30000 you can connect your shell to it by issuing: $ mongo <mongos-host-address>:30000/admin We're switching directly to the admin database on the mongos process. That's where we will be able to issue the following command
MongoDB shell version: 1.6.0
connecting to: <mongos-address>:30000/admin
> db.runCommand( { addshard : "192.168.25.203:27017" } )
> { "shardAdded" : "shard0000", "ok" : 1 }
The host address and port you see on the command are the original mongod's. All the databases of that process were added to the cluster and are accessible now through mongos.
> db.runCommand( { listdatabases : 1 } )
{
"databases" : [
{
"name" : "mydb"
...
"shards" : {
"shard0000" : <size-in-shard00000>
}
},
...
Note that that doesn't mean that the database or any of its collections is sharded. They haven't moved (see next). All we did so far is to make them visible within the cluster environment. You should stop accessing the former stand-alone mongod directly and should have all the clients connect to a mongos process, just as we've been doing here. Sharding a collectionAll the databases of your mongod-process-turned-shard can be chunked and balanced among the cluster's shards. The commands and examples to do so are listed at the Difference between upgrading and starting anewYou should pay attention to the host addresses and ports when upgrading, is all. |

PLEASE POST QUESTIONS IN THE FORUMS: http://groups.google.com/group/mongodb-user. Post tips and clarifications here.
blog comments powered by Disqus