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.
Related
I am on a Windows 10 laptop and installed mongodb 4.4 recently. But when I run mongod, I thought it uses the mongodb.cfg file in the bin directory by default, but changing that made no difference and I ended up launching the server with arguments which is displayed when I run mongod --help.Then I realized I can pass a config file with a -f or --config.
But even after passing the default config file, it gave me this error.
Unrecognized option: storage.dbpath
But I had followed the proper YAML syntax which was mentioned here.
I tried removing space, adding and all other ways to get it working, but it kept giving me the same error. I tried going by what this post said, but I couldn't get it to work.
Then I tried the same on another device with Linux mint.
But there, the mongodb.cfg file, in /etc/ folder was not following YAML syntax(in windows, the default mongodb.cfg in bin folder followed YAML syntax).Rather a format similar to what I have seen in a .bashrc file.
So this surprised me and I tried out the same format in windows 10 machine. Something like this --
dbpath=D:\codes\dbs\dbmongo\data
directoryperdb=true
And this time, it worked when I launched mongod using -f flag to mention the cfg file. It worked fine. It took hours for me to find this because I was trying to get it to work with the cfg file with YAML syntax.
This is the default mongod.cfg file in my windows 10 device, which didn't work.
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: C:\Program Files\MongoDB\Server\4.4\data
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: C:\Program Files\MongoDB\Server\4.4\log\mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
Here's the format in which it worked
dbpath=D:\codes\dbs\dbmongo\data
directoryperdb=true
logappend=true
logpath=D:\codes\dbs\dbmongo\log\mongod.txt
# network interfaces
#port=27017
bind_ip=127.0.0.1
Here you can see that the format which worked uses the same parameters as given in the mongod --help and not the YAML syntax mentioned in the official website.
I was wondering if anyone else is facing this issue and how/why YAML cfg file is not working as it should.
Your example is not valid YAML syntax and the parameters might be wrong. I think Parameter names are case-sensitive.
It must be like this:
storage:
dbPath: D:\codes\dbs\dbmongo\data
directoryPerDB: true
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 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
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.
How do I edit the mongodb.conf file?
I want to change the bind_ip from 127.0.0.1 to 0.0.0.0.
I have tried sudo mongod --bind_ip 0.0.0.0
I have tried manually editing the file (in a text editor), but it won't let me save.
I have tried changing the permissions of the file, yet I still can not save.
I didn't create a mongodb.conf file either, so I'm not sure why it was automatically set up as 127.0.0.1
I'm using Ubuntu.
I've tried searching around but I haven't had any luck.
All suggestions will be much appreciated.
Both the /etc/mongod.conf and /var/log/mongodb/mongob.log files are write restricted to super users. Your standard login account is not allowed to directly modify them.
To edit the mongod.conf file , open a terminal and run the following command (sudo will ask you for your password):
gksudo gedit /etc/mongod.conf
Edit the file to add 0.0.0.0 (or just comment the line out ), save the mongodb.conf file.
In addition mongod is a service on ubuntu so you'll need to run following command in the terminal to restart it to read the new config:
sudo service mongod restart
You can read about sudo here
If you're on windows and are wondering how to edit the config file.
Open the file
Edit the cfg file however you want.
Save as and save it to another folder somewhere else
Copy/cut and past the file back into the bin folder and accept admin permission
Go to windows services and stop->start/restart the MongoDB server service.
Done
trying using your specified mongodb.conf to mongo deamon
use following command to start the mongod daemon
mongod -f <file-locattion>/mongodb.conf
and in your mongodb.conf file add following
bind_ip=<your-pref-ip>
<rest of setting -such as data-folder etc>
using aws ubuntu instance i ssh to my instance using putty navigate to the file directory and
i used the command
sudo pico mongodb.conf
the file opened and i edited my file then saved it
by following onscreen commands