开始使用 MongoDB Ops Manager
MongoDB CLI 为管理您的MongoDB Ops Manager 项目和集群提供命令行界面。
本教程演示了如何
在您的
Ops Manager
项目中创建集群检索新集群的详细信息
本教程中提到的命令的参考页面可在MongoDB CLI 命令中找到.
先决条件
在开始之前,完成以下任务
创建集群
使用mongocli ops-manager clusters create命令在Ops Manager.
以下命令创建具有以下设置的示例集群
集群名称:
getStarted
MongoDB服务器版本:
5.0.0
功能兼容版本:
5.0
副本集成员:
3
成员主机名:
host1
、host2
、host3
注意
本教程使用主机名
host1
、host2
和host3
。请用有效的MongoDB服务器主机名替换这些主机名。每个
mongod
实例的数据目录:/data/cluster/rs1
、/data/cluster/rs2
、/data/cluster/rs3
每个
mongod
实例的日志文件路径:/data/cluster/rs1/mongodb.log
、/data/cluster/rs2/mongodb.log
、/data/cluster/rs3/mongodb.log
每个
mongod
进程的端口:29010
、29020
、29030
每个成员的投票优先级:
1
每个成员的投票数:
1
将以下集群和副本集配置属性复制并粘贴到名为 getStartedCluster.json
的文件中。
要了解更多有关配置文件属性的信息,请参阅 集群配置文件。
{ "name": "getStarted", "version": "5.0.0", "featureCompatibilityVersion": "5.0", "processes": [ { "hostname": "host1", "dbPath": "/data/cluster/rs1", "logPath": "/data/cluster/rs1/mongodb.log", "priority": 1, "votes": 1, "port": 29010 }, { "hostname": "host2", "dbPath": "/data/cluster/rs2", "logPath": "/data/cluster/rs2/mongodb.log", "priority": 1, "votes": 1, "port": 29020 }, { "hostname": "host3", "dbPath": "/data/cluster/rs3", "logPath": "/data/cluster/rs3/mongodb.log", "priority": 1, "votes": 1, "port": 29030 } ] }
检索集群
您可以使用 mongocli ops-manager clusters describe 命令检索集群详细信息来检查您的集群是否已成功创建。
mongocli ops-manager cluster describe getStarted
您的命令输出应类似于以下内容
{ "mongoURI": "mongodb://host1:29010,host2:29020,host3:29030", "name": "getStarted", "processes": [ { "buildIndexes": true, "db_path": "/data/cluster/rs1", "featureCompatibilityVersion": "5.0", "hostname": "host1", "log_path": "/data/cluster/rs1/mongodb.log", "name": "getStartedCluster", "port": 29010, "priority": 1, "process_type": "mongod", "slave_delay": 0, "version": "5.0.0", "votes": 1, "arbiter_only": false, "disabled": false, "hidden": false }, { "buildIndexes": true, "db_path": "/data/cluster/rs2", "featureCompatibilityVersion": "5.0", "hostname": "host2", "log_path": "/data/cluster/rs2/mongodb.log", "name": "getStartedCluster", "port": 29020, "priority": 1, "process_type": "mongod", "slave_delay": 0, "version": "5.0.0", "votes": 1, "arbiter_only": false, "disabled": false, "hidden": false }, { "buildIndexes": true, "db_path": "/data/cluster/rs3", "featureCompatibilityVersion": "5.0", "hostname": "host3", "log_path": "/data/cluster/rs3/mongodb.log", "name": "getStartedCluster", "port": 29030, "priority": 1, "process_type": "mongod", "slave_delay": 0, "version": "5.0.0", "votes": 1, "arbiter_only": false, "disabled": false, "hidden": false } ] }
监控自动化配置状态
运行 mongocli ops-manager automation watch 命令以确定集群是否已准备好使用。以下命令使用默认配置文件访问 Ops Manager
项目
mongocli om automation watch
总结
恭喜!您已成功创建了一个用于存储数据的集群。您可以使用 连接字符串 连接到您的集群,使用 mongosh
或您的应用程序,或通过登录 UI 查看您的集群。