Version Matrix

CategoryConfiguration
MongoDB versionCommunity 7.0.x / 6.0.x
OSUbuntu 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

  1. Shards: Nodes that actually store data
  2. Config Servers: Stores cluster metadata
  3. 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/ErrorPossible CauseFix
mongos cannot connectconfigsvr not readyWait for PRIMARY election
addShard failedReplica set name inconsistentUnify replica set name
Data only lands on one shardBalancer not enabledEnable balancer
jumbo chunk cannot moveChunk too largeSplit chunk first