跳转到主要内容

用于管理MongoDB服务器的RESTful服务

项目描述

请参阅wiki以获取文档。

Mongo Orchestration是一个HTTP服务器,它为单个主机上的MongoDB配置提供REST API以创建和管理。

此项目用于测试MongoDB驱动程序。

功能

  • 在运行mongo-orchestration的主机上启动和停止mongod服务器、副本集和分片集群。

  • 添加和删除副本集成员。

  • 添加和删除分片和mongos路由器。

  • 重置副本集和集群以重新启动所有已停止的成员。

  • 冻结副本集的次要成员。

  • 检索有关MongoDB资源的详细信息。

  • 通过REST接口进行交互。

  • 使用mongo-launch CLI工具启动简单的本地服务器。

要求

安装

安装Mongo Orchestration最简单的方式是使用pip

pip install mongo-orchestration

您还可以手动安装Mongo Orchestration的开发版本

git clone https://github.com/10gen/mongo-orchestration.git
cd mongo-orchestration
pip install .

以这种方式克隆仓库将使您能够访问Mongo Orchestration的测试以及mo脚本。请注意,您可能需要使用sudo运行上面的命令,具体取决于您安装Mongo Orchestration的位置以及您拥有的权限。安装将把一个mongo-orchestration脚本放置在您的路径上。

使用方法

mongo-orchestration [-h] [-f CONFIG] [-e ENV] [--no-fork] [-b BIND IP="localhost"] [-p PORT]
                    [-s {auto,cheroot,wsgiref}] [--socket-timeout-ms MILLIS]
                    [--pidfile PIDFILE] [--enable-majority-read-concern] {start,stop,restart}

参数

  • -h - 显示帮助

  • -f, –config - 配置文件路径

  • -e, –env - 在配置文件中指定的默认发布版本

  • –no-fork - 在前台运行服务器

  • -b, –bind - Mongo Orchestration和下属mongo进程应监听请求的主机。默认为“localhost”。

  • -s, –server - 要使用的HTTP后端:其中一个是autocherootwsgirefauto配置bottle自动选择一个可用的后端。

  • -p - 端口号(默认为8889)

  • –socket-timeout-ms - 连接到MongoDB服务器时的套接字超时

  • –pidfile - mongo-orchestration放置其pid文件的位置

  • –enable-majority-read-concern - 启用支持的服务器版本上的“majority”读取关注点。

  • start/stop/restart:分别启动、停止或重启服务器

此外,Mongo Orchestration可以通过MONGO_ORCHESTRATION_HOME环境变量来影响,它告知服务器预设的“配置”目录的位置以及日志和pid文件的位置。

示例

mongo-orchestration start

在端口8889上以服务方式启动Mongo Orchestration。

mongo-orchestration stop

停止服务器。

mongo-orchestration -f mongo-orchestration.config -e 30-release -p 8888 --no-fork start

使用在mongo-orchestration.config中定义的30-release在端口8888上启动Mongo Orchestration。使用Ctrl+C停止。

如果您已安装mongo-orchestration但仍然收到command not found: mongo-orchestration,这意味着脚本被安装到了不在您的PATH上的目录中。作为替代方案,可以使用

python -m mongo_orchestration.server start

配置文件

Mongo Orchestration可以使用一个JSON配置文件,通过--config选项指定MongoDB二进制文件的位置。有关示例,请参阅mongo-orchestration.config。当没有提供配置文件时,Mongo Orchestration将使用用户PATH上的任何二进制文件。

预定义配置

Mongo Orchestration有一组预定义的配置,可以用来启动、重启或停止MongoDB进程。您可以使用像curl这样的工具直接将这些文件发送到Mongo Orchestration服务器,或者使用位于scripts目录中的mo脚本(仅在仓库中)。以下是一些示例

  • 启动不带SSL或认证的单节点

    mo configurations/servers/clean.json start
  • 获取不带SSL或认证的单节点状态

    mo configurations/servers/clean.json status
  • 停止不带SSL或认证的单节点

    mo configurations/servers/clean.json stop
  • 启动带有ssl和认证的副本集

    mo configurations/replica_sets/ssl_auth.json start
  • 使用curl创建一个具有id“myCluster”的基本分片集群

    curl -XPUT http://localhost:8889/v1/sharded_clusters/myCluster \
               -d@configurations/sharded_clusters/basic.json

请注意,为了运行 mo 脚本,您需要位于“configurations”目录相同的目录中。

有用提示:您可以通过将响应管道输入 python -m json.tool 来美化服务器返回的 JSON 响应,例如。

$ curl http://localhost:8889/v1/servers/myServer | python -m json.tool

{
    "id": "myServer",
    "mongodb_uri": "mongodb://localhost:1025",
    "orchestration": "servers",
    "procInfo": {
        "alive": true,
        "name": "mongod",
        "optfile": "/var/folders/v9/spc2j6cx3db71l/T/mongo-KHUACD",
        "params": {
            "dbpath": "/var/folders/v9/spc2j6cx3db71l/T/mongo-vAgYaQ",
            "ipv6": true,
            "journal": true,
            "logappend": true,
            "oplogSize": 100,
            "port": 1025
        },
        "pid": 51320
    },
    // etc.
}

Mongo 启动

mongo-launch CLI 工具允许您以最少的配置在本地启动服务器。

mongo-launch –help 使用方法:launch.py [single|replica|shard] [ssl] [auth]

mongo-orchestration start mongo-launch replica ssl auth

测试

为了运行测试,您应该首先克隆 仓库

运行所有测试

python -m unittest

运行测试模块

python -m unittest tests.test_servers

运行单个测试用例

python -m unittest tests.test_servers.ServerSSLTestCase

运行单个测试方法

python -m unittest tests.test_servers.ServerSSLTestCase.test_ssl_auth

以详细和立即的 stdout 输出运行单个测试用例以进行调试

python -m unittest -v tests.test_servers.ServerSSLTestCase

变更日志

版本 0.8.0(2023-05-16)中的更改

  • 添加 mongo-launch CLI 工具。

  • 升级到 PyMongo 4.x 并设置 GitHub Actions 测试。

  • 移除管理 MongoDB 3.4 或更早版本服务器的支持。

  • 移除对 Python 3.5 或更早版本的支持。

  • 将 CherryPy 依赖项替换为 cheroot。 -s auto 是新默认值,-s cherrypy 已不再受支持。

  • 移除 transactionLifetimeLimitSeconds 默认值。

版本 0.7.0(2021-04-06)中的更改

  • 移除管理 MongoDB 2.4 版本服务器的支持。

  • 添加对 Python 3.8 和 3.9 的支持。

  • 添加对 MongoDB 4.2 和 4.4 的支持。

  • 将 pymongo 3.5.1 升级到 3.X 最新版本。(#284)

  • 确保 createUser 在所有副本集成员上成功。(#282)

  • 创建具有 SCRAM-SHA-256 和 SCRAM-SHA-1 的管理员用户。(#281)

  • 在“停止”时等待 mongo-orchestration 服务器完全终止。(#276)

  • 允许以 enableTestCommands=0 启动集群。(#269)

  • 默认情况下将 4.2+ 的 transactionLifetimeLimitSeconds 减少。(#267)

  • 默认情况下增加 maxTransactionLockRequestTimeoutMillis。(#270)

  • 减少 periodicNoopIntervalSecs 以加快驱动程序更改流测试。(#283)

  • 默认情况下在 4.2+ 上启用 ztsd 压缩。(#263)

版本 0.6.12(2018-12-14)中的更改

  • 允许在 IPv6 localhost 上运行 mongo-orchestration 服务器。(#237)

  • 增加默认 mongodb 服务器记录的详细程度。(#255)

  • 修复了在关闭集群时 mongo-orchestration 会永久挂起的错误,如果服务器已经退出。(#253)

由以下支持