Вопрос

I am running Fedora 20 and installed MongoDB per the Red Hat installation guide on the official documentation. I was able to run the mongod daemon as a service without error the very first time but when I shut down my machine and came back, the service refused to start due to some failure.

In my log, listed after the successful run, I see this:

***** SERVER RESTARTED *****
ERROR: Cannot write pid file to /var/run/mongodb/mongod.pid: No such file or directory

If I try starting mongod or running mongod --repair manually, I get this message in a start up failure:

ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.

This is odd considering that in my config file in /etc/mongod.conf, the settings for the database path are as follows:

dbpath=/var/lib/mongo

Finally, if I run this command:

mongod --dbpath /var/lib/mongo

The daemon starts up just fine. However, I am unable to replicate that error free behavior for starting a service.

Can anyone tell me what exactly is wrong and how I can begin running mongod as a service?

EDIT

I get this message if I run mongod --config /etc/mongod.conf:

about to fork child process, waiting until server is ready for connections. forked process: 2702 ERROR: child process failed, exited with error number 1

The /var/run/mongodb directory did not exist, so I created and assigned it to the mongod user. That did not make much of a difference, unfortunately.

My /var/log/mongodb/mongod.log shows this message:

[initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /var/lib/mongo/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating

Это было полезно?

Решение

What worked for me on Fedora 20: we need to create the temp dir on every boot, and that's handled by systemd-tmpfiles. So, create a file /lib/tmpfiles.d/mongodb.conf and put one line in it:

d /var/run/mongodb 0755 mongod mongod

That seems to handle it on restarts; if you don't want to restart right away, you can execute that with:

sudo systemd-tmpfiles --create mongodb.conf

(See the man pages for systemd-tmpfiles)

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

I have the same problem, I solved it temporarily, disabling SELinux, rebooted the machine, eliminated mongod.lock:

#rm /var/lib/mongo/mongod.lock

By creating the file /var/run/mongodb/mongo.pid (as mentioned in the configuration file /etc/mongod.conf):

#mkdir /var/run/mongodb
#touch /var/run/mongodb/mongod.pid

and giving 777 permissions:

#chmod 777 /var/run/mongodb/mongod.pid 

and starting mongo:

#service mongod start

But the problem persists after restarting the machine. The folder and file disappear.

I've spent a while looking into this, and it appears as if the pid folder and file permissions don't work with the default daemon.

The simplest solution I've come across is disable the pid file by just putting a # in front of the line in the config file.

vi /etc/mongod.conf

find the line that says pidfilepath=/var/run/mongodb/mongod.pid and change it accordingly.

# pidfilepath=/var/run/mongodb/mongod.pid

For information on what commenting it out does check here. http://docs.mongodb.org/manual/reference/configuration-options/#processManagement.pidFilePath

If you’re starting mongod as a service using:

sudo service mongod start

Make sure the directories defined for logpath, dbpath, and pidfilepath in your mongod.conf exist and are owned by mongod:mongod.

This worked for me in Ubuntu:

sudo kill $(sudo lsof -t -i:27017) 
sudo rm -rf /tmp/mongodb-27017.sock
sudo rm -f /var/lib/mongo/mongod.lock
sudo rm -f /var/run/mongodb/mongod.pid
sudo mkdir -p  /var/run/mongodb/
sudo touch /var/run/mongodb/mongod.pid
sudo chown -R  mongodb:mongodb /var/run/mongodb/
sudo chown mongodb:mongodb /var/run/mongodb/mongod.pid
sudo service mongod start

I was having the same problem running mongodb 3.0.4 on OpenSuse 13.2, and I found that the mongod directory under /var/run was missing. If I created the directory manually it would disappear after a reboot.

I solved it by adding the following lines to my /etc/init.d/mongod startup script:

mkdir -p /var/run/mongod  
chown $MONGO_USER:$MONGO_GROUP /var/run/mongod

i met the same issue,when i modify my mongod.conf as follow and problem resolved~

port=27017
dbpath=/usr/local/mongodb/data/db/
logpath=/usr/local/mongodb/logs
fork = true

tips: logpath is the logfile not a folder.

I just experience a similar problem on ubuntu. Encountered nearly every ERROR tips, like

child process failed, exited with error number 1

orchild process failed, exited with error number 100

or [signalProcessingThread] got signal 2 (Interrupt: 2), will terminate after current cmd ends

For many times I remove the Mongodb and try to install again, but the problem remains....

Finally I came to this way: Backup your data first, then remove Mongodb with

#sudo apk-get autoremove mongodb-org

Find out all the files related with mongodb:

/#find -name mongo*

Delete them all with "rm" or "rmdir", including the packages in the /var/cache/... and everthing.

Then repeat the installation as the first time you did :

#echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
#sudo apt-get update
#sudo apt-get install -y mongodb-org

It will run again.

Comment below the line from your "mongo.conf" file.

pidfilepath=/var/run/mongodb/mongod.pid

Following commands solved for cent os

ERROR:

 service mongod status
 Error starting mongod. /var/run/mongodb/mongod.pid exists

FIXED BY:

   rm /var/lib/mongo/mongod.lock
   chown -R mongod:mongod /var/log/mongodb/
   chown -R mongod:mongod /var/run/mongodb/
   chown -R mongod:mongod /var/lib/mongo/
   chmod 777 /var/run/mongodb/mongod.pid

   mongod --dbpath /var/lib/mongo

We need to create the temp dir location of pidfile /var/run/mongodb that's handled by systemd-tmpfiles. So, create a file /lib/tmpfiles.d/mongodb.conf as root:

lnx#> sudo su
lnx#> cd /lib/tmpfiles.d
lnx#> echo “d /var/run/mongodb 0755 mongod mongod” > mongodb.conf

Then reboot or run this command to activate that temp directory:

lnx#>sudo systemd-tmpfiles --create mongodb.conf

Start mongod service:

lnx#> sudo systemctl start mongod.service

Bibliography: Fedora And Mongodb · l33tsource

sudo mkdir /var/lib/mongodb
sudo mkdir /var/log/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown -R mongodb:mongodb /var/log/mongodb
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top