Chapter 17. Sharding Administration
As with replica sets, you have a number of options for administering sharded clusters. Manual administration is one option. These days it is becoming increasingly common to use tools such as Ops Manager and Cloud Manager and the Atlas Database-as-a-Service (DBaaS) offering for all cluster administration. In this chapter, we will demonstrate how to administer a sharded cluster manually, including:
Inspecting the cluster’s state: who its members are, where data is held, and what connections are open
Adding, removing, and changing members of a cluster
Administering data movement and manually moving data
Seeing the Current State
There are several helpers available to find out what data is where, what the shards are, and what the cluster is doing.
Getting a Summary with sh.status()
sh.status()
gives you an overview of your shards, databases, and sharded
collections. If you have a small number of chunks, it will print a
breakdown of which chunks are where as well. Otherwise it will simply
give the collection’s shard key and report how many chunks each shard
has:
>
sh
.
status
()
---
Sharding
Status
---
sharding
version
:
{
"_id"
:
1
,
"minCompatibleVersion"
:
5
,
"currentVersion"
:
6
,
"clusterId"
:
ObjectId
(
"5bdf51ecf8c192ed922f3160"
)
}
shards
:
{
"_id"
:
"shard01"
,
"host"
:
"shard01/localhost:27018,localhost:27019,localhost:27020"
,
"state"
:
1
}
{
"_id"
:
"shard02"
,
"host"
:
"shard02/localhost:27021,localhost:27022,localhost:27023"
,
"state"
:
1
}
{
"_id"
:
"shard03" ...
Get MongoDB: The Definitive Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.