waiting until server is ready for connections. forked process: 7754 child process started successfully, parent exiting - mongodb

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.

Related

MongoDB isn't saving the dbpath that I assign to it. How can I save the dbpath?

Im setting my dbpath like so:
mongod --dbpath /Users/dylan/development/mongodb/data/db
it then connects to the db and runs fine. But as soon as I exit and try to start mongod again it comes up with this error:
Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option
for some reason it isn't saving the --dbpath
It is a best practice to store all startup parameters in the mongod.conf yaml file
and start the mongod process every time with mongo --config mongodb.conf file or as a service.
example content:
storage:
dbPath: /Users/dylan/development/mongodb/data/db
If you dont specify the dbPath location , the mongod process start with default dbPath location( /data/db ) or if started as service the dbPath found in default config file located in linux at /etc/mongod.conf

Not able to send logs to /var/mongodb/logs/mongod.log file and not able to mongod is forked and run as a daemon

I am doing the course M103 from MongoDB University. They're having a lab section that we need to solve. I am stuck with Chapter 1: The Mongod
Lab: Logging to a Different Facility
Update your configuration file such that:
1)mongod sends logs to /var/mongodb/logs/mongod.log
2)mongod is forked and run as a daemon (this will not work without specifying logpath)
anyone can please explain to me the detailed procedure. I am getting an error while solving it.
mongod --logpath /var/mongodb/logs/mongod.log
mongod --config mongod.conf
Login with the user in order to validate your work
You can simply run in the shell the following line:
mongod --fork --logpath /var/mongodb/logs/mongod.log --config mongod.conf
--logpath /var/mongodb/logs/mongod.log to set the log file
--fork to run a mongod process as a daemon (i.e. fork)
Apart from the previously given answers, you can simply add this to the conf file:
...
systemLog:
path: "/var/mongodb/logs/mongod.log"
destination: "file"
processManagement:
fork: true"
And then execute
mongod --f mongod.conf

mongodb on Ubuntu 18.04 Bionic systemctl handling of mongod.service / mongodb.service

I had some issues installing mongod.service on a digital ocean droplet with systemctl. It is set up now except that it complains there is something else taking its port, although nothing actually is. The culprit, I suppose is the following: there is a failed service for mongodb (rather than mongod.service) whose error is "file not found". Do I need to set up or remove the missing mongodb.service? I see there is a /lib/systemd/system/mongod.service but there's not a mongodb.service in that directory.
Here is some of the config in /etc/mongod.conf
storage:
dbPath: /data/db
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
I also set sudo chown -R mongodb:mongodb /data/db which fixed errors then but now I'm getting /data/db/WiredTiger.turtle: handle-open: open: Permission denied
...Yay mongod is running after sudo chown -R mongodb:mongodb /data/db/WiredTiger.turtle
I suppose that file was generated and missed getting the permissions.
I just read in the documentation: The Linux package init scripts do not expect storage.dbPath to change from the defaults. If you use the Linux packages and change storage.dbPath, you will have to use your own init scripts and disable the built-in scripts. I believe I had originally changed the dbPath...
check if mongodb is running
sudo service mongodb status
if it says inactive, activate using the below command
sudo service mongodb start
I am adding the detail steps to check the MongoDB running on the localhost or not and how to start it.
To check MongoDB running or not type below command on Linux terminal
ps -Aef | grep mongod
After this command, you will properly see the details of mongod running instance with details of process Id and config file loaded by MongoDB.
If not running then check the status as below
sudo service mongod status
Provide the permission to /data/db or change the location and provide the monogdb ownership of that folder as sudo chown -R mongodb:mongodb /data/db Once done then do restart the MongoDB as below
sudo service mongod start
Now check again the status, its working or not. Still facing issue then visit the official MongoDB documentation with proper install guideline Install MongoDB Community Edition on Ubuntu

Mongodb dbpath argument not changing config file [duplicate]

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.

How to specify a config file for Mongod process

When running mongod I receive the non-critical error
[HostnameCanonicalizationWorker] Failed to obtain address information for hostname flimflamjims-MacBook-Pro.local: nodename nor servname provided, or not known
This problem is well documented on stack overflow and solutions typically suggest editing /etc/hosts to specify an address of 127.0.0.1. This does indeed resolve the issue however as an alternative I would like to specify a config file.
As per Homebrew's instructions I have tried running mongod --config /usr/local/etc/mongod.conf. After running the command the process hangs with no logs being printed to the terminal.
mongod.conf was created automatically by Homebrew and its contents are:
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /usr/local/var/mongodb
net:
bindIp: 127.0.0.1
When I remove mongod.conf from /usr/local/var/log/mongodb/ and again run mongod --config /usr/local/etc/mongod.conf I receive the error:
Error reading config file: No such file or directory
try 'mongod --help' for more information`
So it seems that mongod.conf is at least being accessed.
Any help would be much appreciated.
With your configuration the logs will go to the log file mentioned in the systemLog.path. If you remove only the systemLog.path from the config file, it will thrown error as it won't be able to find the path for log file. Because systemLog.destination says log to file, you must specify systemLog.path as well. In case, you want logs be sent to stdout then you need to remove systemLog.destination and systemLog.path both.