1. 程式人生 > 實用技巧 >mongo環境快速搭建工具 mlaunch

mongo環境快速搭建工具 mlaunch

安裝

pip3 install mtools psutil pymongo

Usages

mlaunch init 建立一個初始環境並啟動所有節點

引數說明

--single 建立單個獨立節點

--replicaset --nodes 3 指定此副本集的資料承載節點數(不包括仲裁器)。預設值為3

--arbiter 向副本集中新增一個額外的仲裁器

--sharded S [S ...] 建立一個包含3個分片的環境,每個分片由一個單獨的節點組成。 分片名稱為 shard0001,shard0002,shard0003。 它還將建立1個配置伺服器和每個預設情況下1個 mongos。

--config 1 配置伺服器的數量,預設是1

--mongos 1 路由伺服器的數量,預設是1

--hostname localhost

--port 27017 使用 PORT 作為開始埠號

--dir 資料目錄,預設是./data

--binarypath 如果環境有二進位制檔案,則不用指定

示例

  1. 建立一個單點的mongo
mlaunch init --single [--port=27017]
  1. 建立一個副本集
mlaunch init --replicaset [--port=27017]

建立一個帶仲裁節點的副本集

mlaunch --replicaset --nodes 2 --arbiter

埠預設從27017開始,依次為2017,27018,27019

  1. 建立3個shard分片
mlaunch --replicaset --sharded 3
  1. 建立帶副本集的分片,並指定mongos數量
mlaunch init --replicaset --nodes 3 --sharded 3  --config 3  --mongos 1 --port 38017

mlaunch [start stop kill] 啟動當前環境中的部分或全部節點

optional arguments:
--verbose outputs more verbose information.
--dir DIR base directory to start nodes (default=./data/)
--binarypath PATH search for mongod/s binaries in the specified PATH.

引數說明

  • all環境中的所有節點
  • running正在執行: 所有正在執行的節點
  • down所有節點正在關閉
  • mongos 所有的mongos程序
  • mongod 所有 mongod 程序(包括仲裁器和配置伺服器)
  • config全部配置伺服器
  • shard 此標記僅用於標識特定的 shard 編號
  • primary所有執行的主節點
  • secondary所有執行的輔助節點
  • arbiter所有仲裁者
  • <port number>匹配埠號的程序

mlaunch list

mlaunch list [--dir DIR] [--startup] [--tags]
  • --tags list的同時顯示標籤

  • --startup list的同時顯示啟動命令

參考

https://www.jianshu.com/p/f33570f0cd30 mongo 水平擴充套件
https://www.npmjs.com/package/mgeneratejs 生成資料