简体   繁体   English

启动mongodb单服务器作为副本集通过supervisord启用oplog

[英]starting mongodb single server as replica set to enable oplog through supervisord

I want to start a single mongod instance with command mongod --config config/mongod.conf Once above process starts running I also have to call mongodb/bin/mongo --eval rs.initiate() Now the issue is I am starting mongod through supervisord I want to perform both of the above operation one after another.我想使用命令mongod --config config/mongod.conf启动单个 mongod 实例一旦上述过程开始运行,我还必须调用mongodb/bin/mongo --eval rs.initiate()现在问题是我正在启动 mongod通过 supervisord 我想一个接一个地执行上述两个操作。 supervisord takes just 1 command to start the process which is first command. supervisord 只需要 1 个命令来启动进程,这是第一个命令。 I have no other place to run the rs.initiate().我没有其他地方可以运行 rs.initiate()。 If I put both the command in shell script even then the control will be stuck with the first command itself.如果我将两个命令都放在 shell 脚本中,那么控件将被第一个命令本身卡住。

Perhaps you could combine the commands into a single command.也许您可以将这些命令合并为一个命令。 Ie, IE,

mongod --config config/mongod.conf && sleep 5 && mongodb/bin/mongo --eval rs.initiate()

The sleep command assumes 5 seconds is enough for the mongod to come up and be available for an rs.initiate(). sleep 命令假设 5 秒足以让 mongod 出现并可供 rs.initiate() 使用。 Given you are initiating a replica set I assume you have no data?鉴于您正在启动一个副本集,我假设您没有数据? If so, startup should be relatively quickly.如果是这样,启动应该相对较快。 Also if you are attempting to make a single node replica set you might want to consider...此外,如果您尝试制作单节点副本集,您可能需要考虑......

rs.initiate (
    {
        _id: "somereplicasetname",
        version: 1,
        members:
        [
            { _id: 0, host: "somehostname:27017" }
        ]
    }
)

... so that you don't need to configure the initiated replicaset any further. ...这样您就不需要进一步配置启动的副本集。 The _id value (currently showing as somereplicasetname ) is expected to match the replica set name in the config file mongod.conf and the somehostname is expected to resolve to the current host. _id 值(当前显示为somereplicasetname )应与配置文件mongod.conf中的副本集名称匹配,而somehostname应解析为当前主机。

By the way, I assume you recognize you only need to initialize a replica set once, not every time you start the mongod process..顺便说一句,我假设您认识到您只需要初始化一个副本集一次,而不是每次启动 mongod 进程时..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM