关于mongodb:技术分享-mlaunchMongoDB-测试环境快速构建工具

4次阅读

共计 4240 个字符,预计需要花费 11 分钟才能阅读完成。

作者:余振兴

爱可生 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.tgz
drwxr-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_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
launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30000
launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30001
launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30002
replica set 'demo_replicatset' initialized.
  
## 查看部署运行的正本集状态
shell> mlaunch list --dir /data/demo_rs/
PROCESS    PORT     STATUS     PID
mongod     30000    running    9017
mongod     30001    running    9065
mongod     30002    running    9113
  
## 登录正本集 (默认无明码, 可也在初始化时指定)
shell> /opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongo --host=localhost:30000
demo_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 30000
launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30001
launching: "/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 个 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
launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30001
launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30002
launching: "/opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongod" on port 30003
launching: config server on port 30004
launching: config server on port 30005
launching: config server on port 30006
replica 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 30000
adding shards. can take up to 30 seconds...
  
## 查看部署的集群架构及根本信息
[root@10-186-61-159 ~]# mlaunch list --dir /data/demo_shard/
PROCESS          PORT     STATUS     PID
mongos           30000    running    15820
config server    30004    running    15514
config server    30005    running    15567
config server    30006    running    15620
shard01
    mongod       30001    running    15377
shard02
    mongod       30002    running    15422
shard03
    mongod       30003    running    15469
  
## 登录集群
shell> /opt/mongodb-linux-x86_64-rhel70-4.4.14/bin/mongo --host=localhost:30000
mongos>

四、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…

正文完
 0