§2023-07-25
Database sharding is the process of splitting up records that would normally be held in the same table or collection and distributing them across multiple machines, known as shards. Sharding is especially useful in cases where you’re working with large amounts of data, as it allows you to scale your base horizontally by adding more machines that can function as new shards.
Additionally, MongoDB recommends that a sharded cluster’s shard servers and config server
all be deployed as replica sets
with at least three members
. Again, though, in order to get a sharded cluster up and running quickly,
this guide outlines how to deploy these components as single-node replica sets.
¶Prerequisites
Machine | IP | OS | mongod Version | Replication Set | momgosh Avialbale | Saharding |
---|---|---|---|---|---|---|
hc4Jammy.yushei.com.tw:2701 | 192.168.2.195 | odroid-hc4 Ubuntu Jammy | 7.0.0-rc8 | odroid01 | Yes | No |
N2Jammy.yushei.com.tw:27017 | 192.168.2.177 | odroid-n2+ Ubuntu Jammy | 7.0.0-rc8 | odroid01 | No | No |
x8664Arch.yushei.com.tw:27017 | 192.168.2.132 | AMD x86_64 ArchLinux | 7.0.0-rc8 | odroid01 | Yes | No |
orgpi5Arch.yushei.net:27017 | 192.168.48.241 | Orange Pi 5 Plus, 16G mem, PCIeSSD 256G Archlinux | 7.0.0-rc8 | N/A | Yes | No |
orgpi5Jammy.yushei.net | 192.168.48.247 | Orange Pi 5 Plus, 8G mem, PCIeSSD 256G Ubuntu Jammy | 7.0.0-rc8 | N/A | Yes | No |
hc4Jammy.yushei.net | 192.168.48.243 | Odroid-hc4 Ubuntu Jammy | 7.0.0-rc8 | N/A | Yes | No |
h2Jammy.yushei.net | 192.168.11.248/ |
n2Mnjaro.yushei.net. 7200 IN A 192.168.48.245
For clarity, this tutorial will refer to the four servers as follows:
mongo-config, which will function as the cluster’s config server. mongo-shard1 and mongo-shard2, which will serve as shard servers where the data will actually be distributed. mongo-router, which will run a mongos instance and function as the shard cluster’s query router.