Вопрос

I have a production and staging environments on one machine. One rails app works the fulltime. One (actually the same) rails app is only for testing/implementing new features.

So I use a mongodb:

mongod --dbpath /path/to/my/production/rails/app/db

I would also like to run one mongod with:

mongod --dbpath /path/to/my/staging/rails/app/db

But I cannot imagine how to do that, because if I do just as described, I obviously get:

Mon Oct 14 16:12:59 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
Mon Oct 14 16:12:59 [initandlisten] ERROR:   addr already in use

So what is the best practice to work with two different mongodb instances on one machine to be able to work with both production and staging apps separately?

Update:

of course it is better to define different environments within the rails app (e.g. mongodb.yml) and use the same mongod process and port, but would be interesting if it is possible something like this (to compleetely separate environments):

port 27017 <--> --dbpath /path/to/my/production/rails/app/db
port 27018 <--> --dbpath /path/to/my/staging/rails/app/db
Это было полезно?

Решение

Yes.

mongod --dbpath /path/to/my/production/rails/app/db --port 12345
mongod --dbpath /path/to/my/staging/rails/app/db --port 12346

Check out this earlier answer for more information/pitfalls: multiple instances of Mongo DB on same server

Другие советы

Slightly modified version of my answer in the related question:

The aforementioned answer is 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 logpath and pidfilepath which in most cases is not what you want.

Please, consider creating dedicated mongod configuration files like mongod-PROD.conf and mongod-STAGE.conf. In these files you may want to provide dbpath, logpath folders, bind_ip, port and pidfilepath specific to each mongod instance and that will not affect each other.

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

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

You can find more details on mongodb docs page

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top