Deploying MongoDB Replicasets and Sharded Clusters Quickly with mlaunch
This guide explains how to install mlaunch and use it to rapidly set up MongoDB single nodes, replica sets, and sharded clusters, providing step‑by‑step command examples, operational commands, and reference links for efficient testing environments.
1. Installing mlaunch and MongoDB
First install Python3 and required dependencies, then install mlaunch and its Python packages, and finally place the MongoDB binaries (any version) in a directory such as /opt/mongodb-linux-x86_64-* .
## 安装python3,及MongoDB服务的依赖包
shell> yum install -y python3 python3-devel net-snmp-agent-libs
## 安装 mlaunch 依赖包
shell> pip3 install mtools psutil pymongo
## MongoDB软件包安装(解压即可),MongoDB软件包自行下载,当前示例服务器下载了2个版本软件包,可以任意指定其中版本
shell> ll -ld /opt/mongodb-linux-x86_64-*2. Deploying a Replica Set with mlaunch
Initialize a three‑node replica set named demo_replicatset on ports starting from 30000, then manage it with typical operations such as list, login, stop, start, and removal.
## 初始化一个3节点的副本集
## 副本集名称为 demo_replicatset
## 起始端口为 30000
## 版本为 4.4.14
## 数据目录为 /data/demo_rs
shell> mlaunch init --replicaset --nodes 3 --name "demo_replicatset" --priority --port 30000 --binarypath /opt/mongodb-linux-x86_64-rhel70-4.4.14/bin --dir /data/demo_rs
## 查看部署运行的副本集状态
shell> mlaunch list --dir /data/demo_rs/
## 登录副本集
shell> /opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongo --host=localhost:30000
## 停止该副本集
shell> mlaunch stop --dir /data/demo_rs/
## 重启启动该副本集
shell> mlaunch start --dir /data/demo_rs/
## 删除该副本集
shell> rm /data/demo_rs/ -rf3. Deploying a Sharded Cluster with mlaunch
Create a sharded cluster with three config servers, three shard replica sets (each with a single node), and a mongos router, all on sequential ports starting at 30000.
## 创建3节点的分片,每个节点只有1个主
## 配置3节点configServer
## 配置1个mongos
shell> mlaunch init --sharded 3 --nodes 1 --replicaset --config 3 --csrs --mongos 1 --priority --name "demo_shard" --port 30000 --binarypath /opt/mongodb-linux-x86_64-rhel70-4.4.14/bin --dir /data/demo_shard
## 查看部署的集群架构及基本信息
shell> mlaunch list --dir /data/demo_shard/4. Common mlaunch Command Examples
Typical one‑line commands for various deployment patterns, including single‑node replica sets, PSS and PSA architectures, and high‑availability sharded clusters.
## 单节点副本集
mlaunch init \
--replicaset \
--priority \
--nodes 1 \
--name "demo_single_rs" \
--port 30000 \
--binarypath /opt/mongodb-linux-x86_64-rhel70-4.4.14/bin \
--dir /data/demo_single_rs
## 副本集 PSS 架构
mlaunch init \
--replicaset \
--priority \
--nodes 3 \
--name "demo_replicatset" \
--port 30000 \
--binarypath /opt/mongodb-linux-x86_64-rhel70-4.4.14/bin \
--dir /data/demo_rs
## 副本集 PSA 架构
mlaunch init \
--replicaset \
--priority \
--arbiter \
--nodes 3 \
--name "demo_replicatset" \
--port 30000 \
--binarypath /opt/mongodb-linux-x86_64-rhel70-4.4.14/bin \
--dir /data/demo_rs
## 分片集群高可用架构
mlaunch init \
--sharded 3 \
--nodes 3 \
--replicaset \
--config 3 \
--mongos 3 \
--csrs \
--priority \
--name "demo_shard" \
--port 30000 \
--binarypath /opt/mongodb-linux-x86_64-rhel70-4.4.14/bin \
--dir /data/demo_shard5. Reference Links
mlaunch Documentation
mtools GitHub Repository
Aikesheng Open Source Community
The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.