作者:余振兴
爱可生 DBA 团队成员,热衷技术分享、编写技术文档。
本文起源:原创投稿
*爱可生开源社区出品,原创内容未经受权不得随便应用,转载请分割小编并注明起源。
目录:
- 一、mlaunch 及 MongoDB软件装置
- 二、mlaunch 部署正本集及运维操作
- 三、mlaunch 部署分片集群
- 四、mlaunch 罕用部署架构命令示例
- 五、参考链接
咱们在应用和学习 MongoDB 过程中不免遇到须要部署各类架构进行功能性验证,因为不同的架构和配置,使得咱们在搭建环境过程中须要破费大量工夫,这里举荐应用一款可疾速部署 MongoDB 测试环境各类架构的工具 mlaunch ,它是 MongoDB 一组开源工具包 mtools 中的一个(对 mtools 的其余工具有趣味也可查看文末链接地址理解详情),可用来在测试环境疾速部署不同架构的 MongoDB 服务,反对单节点、正本集以及分片集群,装置及操作均非常简略,以下给到罕用场景和架构的部署示例
一、mlaunch 及 MongoDB软件装置
## 装置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-*drwxr-xr-x 4 root root 148 8月 16 18:30 /opt/mongodb-linux-x86_64-enterprise-rhel70-4.0.16-rw-r--r-- 1 root root 120608697 8月 16 18:30 /opt/mongodb-linux-x86_64-enterprise-rhel70-4.0.16.tgzdrwxr-xr-x 3 root root 100 8月 16 18:31 /opt/mongodb-linux-x86_64-rhel70-4.4.14-rw-r--r-- 1 root root 72399766 8月 16 18:25 /opt/mongodb-linux-x86_64-rhel70-4.4.14.tgz
二、mlaunch 部署正本集及运维操作
## 初始化一个3节点的正本集## 正本集名称为 demo_replicatset## 起始端口为 30000## 指定30000端口的优先级最高(优先级默认为1,主节点调整为10,值越高,优先级越高)## 版本为 4.4.14## 数据目录为 /data/demo_rsshell> 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_rslaunching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30000launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30001launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30002replica set 'demo_replicatset' initialized. ## 查看部署运行的正本集状态shell> mlaunch list --dir /data/demo_rs/PROCESS PORT STATUS PIDmongod 30000 running 9017mongod 30001 running 9065mongod 30002 running 9113 ## 登录正本集(默认无明码,可也在初始化时指定)shell> /opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongo --host=localhost:30000demo_replicatset:PRIMARY> ## 进行该正本集shell> mlaunch stop --dir /data/demo_rs/sent signal Signals.SIGTERM to 3 processes. ## 重启启动该正本集shell> mlaunch start --dir /data/demo_rs/launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30000launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30001launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30002 ## 删除该正本集(进行后间接删除目录即可)shell> rm /data/demo_rs/ -rf
三、mlaunch 部署分片集群
## 创立3节点的分片,每个节点只有1个主(思考服务器配置无限)## 配置3节点configServer## 配置1个mongosshell> 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_shardlaunching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30001launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30002launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30003launching: config server on port 30004launching: config server on port 30005launching: config server on port 30006replica set 'configRepl' initialized.replica set 'shard01' initialized.replica set 'shard02' initialized.replica set 'shard03' initialized.launching: /opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongos on port 30000adding shards. can take up to 30 seconds... ## 查看部署的集群架构及根本信息[root@10-186-61-159 ~]# mlaunch list --dir /data/demo_shard/PROCESS PORT STATUS PIDmongos 30000 running 15820config server 30004 running 15514config server 30005 running 15567config server 30006 running 15620shard01 mongod 30001 running 15377shard02 mongod 30002 running 15422shard03 mongod 30003 running 15469 ## 登录集群shell> /opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongo --host=localhost:30000mongos>
四、mlaunch 罕用部署架构命令示例
## 单节点正本集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 ## 分片集群高可用架构## 3节点ConfigServer 正本集## 3节点shard分片节点 正本集## 3节点mongos 高可用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_shard
五、参考链接
http://blog.rueckstiess.com/m...
https://github.com/ruecksties...