mongodb 同一服务器上的多个 Mongo DB 实例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15124610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 13:05:26  来源:igfitidea点击:

multiple instances of Mongo DB on same server

mongodb

提问by amateur

I am working with Mongo DB and I am a newbie to it. I am about to install it on a server specifically for Mongo.

我正在使用 Mongo DB,我是它的新手。我将把它安装在一个专门用于 Mongo 的服务器上。

I would like to create 2 instances of it - 1 to support a QA environment, the other to support a Staging Environment.

我想创建它的 2 个实例 - 1 个用于支持 QA 环境,另一个用于支持暂存环境。

I am more familiar with SQL Server where I can create multiple instances.

我更熟悉 SQL Server,我可以在其中创建多个实例。

Is it possible to do the same with Mongo DB and if so, how?

是否可以对 Mongo DB 做同样的事情,如果可以,如何做?

回答by kasur

The aforementioned answeris not a recommended way to run multiple instances (especially when the servers might be running at the same time) as it will lead to usage of the same config parameters like for example logpathand pidfilepathwhich in most cases is not what you want.

上述答案不是运行多个实例的推荐方法(尤其是当服务器可能同时运行时),因为它会导致使用相同的配置参数,例如logpathpidfilepath在大多数情况下这不是你想。

Please, consider creating dedicated mongod configuration files like mongod-QA.confand mongod-STAGE.conf. In these files you may want to provide dbpath, logpathfolders, bind_ip, portand pidfilepathspecific to each mongod instance and that will not affect each other.

请考虑创建专用的 mongod 配置文件,如mongod-QA.confmongod-STAGE.conf。在这些文件中,您可能希望提供特定于每个 mongod 实例的dbpathlogpath文件夹、bind_ipportpidfilepath并且不会相互影响。

After these steps you are good to trigger two instances as follows

完成这些步骤后,您可以按如下方式触发两个实例

mongod --config <path-to>/mongod-QA.conf
mongod --config <path-to>/mongod-STAGE.conf

You can find more details on mongodb docs page

您可以在 mongodb 文档页面上找到更多详细信息

回答by Ilake Chang

You just need to create another folder(ex: mongodb2) dbpath for the second instance, and run it in different port(ex: 27018)

您只需要为第二个实例创建另一个文件夹(例如:mongodb2)dbpath,并在不同的端口(例如:27018)中运行它

 mongod --dbpath /usr/local/var/mongodb2 --port 27018

回答by Developer Marius ?il?nas

Here is how I start 4 mongod'son the same pcto emulate production environmentin development environment.

这是我在同一台电脑上启动 4 个mongod以在开发环境中模拟生产环境的方法。

To start mongodyou should use separate config for each mongod. Take 4 configs and start mongodsusing them:

要启动mongod,您应该为每个 mongod使用单独的配置。获取 4 个配置并使用它们启动mongods

start C:\mongodb\bin\mongod.exe --config C:\net2\dev1-pc\configs\mongod-primary1.cfg 
start C:\mongodb\bin\mongod.exe --config C:\net2\dev1-pc\configs\mongod-secondary1.cfg --rest
start C:\mongodb\bin\mongod.exe --config C:\net2\dev1-pc\configs\mongod-secondary2.cfg
start C:\mongodb\bin\mongod.exe --config C:\net2\dev1-pc\configs\mongod-secondary3.cfg

Configs look like this:

配置如下所示:

mongod-primary1.cfg file contents

mongod-primary1.cfg 文件内容

systemLog:
    destination: file
    path: c:\net2\primary1-pc\data\log\mongod.log
storage:
    dbPath: c:\net2\primary1-pc\data\db
net:
    port: 27018
replication:
    replSetName: repl1

mongod-secondary1.cfg file contents

mongod-secondary1.cfg 文件内容

systemLog:
    destination: file
    path: c:\net2\secondary1-pc\data\log\mongod.log
storage:
    dbPath: c:\net2\secondary1-pc\data\db
net:
    port: 27019
replication:
    replSetName: repl1

mongod-secondary2.cfg file contents

mongod-secondary2.cfg 文件内容

systemLog:
    destination: file
    path: c:\net2\secondary2-pc\data\log\mongod.log
storage:
    dbPath: c:\net2\secondary2-pc\data\db
net:
    port: 27020
replication:
    replSetName: repl1

mongod-secondary3.cfg file contents

mongod-secondary3.cfg 文件内容

systemLog:
    destination: file
    path: c:\net2\secondary3-pc\data\log\mongod.log
storage:
    dbPath: c:\net2\secondary3-pc\data\db
net:
    port: 27021
replication:
    replSetName: repl1

回答by Asya Kamsky

It's possible - you would give each one its own port to listen on, and its own --dbpath directory to put its files in, but I wouldn't recommend this because they will both be competing for the same resources - RAM, i/o bandwidth, etc.

这是可能的 - 你会给每个人自己的端口来监听,以及自己的 --dbpath 目录来放置它的文件,但我不推荐这样做,因为它们都会竞争相同的资源 - RAM,i/ o 带宽等。

If you have multiple disks on this server you can place their data files on separate devices but you're still risking your QA instance reducing availability of the production instances, possibly at the worst possible time.

如果您在此服务器上有多个磁盘,您可以将它们的数据文件放在不同的设备上,但您仍然面临着 QA 实例降低生产实例可用性的风险,可能是在最糟糕的时间。

I would put QA instance on a random machine that's doing something unimportant before I would colocate it with my production instance.

在我将 QA 实例与我的生产实例并置之前,我会将 QA 实例放在一台正在做一些不重要的事情的随机机器上。