macports mongod fails to start - mongodb

I have installed mongodb using macports. I can run mongod from the terminal with
sudo mongod --dbpath /opt/local/var/db/mongodb
When I try to run it with:
sudo port load mongodb
mongod fails to start. The log file shows repeated attempts to start, each of them including the message
info preallocateIsFaster couldn't run due to: couldn't open file /opt/local/var/db/mongodb/journal/tempLatencyTest for writing errno:13 Permission denied; returning false
There is no such file, but the directory exists. It is owned by root with group _mongo. Changing its ownership to _mongo resulted in other problems. I also tried
mongod --repair
and although that had fixed a problem with the lock file it isn't fixing this one. Help appreciated.

Related

MongoDB can't start - DBPathInUse: Unable to create/open the lock file

So guys, I've been trying to execute MongoDB on my MacBook Pro (OSX 10.15.4) by running
sudo mongod
Then
mongo
but when I run mongo command it returns the following error:
exception in initAndListen: DBPathInUse: Unable to create/open the lock file:
/data/DB/mongod.lock (Read-only file system). Ensure the user executing mongod is the owner
of the lock file and has the appropriate permissions. Also make sure that another mongod
instance is not already running on the /data/db directory, terminating
I already added the Mongo folder to my /etc/paths and created the /data and /db folders using the command mkdir.
There's no lockfile and all the permissions are granted. I also tried to kill the mongo process but I still get the same error.
Any tips?
Thank you.
It seems like you are not owner of mongod.
execute
chown $USER mongo
On recent versions of OSX you are not allowed to create directories in the root even with sudo. I recommend using the --dbpath commandline parameter to locate your database directory in a directory you are entitled to write to. e.g.
mongod --dbpath ${HOME}/data

How to resolve MongoDB failing to instantiate [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I followed the MongoDb Docs to setup my first MongoDb,
When I start MongoDB using the command
C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe
I get the following error
exception in initAndListen: 29 Data directory C:\data\db\ not found., terminating
shutdown: going to close listening sockets...
shutdown: going to flush diaglog...
now exiting
shutting down with code:100
MongoDB needs a folder to store the database. Create a C:\data\db\ directory:
mkdir C:\data\db
and then start MongoDB:
C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe
Sometimes C:\data\db folder already exists due to previous installation. So if for this reason mongod.exe does not work, you may delete all the contents from C:\data\db folder and execute mongod.exeagain.
For macOS users to fix this issue:
You need to go through the following steps:
Create the “db” directory. This is where the Mongo data files will live. You can create the directory in the default location by running:
sudo mkdir -p /data/db
Make sure that the /data/db directory has the right permissions by running:
sudo chown -R `id -un` /data/db
You're all set now and you can run sudo mongod to start the Mongo server.
It's not working if you run only mongod
Source.
Same issue on my Mac (using Brew) solved using:
sudo mongod
For macOS users take care of below issue:
if you installing MongoDB Community on macOS using .tgz Tarball
((Starting with macOS 10.15 Catalina, Apple restricts access to the MongoDB default data directory of /data/db. On macOS 10.15 Catalina, you must use a different data directory, such as /usr/local/var/mongodb.))
you can solve it as the following:
(MacOS Catalina onwards)
Apple created a new Volume in Catalina for security purposes. If you’re on Catalina, you need to create the /data/db folder in System/Volumes/Data.
Use this command:
sudo mkdir -p /System/Volumes/Data/data/db
Then, use this command to give permissions:
sudo chown -R `id -un` /System/Volumes/Data/data/db
this will replace normal
sudo mkdir -p /data/db
Make sure that the /data/db directory has the right permissions by running:
sudo chown -R `id -un` /data/db
once you finish and start mongoDB you can use the following in terminal:
sudo mongod --dbpath /System/Volumes/Data/data/db
To change default db folder C:\data\db in windows, the command is:
--dbpath
For example:
\mongod --dbpath C:\myfolder
Mac Users
Instead of running MongoDB with:
sudo mongod
You can use mongod instead if you:
Locate the data folder of mongodb (usually ~/data)
Add permission to read + write with sudo chmod -R ugo+rw data
If you need to use sudo when running mongodb (sudo mongod), that means you don't have read and write permission on the mongodb data folder
Please take following steps:
As other friends mentioned, you should make a directory first for your database data to be stored. This folder could be something like:
C:\mongo-data
From command line navigate to where you have installed mongodb and where mongod.exe resides. In my case the full path is:
C:\Program Files\MongoDB\Server\3.4\bin
From here run mongod.exe and pass it the path to the folder you created in step one using the flag --dbpath as follows:
mongod.exe --dbpath "C:\mongo-data"
Please Note: If you are on windows it is necessary to use double-quotes ("") in the above to run properly.
In this way you will get something like the following:
2017-06-14T12:45:59.892+0430 I NETWORK [thread1] waiting for connections on port 27017
If you use single quotes (' ') on windows, you will get:
2017-06-14T01:13:45.965-0700 I CONTROL [initandlisten] shutting down with code:100
Hope it helps to resolve the issue.
To run Mongo DB demon with mongod command, you should have a database directory, probably you need to run:
mkdir C:\data\db
Also, MongoDB need to have a write permissions for that directory or it should be run with superuser permissions, like sudo mongod.
I kept getting the following error when I tried to start mongodb (on mac os).
"shutting down with code:100"
I was using the following command:
./mongod --dbpath=~/mongo-data
The fix for me was that I didn't need the "=" sign and this was causing the error. So I did
./mongod --dbpath ~/mongo-data
Just wanted to throw this out there because the error in no way specifies that this is the problem. I almost removed the contents of the ~/mongo-data directory to see if that helped. Glad I remembered that cli args sometimes do not use the "=" sign.
first you have to create data directory where MongoDB stores data. MongoDB’s default data directory path is the absolute path \data\db on the drive from which you start MongoDB.
if you have install in C:/ drive then you have to create data\db directory. for doing this
run command in cmd
C:\>mkdir data\db
To start MongoDB, run mongod.exe.
"C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe" --dbpath="c:\data\db"
The --dbpath option points to your database directory.
Connect to MongoDB.
"C:\Program Files\MongoDB\Server\4.2\bin\mongo.exe"
to check all work good :
show dbs
1.If it shows error (shutting down
with code 100) that means it is not finding the desired
location of file.
1.a If its before macOS Catalina then create directory with
sudo mkdir -p /data/db and give permissions to use it
sudo chown -R id -un /data/db.
1.b if it macOS Catalina onwards then make
sudo mkdir -p /System/Volumes/data/db and give it
permissions
sudo chown -R id -un /System/Volumes/data/db.
2.Starting mongo db brew services run mongodb-community
3.Type mongod or mongod --dbpath /System/Volumes/Data/data/db
4.And if the mongod show error (shutting down with code 48) that
means the port is being already use so you can do two things
4.a Either you change the port of mongod by specifying port
number
mongod --dbpath /System/Volumes/Data/data/db —port 27018.
4.b Or You can kill the process at that port by finding
the process by
sudo lsof -i :27017
and then kill by command
kill -9
5.Repeat the step 2 and 3.
In MacOS:-
If you forgot to give the path of the previously created database while running the mongo server, the above error will appear.
sudo ./mongod --dbpath ../../mongo-data/
Reference
Note :- ./mongod && ../../mongo-data is relative path.
So you can avoid it by configuration in environment variable
Reference
For windows i've got same issue.
The fix was - i need to run command line as administrator.
if you already have the directory, check the dir permissions or try to restart mongo with sudo.
sudo brew services start mongodb
In my case, I got a similar error and it was happening because I had run mongod with the root user and that had created a log file only accessible by the root. I could fix this by changing the ownership from root to the user you normally run mongod from. The log file was in /var/lib/mongodb/journal/
I you are using Virtualbox check your VM.
docker-machine ssh
df -h
Look at dev/sda1 if you do not have any free space this may be due to a large number of images, or containers. you can remove them using "docker rm" and "docker rmi"
This exit code will also be given if you are changing MongoDB versions and the data directory is incompatible, such as with a downgrade. Move the old directory elsewhere, and create a new directory (as per the instructions given in other answers).
Aravind.
It happened with me too because I stopped the MongoDB by the Task Manager.
Creating the C:\data\db folder and starting the MongoDB at C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe worked for me, as cespon suggested, but the MongoDB didn't show any of my Databases previously created.
Then, removing the C:\data\db folder and repairing the installation with the MongoDB installer, I recovered my data and started normally the MongoDB.
(I'm very new with MongoDB, but it helped me solve this problem and recover may previews data).
typed mongod and getting error
Errors:
exception in initAndListen: NonExistentPath: Data directory /data/db not found.,
terminating
shuts down with Code 100
Then try with (create data and db folder with all permission)
mongod --dbpath=/data
use new tab and type mongo.
>use dbs
If still you are facing prob
then you can check for mac catalina: (https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x-tarball/)
for windows: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows-unattended/

MongoDB: ERROR: child process failed, exited with error number 14

I run MongoDB on Mac:
Shave:mongodb_simple Logan$ ./bin/mongod -f conf/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 5110
ERROR: child process failed, exited with error number 14
Is that because I shutdown it in wrong way?
You started and probably shutdown mongo in the wrong way.
1. TO START MONGODB
To start mongo in the background type: mongod --dbpath /data/db --fork --logpath /dev/null.
/data/db is the location of the db. If you haven't created one yet => type: mkdir /data/db
--fork means you want to start mongo in the background - deamon.
--logpath /dev/null means you don't want to log - you can change that by replacing /dev/null to a path like /var/log/mongo.log
2. TO SHUTDOWN MONGODB
Connect to your mongo by typing: mongo and then use admin and db.shutdownServer(). Like explain in mongoDB
If this technique doesn't work for some reason you can always kill the process.
Find the mongodb process PID by typing: lsof -i:27017 assuming your mongodb is running on port 27017
Type kill <PID>, replace <PID> by the value you found the previous command.
Check the ownership of the file /tmp/mongodb-27017.sock
It should be mongod. I got same error since it was root:root
For me it was ulimit issue, mongo could not open too many files.
Used ulimit -n 10000.
However as a generic pointer look into mongo logs file, they will tell where to look further. Generally the logs file are in /var/log/mongo.log but look into your mongo config file.
It's because you haven't configured your mongod instance correctly in the config file that you passed to the -f option.
Revisit your config file and make sure eveything is configured correctly.
By changing owner to mongodb for all files under /var/lib/mongodb/ it started working for me:
chown mongodb:mongodb -R /var/lib/mongodb/
This worked for me:
run in terminal
sudo rm -rf mongod.lock
export LC_ALL=C
then
sudo mongod --fork --config /xxxx/xx/mongod.conf --logpath /xxx/log/mongodb/mongodb.log
with me I remove file: /tmp/mongodb-27017.sock
then restart mongod
Just run this and start mongod
rm -f /tmp/mongodb-27017.sock
systemctl start mongod
Check if the mongod is running with pgrep mongod or ps -aef | grep mongod or systemctl status mongod
Stop and restart it to check if the issue gone
if you start mongod with mongod -f /etc/mongod.conf kill it with pkill -9 mongod then start it with mongod -f /etc/mongod.conf
fi you run it a service, use systemctl restart mongod to restart it.
If restart not works, figure out the issue by the /var/log/message and /var/log/mongodb/mongod.log file.
use tail -f /var/log/message and tail -f /var/log/mongodb/mongod.log to check the output when your action.
for example:
1.
Failed to unlink socket file /tmp/mongodb-27017.sock Operation not permitted
delete the sock file with `rm`
2.
WiredTiger error (13) [1596090168:830936][25997:0x7fe22f208b80], wiredtiger_open: __posix_open_file, 672: /data/mongo/WiredTiger.turtle: handle-open: open: Permission denied Raw: [1596090168:830936][25997:0x7fe22f208b80], wiredtiger_open: __posix_open_file, 672: /data/mongo/WiredTiger.turtle: handle-open: open: Permission denied
Failed to start up WiredTiger under any compatibility version
Reason: 13: Permission denied
check the file permission or owner with `ls` then change to the wright permission with `chmod` or right owner with `chown`
I had this same issue, but mine was the system clock being off so my SSL cert was technically invalid. Changing to the current date and time worked date --set "<DD M Y H:M>" Only found this by looking at the mongodb log
I encountered this issue on a GCP managed Compute Engine instance.
As this is the top answer on a Google search for the issue, I'll include what worked for me, and is a documented bug as per MongoDB (jira-link)
On linux systems, if the user running mongod does not have a locale set or the locale is misconfigured, mongod fails to start printing a stack trace.
The issue can be resolved by combining a few steps:
Install the required language packs (ref):
sudo apt-get install language-pack-XX
Run update locale (ref):
sudo update-locale
Restart your session, and check the same mongo command again
IFF the above doesn't work (it didn't for me), just manually add the following to the file at /etc/default/locale (ref):
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
Just to admire the absence of those persistent warnings about LC_ALL not being set, run the following:
sudo dpkg-reconfigure locales
That's all, your MongoDB instance should be good to go now!
In my mongodb setup, in order to retain a specific version of mongoDB inline to existing servers and also to avoid having binary files placed under root disk, i changed the path of all mongo binaries in a different directory. i had to use rpm option instead of yum option (as yum installs only the latest version despite of mentioning the specific version).
rpm -ivh --prefix=/apps/mongodb /apps/mongo_rpm_packages/mongodb-org-*.rpm
Note: The default path where the binaries will be placed is /var/lib/mongo.
This approach does not either allow required permission for mongod user or its not provisioned properly and hence, i changed user and group in mongod.service file to root user and managed to successful start the process using:
service start mongod
Use --shutdown
mongod --shutdown
Then
service mongod restart
It work!
https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/#use-shutdown

'Failed to unlink socket file" error in MongoDB 3.0

I am new to MongoDB. I am trying to install MongoDb 3.0 on Ubuntu 13.0 LTS, which is a VM on Windows 7 Host. I have installed MongoDB successfully (packages etc.), but when I execute the command sudo service mongod start, I get the following error in the "/var/log/mongodb/mongod.log" log file. Can anyone help me understanding this error. There is nothing on internet related to this.
2015-04-23T00:12:00.876-0400 I CONTROL ***** SERVER RESTARTED *****
2015-04-23T00:12:00.931-0400 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2015-04-23T00:12:00.931-0400 I - [initandlisten] Fatal Assertion 28578
2015-04-23T00:12:00.931-0400 I - [initandlisten]
I have fixed this issue myself, by deleting the mongodb-27017.sock file . I ran the service after deleting this file, which worked fine. However, I am still not sure the root cause of the issue. The output of the command ls - lat /tmp/mongodb-27017.sock is now
srwx------ 1 mongodb nogroup 0 Apr 23 06:24 /tmp/mongodb-27017.sock
Alternative to the answer provided by KurioZ7, you can simply set the permissions of the .sock file to the current user:
sudo chown `whoami` /tmp/mongodb-27017.sock
This does the trick for me if I want to run mongod without sudo. If I delete the file like in KurioZ7s answer, I will simply get the same error the next time I restart my machine.
This issue occurs when you use the command
mongod
Before using the command
sudo service mongod start
To fix the issue, either:
Set appropriate permissions on the file:
/tmp/mongodb-27017.sock
OR
Remove the file
/tmp/mongodb-27017.sock
Run
sudo service mongod start && mongod
The most likely cause for this was that the mongod process was at some point started by the root user. The socket file (/tmp/mongodb-27017.sock) was therefore owned by the root user. The mongod process usually runs under its own dedicated user, and that user did not have the permissions to delete that file.
The solution, as you already found out, was to delete it. Then mongodb was able to recreate it with the correct permissions. This should persist after reboot, as long as mongodb is started using the init scripts, or under the correct user account.
$ sudo mongod
it solve problem for me
Change the ownership mongodb-27017.sock file in /tmp directory and start the mongod again.
cd /tmp
sudo chown mongodb:mongodb mongodb-27017.sock
sudo systemctl start mongod
For UNIX-based operating systems, as an alternative to the answer provided by Bastronaut, you could also specify the .sock file to be saved to a folder over which mongod has full user rights (corresponding to the way you are running mongod), that way mongod will also be able to remove the .sock file upon shutdown. The default folder to which the .sock file is saved is '/tmp'. To specify another folder, use a custom mongodb configuration file, for instance 'mongodb.conf', and add the following to it:
net:
unixDomainSocket:
pathPrefix: "anotherFolder"
After which you can run mongod with the command:
$ mongod --config /path/to/mongodb.conf
You can read the documentation on: https://docs.mongodb.org/manual/reference/configuration-options/#net.unixDomainSocket.pathPrefix
Manually restarting mongod service after restart fixed the problem.
Long-term solution was to add static host name, instead of ip address 'net' part of mongod.conf file (I suspect the problem is that ip address is not yet given to server, when mongod servis starts).
If you are having this problem using docker, refer to this question:
MongoDB docker container “Failed to unlink socket file”

getting an error when firing up mongodb in terminal [duplicate]

I'm getting the following error when I try to run "mongod" in the terminal. I've tried uninstalling, reinstalling, and restarting the machine. Any suggestions on how to get it working would be amazing.
ERROR:
dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
Side note:
Node also stopped working on my machine around the same time that I got this error.
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
Any help would be much appreciated!
This should work to ensure that the directory is set up in the right place so that Mongo can find it:
sudo mkdir -p /data/db/
sudo chown `id -u` /data/db
You need to create the directory on root /data/db or set any other path with the following command :
mongod --dbpath /srv/mongodb/
See the example link
I solved the problem with :
sudo mongod --dbpath=/var/lib/mongodb and then mongo to access the mongodb Shell.
Change the user of the new data directory:
chown mongodb [rute_directory]
And try another time to start the mongo service
service mongod start
I solve the same problem with this.
Daemons (usually ending with d) are normally started as services. Starting the service (daemon) will allow mongodb to work as designed (without permission changes if integrates well with your distro). I start it using the service named mongodb instead of starting mongod directly--on distro with systemd enable on startup then run like:
sudo systemctl enable mongodb
sudo systemctl start mongodb
or, on distro with upstart (if you have /etc/init) or init (if you have /etc/init.d) ( https://www.tecmint.com/systemd-replaces-init-in-linux/ ) instead run:
sudo service mongodb enable
sudo service mongodb start
If you have a distro with rc ("run commands") such as Gentoo (settings in /etc/init.d) (https://forums.gentoo.org/viewtopic-t-854138-start-0.html) run:
rc-update add mongodb default
/etc/init.d/mongodb start
In a distro/version of FreeBSD which still has rc (check whether your version switched to systemd, otherwise see below):
add the following line to /etc/rc.conf:
mongod_enable="YES"
then:
sudo service mongod start
After starting the service, an unpriveleged user can use mongo, and each user will have separate data.
I also got the error that "The file /data/db doesn't exist" when I tried to save my file using the "mkdir -p /data/db" command(using both with and without sudo command). But later on one site, a person named Emil answered that the path "/data/db" no longer works on Mac, so use "~/data/db" instead
i.e., use the command
mkdir -p ~/data/db
instead of previous command.
Moreover, use
mongod --dbpath ~/data/db
to run mongod
It worked for me, hope it work for others too facing the same problem