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.
I would like to create 2 instances of it - 1 to support a QA environment, the other to support a Staging Environment.
I am more familiar with SQL Server where I can create multiple instances.
Is it possible to do the same with Mongo DB and if so, how?
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-QA.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-QA.conf
mongod --config <path-to>/mongod-STAGE.conf
You can find more details on mongodb docs page
You just need to create another folder(ex: mongodb2) dbpath for the second instance, and run it in a different port(ex: 27018)
mongod --dbpath /usr/local/var/mongodb2 --port 27018
Here is how I start 4 mongod's on the same pc to emulate production environment in development environment.
To start mongod you should use separate config for each mongod. Take 4 configs and start mongods using them:
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
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
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
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
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
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.
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.
I would put QA instance on a random machine that's doing something unimportant before I would colocate it with my production instance.
Related
i tried installing mongodb, after following all the steps as per the website when i ran "mongod" in the terminal/Hyper
i got this error
error code
later i tired with this code
" mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork "
got another error enter image description here
i'm new to this ,
i'm learning course from udmey , plz help me to create and run mongo in my mac
link i used for installing mongo
You can start mongod processes in a variety of ways. In most distributions you can use either systemd or sysinit. These make use of a configuration file, usually located at /etc/mongod.conf. It looks like you downloaded a tarball and are running it manually without systemd or sysinit.
You can also run mongo in a command line mode, like you show with the following options...
mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork
... but you can also keep the configuration in a config file and refer to it instead...
mongod -f /etc/mongod.conf
An example of a config file having the same command line options you used would look like ...
systemLog:
destination: file
logAppend: true
path: /usr/local/var/log/mongodb/mongo.log
storage:
dbPath: /usr/local/var/mongodb
journal:
enabled: true
processManagement:
fork: true
pidFilePath: /usr/local/var/mongodb/mongod.pid
net:
port: 27017
bindIp: localhost
Assuming you saved the configuration file to /etc/mongod.conf you can call mongo this way...
mongod -f /etc/mongod.conf
A couple of points...
This config file will only accept connections from itself - localhost, because that is what we put in the config file. If you want it to be wide open replace localhost with 0.0.0.0. Secondly, it uses a PID file to track the process. It expects to be able to write the file /usr/local/var/mongodb/mongod.pid with whatever account you execute the program with. Also, it expects the data directory to exist and be writable by the user that executes the program. The log file directory is non-standard. Your original post referred to /usr/local/var/log/mongodb/mongo.log, but the default logging location for mongo is /var/log/mongodb/mongod.log.
I am trying to get MongoDB authentication working on my AWS Linux server. I have run authentication using MongoDB running on windows with no issues,
>mongod --auth
On my AWS server I am trying to run MongoDB using the service command,
$ sudo service mongod start
However, mogod does not start. I believe the problem is with my /etc/mongod.conf file. Here is the /etc/mongod.conf with authentication enabled,
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
security:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
The problem is with the security tag.
security:
authorization: enabled
If I include it, MongoDB will not start. If I take it out, MongoDB starts fine but has no security. What I am doing wrong?
Ok, my bad...The file is of type YAML. I originally entered,
security:
authorization: enabled
Because it's YAML, I needed a couple of spaces. The correct entry is,
security:
authorization: enabled
Works fine now.
By the way, If you are using MongoDB and have a public IP/port exposed I would highly recommend that you enable security. I got an email last week from AWS saying that if you are using MongoDB that has a port that is publicly available you should implement security. I am still in development so I ignored the AWS recommendation. Well, 3 days later, someone accessed my databases, copied them, deleted them, and left me a ransomware note in a new database. They wanted one bitcoin for the return of my existing databases. I did not pay the ransom. Fortunately, this was not a problem for me. All of the data was limited test data. To avoid potential malware bombs, I deleted the AWS instance, created a new instance and installed a fresh MongoDB release with authorization enabled.
This episode could have been a disaster with real customer data. If you are using MongoDB with public access make sure you enable authorization.
I've noticed an anomaly after performing a mongorestore from a 2.6.11 dump (from another system) to a 3.2.5 system. In a nutshell, the names of the collection files on the new system (in /var/lib/mongodb) are named differently and follow this format:
collection-55--6670716476518949126.wt
index-1--6670716476518949126.wt
Whereas on the old system, the collections were in /home/mongodb and followed this naming convention:
collection_name.0
collection_name.1
collection_name.ns
Strangely, everything seems to be "working" though, even though the ~150MB collection file sizes on the old system aren't represented in the new collection file sizes (which are ~150kb).
I was following the answer in:
How to migrate MongoDB 2.6 to 3.0 with WiredTiger
Which basically suggests:
Perform mongodump.
Stop mongod
Upgrade MongoDB version
Convert the old config file at /etc/mongod.conf to the new YAML format.
Restart mongod
Perform the mongorestore on the dump.
As I am doing a mongorestore to a fresh MongoDB 3.2.5 install, however, I already have a config file in the YAML format (see below).
So the only step it seems I need to do is the mongorestore - which I have done and resulted in the anomalies noted above.
My questions are:
01) Are there any other steps I should have performed?
02) Are these file naming 'anomalies' expected?
03) Why is there such a large discrepancy in collection file sizes?
I ask in order to avoid any problems that may arise later due to missing an important step.
/etc/mongod.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
#processManagement:
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
the file names are correct as mongoDb uses now wired tiger as default storage engine.
The size associated can be different as WT uses different approach when storing documents in file
see more here
I am trying to set up MongoDB on Windows, and the online docs seem far from accurate.
Under "Configure a Windows Service" part, step 1 mentions to create a config file. Then it mentions to fill in the file with a line in the format logpath="X:\path\mongo.log". However, following the link, the config file is said to be in YAML format, which renders the previous line unreadable in YAML.
I have created a basic mongodb.cfg(.cfg or .conf??) file:
systemLog:
destination: file
path: "P:\\Servers\\MongoDB\\logs\\mongodb.log"
quiet: true
logAppend: true
storage:
dbPath: "P:\\Servers\\MongoDB\\data"
journal:
enabled: true
net:
bindIp: 127.0.0.1
port: 27017
However when I start mongod --config P:\Servers\MongoDB\mongodb.cfg, the service just won't give any output at all, and just hangs.
If I remove the dbPath line, it will just close itself with no message at all.
I have also tried to leave the mongodb.cfg file just like this:
logpath="P:\Servers\MongoDB\logs\mongodb.log"
dbpath="P:\Servers\MongoDB\data"
But execution aborts complaining about any of the 2 paths, even tho they exist. Tried with single backslashes and with escaped backslashes (\\) with no success.
The only way the service works and listens for connections is to manually pass --dbpath only, and ignore any config file and logpath at all. Obviously this is not serious, as I need to keep track of the logs and also might need to change config parameters at some later point.
This is nuts... Am I missing something very basic or this docs are a real mess?
Here is my simple test MongoDB Config file for Windows. Note that I had to have 2 spaces before each property, e.g., path. When I had 3 spaces I got an error at startup.
I start the server with: mongod --config c:\tools\mongodb\db\mongod.cfg
systemLog:
destination: file
path: "C:\\tools\\mongodb\\db\\log\\mongo.log"
logAppend: true
storage:
dbPath: "C:\\tools\\mongodb\\db\\data"
security:
authorization: enabled
Here's an example of a mongodb.config file for Windows.
##store data here
dbpath=C:\mongodb\data\db
##all output go here
logpath=C:\mongodb\data\log\mongo.log
##log read and write operations
diaglog=3
For those who installed via *.msi installer and wondering where is .conf file located. Run 'services.msc' and check properties of mongodb service runnable file.
Bit late but I had the exact same issue today. If you use forward slashes for your paths within the config file it works fine.
systemLog:
destination: file
logAppend: true
path: "e:/mongo_data/3.6/mongo.log"
storage:
dbPath: "e:/mongo_data/3.6/db"
engine: "wiredTiger"
check if you have any file in data\db path. Please remove all those files and try to restart. I exactly used your config file and able to start the service successfully with bindip and port
You can find logs with reasons why it's not working in log file. In your case, read P:\Servers\MongoDB\logs\mongodb.log file.
I have a CentOS machine where I installed mongodb and I want it to always use storage.smallFiles setting, so I went to /etc and I created a new file /etc/mongodb.conf where I added the following text and I saved:
storage:
smallFiles:
enabled: true
then I typed:
$ mongod --config /etc/mongodb.conf
Unrecognized option: storage.smallFiles.enabled
try 'mongod --help' for more information
I followed documentation on http://docs.mongodb.org/manual/reference/configuration-options/#storage.smallFiles
The configuration for storage option smallFiles is different for different versions of MongoDB. Note that MMAPv1 storage engine is deprecated in MongoDG v4.0 and removed in MongoDB v4.2 - docs.
MongoDB 3.0–4.0 - docs:
storage:
mmapv1:
smallFiles: true
MongoDB 2.6 - docs:
storage:
smallFiles: true
MongoDB 2.4 - docs:
smallfiles = true
You can check that your setting is properly set by calling this command against admin database:
db.runCommand({getCmdLineOpts:1});
You can also specify it directly when starting mongod:
mongod --config /etc/mongodb.conf --smallFiles
If you're a developer, don't have time and is using a VM getting out of space... Just copy, paste and go!
sudo bash -c "echo \"smallfiles=true\" >> /etc/mongodb.conf"
sudo service mongodb restart
If you are using mongodb: 3.0.
You need to set the Option Hierarchy as storage.mmapv1.smallFiles : true
storage:
mmapv1:
smallFiles: true
Take care of the spaces in your yaml file.
Example:
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
mmapv1:
smallFiles: true
If you are getting this error with mongodb 4.2 then it is because some of the options are removed in Mongo DB 4.2
Removed Configuration File Setting Removed Command-line Option
storage.mmapv1.journal.commitIntervalMs
storage.mmapv1.journal.debugFlags mongod --journalOptions
storage.mmapv1.nsSize mongod --nssize
storage.mmapv1.preallocDataFiles mongod --noprealloc
storage.mmapv1.quota.enforced mongod --quota
storage.mmapv1.quota.maxFilesPerDB mongod --quotaFiles
storage.mmapv1.smallFiles mongod --smallfiles
storage.repairPath mongod --repairpath
replication.secondaryIndexPrefetch mongod --replIndexPrefetch
Please refer Mongodb 4.2 Release Notes