To build a sharded MongoDB cluster on Ubuntu, deploy three kinds of processes: shard replica sets that store application data, a config-server replica set that stores cluster metadata, and one or more mongos routers that applications connect to. For production, MongoDB documents three config-server members and three members in each shard replica set; a one-member layout is suitable only for development or testing.
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
The practical sequence is to provision private, name-resolvable VPS nodes; install the same MongoDB major version everywhere; configure internal authentication before allowing remote traffic; initialize the config and shard replica sets; start redundant routers; add shards through mongos; and then choose a shard key from measured query and write patterns.
As an Amazon Associate I earn from qualifying purchases.
Free tools Windows power users keep installed
One-click scans. No signup required.
Understand the cluster before creating it
MongoDB describes a sharded cluster as a combination of shards, routing through mongos, and config servers. Treat those as separate responsibilities even when development hardware places more than one process on a host.
Shard replica sets store the data
Each shard contains only a portion of a sharded collection. A shard is normally a replica set, not a standalone mongod, so one member can become primary while secondaries replicate the same shard data. Every shard replica set must have its own unique replica-set name, such as shard01RS or shard02RS.
#1 Best Overall
- BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
- EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
- COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
- LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
- WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.
The config-server replica set stores metadata
Config servers hold the cluster metadata that tells routers where chunks or ranges belong. They do not replace the data-bearing shards. MongoDB’s production reference topology uses a three-member config-server replica set. MongoDB 8.0 also documents a config-shard architecture in which a shard can host config data; the procedure below uses the dedicated config-server replica-set design because it is easier to reason about when building a first cluster.
mongos routes client operations
mongos is stateless from the application’s point of view. It reads metadata from the config replica set, routes each operation to the relevant shard or shards, and returns the result. Run at least one router for a test cluster and more than one when router failure must not interrupt application access. Applications should use router hostnames rather than connecting directly to shard members.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Choose a topology that matches the purpose
| Use case | Logical members | Failure behavior | Placement guidance |
|---|---|---|---|
| Development or testing | One config-server member, one shard replica-set member, and one mongos |
No replica-set failover; suitable for validating commands and application integration | These can be three small VPS instances or processes on fewer machines when isolation is unimportant |
| Production with one shard | Three config-server members, three members in the shard replica set, and one or more mongos routers |
Replica-set elections and router redundancy are available when members remain reachable | Use independent failure domains; MongoDB recommends at least three data centers when feasible |
| Production with multiple shards | Three config-server members, three members for every shard replica set, and one or more mongos routers |
Each shard can fail over independently, while config metadata remains a separate quorum | Spread config and shard members across zones or data centers rather than concentrating a quorum in one location |
If every logical member receives its own VPS, a one-shard production cluster starts at seven instances: three config servers, three shard members, and one router. Routers are lightweight and stateless, so the number of router VPS instances should be driven by availability and connection load rather than by the replica-set quorum.
Plan the Ubuntu VPS network
Use stable names and private connectivity
Assign a permanent DNS name to every member, for example cfg1.db.internal, cfg2.db.internal, cfg3.db.internal, sh1a.db.internal, and mongos1.db.internal. Use those names in replica-set configuration and sharded-cluster connection strings. Names avoid having to rewrite replica-set metadata after a private address changes and make certificate identity management possible later.
Put inter-node traffic on a private network. Firewall rules should allow only the configured MongoDB ports from the other cluster members and from approved administration hosts. Do not expose a database listener to the public internet simply because the VPS has a public address.
Synchronize clocks and plan storage
Enable reliable time synchronization on every VPS before initiating any replica set. Clock drift complicates elections, certificate validation, and incident timelines. Select storage with enough IOPS for the write workload, leave headroom for index growth and replication, and decide where backups will be stored before production data arrives.
Use a supported Ubuntu image
MongoDB 8.0 documentation lists 64-bit Ubuntu 20.04, 22.04, and 24.04 support on documented x86_64 platforms, with selected ARM64 support. Confirm that your chosen VPS architecture is covered by the current MongoDB installation documentation. Install the same MongoDB major version on every mongod and mongos host.
Install MongoDB 8.0 packages
On each VPS, start with the operating-system prerequisites:
Rank #2
- WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
- AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
- PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
- ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
- COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed
sudo apt-get update
sudo apt-get install -y gnupg curl
Import the MongoDB 8.0 signing key using the command from MongoDB’s Ubuntu 8.0 installation documentation, then create /etc/apt/sources.list.d/mongodb-org-8.0.list with the repository entry for the machine’s Ubuntu LTS codename: Noble for 24.04, Jammy for 22.04, or Focal for 20.04. Do not use a repository line for a different release.
sudo apt-get update
sudo apt-get install -y mongodb-org
When reproducibility matters, pin the package versions after testing them and record the exact versions installed on every node. Review the current MongoDB release notes and platform-support page before a production rollout; package availability and supported operating-system combinations can change.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallKeep the default mongod service stopped while you are writing its final configuration, or stop it before replacing the package-generated configuration:
sudo systemctl stop mongod
sudo systemctl disable mongod
Set up internal authentication before remote access
Use a keyfile for a lab or development cluster
A keyfile is convenient for a small test deployment, but MongoDB documents its limited manageability and cryptographic strength. Generate one on a protected administration host, transfer it over a secure channel to every mongod and mongos, and keep identical contents everywhere:
openssl rand -base64 756 | sudo tee /etc/mongodb-keyfile > /dev/null
sudo chown mongodb:mongodb /etc/mongodb-keyfile
sudo chmod 400 /etc/mongodb-keyfile
Do not put the keyfile in a world-readable directory, source-control repository, image template, or shell history. For production, evaluate TLS with X.509 or another strong mechanism such as LDAP proxy authentication or Kerberos instead of relying on a keyfile alone.
Configure host binding and authorization
MongoDB binds to localhost by default. That default prevents remote members from joining until you explicitly add approved hostnames. On each config-server member, use a role-specific configuration like this and substitute that member’s own hostname in net.bindIp:
security:
keyFile: /etc/mongodb-keyfile
authorization: enabled
sharding:
clusterRole: configsvr
replication:
replSetName: cfgRS
net:
bindIp: localhost,cfg1.db.internal
port: 27017
On a shard member, keep the security and network settings but change the role and replica-set name:
security:
keyFile: /etc/mongodb-keyfile
authorization: enabled
sharding:
clusterRole: shardsvr
replication:
replSetName: shard01RS
net:
bindIp: localhost,sh1a.db.internal
port: 27017
The same structure applies to every member; only the hostname and the shard’s replica-set name change. The first administrator can be created through the localhost exception after the first secured member is running. Create named administrative and application users with only the roles they need, and use MongoDB’s role-based access control for client access instead of sharing the cluster bootstrap account.
Rank #3
- Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
- Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
- Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
- ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
- Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)
Initialize the config-server replica set
Start the members
After placing the configuration on all three config hosts, start the service on each one:
sudo systemctl enable --now mongod
Check the service log and connect locally with mongosh. Confirm that DNS names resolve in both directions and that the firewall allows the other config members to reach the configured port.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Initiate the config replica set once
Connect to one config member and initiate the set with configsvr: true. The _id must exactly match the replication.replSetName value:
rs.initiate({
_id: "cfgRS",
configsvr: true,
members: [
{ _id: 0, host: "cfg1.db.internal:27017" },
{ _id: 1, host: "cfg2.db.internal:27017" },
{ _id: 2, host: "cfg3.db.internal:27017" }
]
})
Wait for a primary and secondaries before continuing. Run rs.status() and verify that all three members report the expected state. A production config-server replica set requires at least three members so it can maintain a quorum during a single-member failure.
Initialize each shard replica set
Configure and start the first shard
For shard01RS, place the shard-role configuration on sh1a, sh1b, and sh1c. Keep the keyfile, authorization, port, and approved bind-address pattern consistent. Start mongod on all three hosts:
sudo systemctl enable --now mongod
Initiate the shard set from one member:
rs.initiate({
_id: "shard01RS",
members: [
{ _id: 0, host: "sh1a.db.internal:27017" },
{ _id: 1, host: "sh1b.db.internal:27017" },
{ _id: 2, host: "sh1c.db.internal:27017" }
]
})
Wait for one primary and healthy secondaries before adding the shard to the cluster. Repeat the process for every additional shard, changing both the hostnames and the replica-set name, for example shard02RS.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Do not mix replica-set names
A frequent configuration error is copying a shard file and leaving the previous replSetName in place. A shard’s connection string, its rs.initiate() document, and its replication.replSetName must all use the same value. The config replica set must remain a different name from every shard set.
Deploy and secure mongos
Create the router configuration
On each router host, create /etc/mongos.conf with the config replica-set connection string. A router needs the config-server addresses, not a list of shard members:
Rank #4
- Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
- Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
- 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
- Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
- USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC
sharding:
configDB: cfgRS/cfg1.db.internal:27017,cfg2.db.internal:27017,cfg3.db.internal:27017
security:
keyFile: /etc/mongodb-keyfile
clusterAuthMode: keyFile
net:
bindIp: localhost,mongos1.db.internal
port: 27017
Copy the protected keyfile to the router and ensure the router can resolve every config hostname. Start mongos using a dedicated service account and log directory. A direct launch for a test host is:
Recommended Free Tools
sudo mkdir -p /var/log/mongodb
sudo chown mongodb:mongodb /var/log/mongodb
sudo -u mongodb mongos --config /etc/mongos.conf --fork --logpath /var/log/mongodb/mongos.log
For production, create a systemd unit so the router starts after reboot, restarts on failure, and has explicit ownership and resource limits. Repeat the router deployment on additional hosts when application availability requires it.
Add the shard replica sets through a router
Connect mongosh to the router, authenticate, and add each shard with its replica-set name and member addresses:
sh.addShard("shard01RS/sh1a.db.internal:27017,sh1b.db.internal:27017,sh1c.db.internal:27017")
sh.addShard("shard02RS/sh2a.db.internal:27017,sh2b.db.internal:27017,sh2c.db.internal:27017")
db.adminCommand({ listShards: 1 })
The command must be run against mongos, not directly against a shard primary. The result should list each shard with the expected replica-set name and members. If a shard cannot be added, check DNS, keyfile identity, firewall rules, and whether the shard has elected a primary.
Enable sharding and choose a shard key deliberately
Enable sharding for the database
Once listShards is correct, enable sharding for the application database:
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchessh.enableSharding("appdb")
Then shard a collection with a key that reflects actual workload patterns. The following is only a syntax example; it is not a universal recommendation:
sh.shardCollection("appdb.events", { tenantId: "hashed" })
Evaluate the key against real traffic
- Query targeting: Prefer a field commonly present in filters so routers can target a subset of shards instead of broadcasting every operation.
- Cardinality: The field needs enough distinct values to distribute data and chunks; a low-cardinality field can create hot shards.
- Write distribution: Examine whether inserts arrive at one end of a range or concentrate on a single value.
- Range behavior: Range-based keys support locality and range queries but can create uneven growth; hashed keys spread values more evenly but do not preserve useful range locality.
- Uniqueness is not enough: A unique field can still be a poor shard key if queries do not include it or if the write pattern makes one shard hot.
Measure representative reads and writes before committing to a key. Changing a shard key later is an operational project, so treat key selection as a workload decision rather than a setup checkbox.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Verify the cluster before sending application traffic
Run health checks on every replica set
From an authenticated shell connected to each replica set, inspect:
Best Value
- Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
- Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
- Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
- Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
- Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
rs.status()
rs.printSecondaryReplicationInfo()
Confirm that each set has one primary, expected secondary members, and acceptable replication lag. Also check that the hostnames shown in the status output are the stable names you intend to keep.
Check cluster metadata through mongos
db.adminCommand({ listShards: 1 })
sh.status()
Verify that all configured shards appear, the config replica set is reachable, and the router can refresh metadata. Test a read and write through every router hostname your application will use.
Exercise failure paths before production
- Stop one shard secondary and confirm that the primary continues serving and the secondary can rejoin.
- Step down or stop a primary during a maintenance window and verify that an election completes and clients retry correctly.
- Stop one config-server member and confirm that the remaining quorum keeps metadata operations available.
- Stop one
mongosand verify that the application or connection pool fails over to another router. - Restore a backup into an isolated environment and document the exact recovery sequence.
- Temporarily apply the production firewall policy and confirm that only intended node-to-node and administrative paths remain.
Harden the public edge and inter-node traffic
Bind only to approved interfaces
Do not replace localhost with 0.0.0.0 as a shortcut. Add the private hostname or private address that other members actually use, keep administration on a separate allowlist, and ensure the VPS provider’s network firewall agrees with the host firewall. MongoDB’s documented warning is direct: before binding an instance to a publicly accessible address, secure the cluster against unauthorized access.
Use authentication consistently
Every mongod and mongos must use the same internal-authentication policy. For intra-cluster SCRAM on MongoDB 5.3 and later, use SCRAM-SHA-256. Production deployments should consider TLS and X.509 or another centrally managed mechanism when keyfile handling is not sufficient. Keep client authorization enabled and issue separate users for applications, operators, monitoring, and backups.
Separate client and replication exposure
Applications should reach routers, not shard or config-server listeners. Restrict shard and config ports to the cluster’s private network and management sources. If TLS is enabled, use certificates whose names match the hostnames used in replica-set and router configuration.
Operate the cluster after launch
Protect config-server data
Back up the config database before maintenance and include its recovery procedure in the disaster plan. Config metadata is essential even though application documents live on shards. If a config-server primary cannot be elected, metadata operations become read-only and chunk migrations or splits stop. If all config servers are unavailable, the cluster can become inoperable.
Monitor the signals that predict trouble
- Replica lag and repeated elections on every shard and on the config replica set
- Disk utilization, storage latency, and sudden index or journal growth
- Chunk balancing activity and persistent imbalance between shards
mongosconnection failures, rejected operations, and stale metadata warnings- Firewall drops, DNS failures, and authentication errors between members
Alert on trends rather than waiting for a complete outage. A growing replication lag window, frequent primary changes, or sustained disk pressure should trigger investigation before a member falls out of the quorum.
Keep versions and configuration reproducible
Record the Ubuntu release, MongoDB package version, replica-set names, hostnames, bind addresses, authentication method, and firewall rules for every node. Apply upgrades consistently and preserve the ability to rebuild a member from a clean VPS image and a documented backup.
Quick Recap
Troubleshoot common setup failures
| Symptom | Likely cause | Corrective action |
|---|---|---|
| A new member cannot join and the log shows connection timeouts | The process is still bound to localhost, DNS is wrong, or a firewall blocks the configured port | Check net.bindIp, resolve both hostnames from every member, and allow only the required private traffic |
| A replica set has no primary | Members cannot reach a quorum, clocks differ, or replica-set hostnames do not resolve consistently | Restore connectivity to a majority, synchronize clocks, and correct the host strings before re-running status checks |
| Authentication fails between members | Keyfile contents, ownership, permissions, or authentication mode differ | Compare the protected keyfile byte-for-byte, set restrictive ownership and mode, and apply the same internal-authentication settings everywhere |
sh.addShard() fails |
The command was sent to a shard instead of mongos, or the shard has no healthy primary |
Reconnect to the router, verify rs.status() on the shard, and use the exact replica-set connection string |
| Chunk migrations or splits stop | The config-server primary cannot be elected | Restore config-server quorum and verify replication before attempting balancing again |
| Routers report stale metadata | A router cannot refresh from the config replica set or inter-node connectivity is intermittent | Check config-server health, DNS, firewall logs, and router logs; resolve the underlying connectivity issue before restarting routers |
Production go-live checklist
- All hosts run a supported 64-bit Ubuntu release and the same MongoDB major version.
- Production config and shard replica sets have three members, with members distributed across independent failure domains where feasible.
- Every member has a stable DNS name, synchronized clock, private network path, and restrictive firewall policy.
- Internal authentication is enabled consistently; client users use RBAC; production authentication is protected with an appropriate strong mechanism.
- At least two routers are available when router failure must not interrupt service.
- Each shard has a primary and healthy secondaries, and
mongosreports all expected shards. - The shard key has been evaluated against query targeting, cardinality, write distribution, and range behavior.
- Config-server backups, shard backups, restore tests, election tests, router failover tests, and firewall tests are documented.
- Monitoring covers replication lag, elections, disk pressure, balancing, router connectivity, and stale metadata.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →




