install mongoDB (child process failed, exited with

2019-01-22 03:12发布

问题:

I tried to install mongoDB on my macbook air.

I've downloaded zipped file from official website and extract that file and move to root directory. After that, under that directory, I've made /data/db and /log folder.

Here is my mongodb.config which describes the basic config for my DB.

dbpath = /mongodb/data/db
logpath = /mongodb/log/mongo.log
logappend = true
#bind ip = 127.0.0.1
port = 27017

fork = true
rest = true
verbose = true
#auth = true
#noauth = true

Additionally, I want to know what the # means in the config file.

I put this file to /mongodb/bin, /mongodb is the directory I extracted the files into.

I opened terminal and entered ./mongod --config mongodb.config and I got this back.

Juneyoung-ui-MacBook-Air:bin juneyoungoh$ ./mongod --config mongodb.config
about to fork child process, waiting until server is ready for connections.
forked process: 1775
all output going to: /mongodb/log/mongo.log
ERROR: child process failed, exited with error number 100

How can I handle this error and what this means?

回答1:

The data folders you created were very likely created with sudo, yes? They are owned by root and are not writable by your normal user. If you are the only user of your macbook, then change the ownership of the directories to you:

sudo chown juneyoungoh /data
sudo chown juneyoungoh /data/db
sudo chown juneyoungoh /data/log

If you plan on installing this on a public machine or somewhere legit, then read more about mongo security practices elsewhere. I'll just get you running on your macbook.



回答2:

I had a similar issue and it was not related to any 'sudo' problem. I was trying to recover from a kernel panic!

When I look at my data folder I found out a mongod.lock file was there. In my case this page helped a lot: http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/. As they explain,

if the mongod.lock is not a zero-byte file, then mongod will refuse to start.

I tested this solution in my environment and it works perfectly:

  1. Remove mongod.lock file.
  2. Repair the database: mongod --dbpath /your/db/path --repair
  3. Run mongod: mongod --dbpath /your/db/path


回答3:

There was the same problem on my machine. In the log file was:

Mon Jul 29 09:57:13.689 [initandlisten] ERROR: Insufficient free space for journal file
Mon Jul 29 09:57:13.689 [initandlisten] Please make at least 3379MB available in /var/mongoexp/rs2/journal or use --smallfiles

It was solved by using mongod --smallfiles. Or if you start mongod with --config option than in a configuration file disable write-ahead journaling by nojournal=true (remove the beginning #). Some more disk space would also solve the above problem.



回答4:

Similar issue with the same error - I was trying to run the repair script sudo -u mongodb mongod -f /etc/mongodb.conf --repair

Checked ps aux | grep mongo and see that the daemon was running. Stopped it and then the repair script run without an issue.

Hope that could be helpful for someone else.



回答5:

It's because you probably didn't shutdown mongodb properly and you are not starting mongodb the right way. According your mongodb.config, you have dbpath = /mongodb/data/db - so I assume you created the repository /mongodb/data/db? Let me clarify all the steps.

  1. TO START MONGODB

In your mongodb.config change the dbpath = /mongodb/data/db to dbpath = /data/db. On your terminal create the db repository by typing: mkdir /data/db. Now you have a repository - you can start your mongo.

To start mongo in the background type: mongod --dbpath /data/db --fork --logpath /dev/null.

  • /data/db is the location of the 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

    1. 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.



回答6:

I had the same error on linux (Centos) and this worked for me

  1. Remove mongod.lock from the dbpath

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

  2. Repair the mongod process

    $ mongod --repair

  3. Run mongod config

    $ mongod --config /etc/mongod.conf



回答7:

I had the same error. I ran it interactively to see the log.

2014-10-21T10:12:35.418-0400 [initandlisten] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017

Then I used lsof to find out which process was using my port.

$ lsof -i:27017
COMMAND  PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
mongod  2106 MYUSERID   10u  IPv4 0x635b71ec3b65b4a1      0t0  TCP *:27017 (LISTEN)

It was a mongod that I had forked previously and forgot to turn off (since I hadn't seen it running in my bash window). Simply killing it by running kill 2106, enabled my process to run without the error 100.



回答8:

Generally, this error comes when the mongod.conf file is not able to find a certain path for Database store or log store or maybe processid store or maybe it's not getting the file permission to access the config directories and files which has been declared in mongod.conf

to resolve this error we need to observe the log generated by the MongoDB it will clearly indicate whether which file or directory you MongoDB is not able to access

the above error may look like below screenshot