Version Matrix
| Category | Configuration |
|---|
| MongoDB version | Community 7.0.x / 6.0.x |
| OS | Ubuntu 22.04/24.04, CentOS 7+ |
Port Planning
- Config Server (cfg): 17017 / 17018 / 17019
- Shard1: 37017-37019
- Shard2: 47017-47019
- Mongos: 27017
Sharded Cluster Core Components
- Shards: Nodes that actually store data
- Config Servers: Stores cluster metadata
- Mongos: Application access entry point
Config Server Setup
dbpath=config/config1
port=17017
configsvr=true
replSet=configsvr
Initialize
var cfg = {
"_id":"configsvr",
"members":[
{"_id":1,"host":"10.10.52.38:17017"},
{"_id":2,"host":"10.10.52.38:17018"},
{"_id":3,"host":"10.10.52.38:17019"}
]
};
rs.initiate(cfg);
Mongos Router Node
port=27017
configdb=configsvr/10.10.52.38:17017,10.10.52.38:17018,10.10.52.38:17019
Add Shards
sh.addShard("shard1/10.10.52.38:37017,10.10.52.38:37018,10.10.52.38:37019");
sh.addShard("shard2/10.10.52.38:47017,10.10.52.38:47018,10.10.52.38:47019");
Enable Sharding
sh.enableSharding("wzk_test")
sh.shardCollection("wzk_test.wzk_test_data",{"name": "hashed"})
Error Quick Reference
| Symptom/Error | Possible Cause | Fix |
|---|
| mongos cannot connect | configsvr not ready | Wait for PRIMARY election |
| addShard failed | Replica set name inconsistent | Unify replica set name |
| Data only lands on one shard | Balancer not enabled | Enable balancer |
| jumbo chunk cannot move | Chunk too large | Split chunk first |