mongod stuck on fork with no error message - mongodb

I was unable to run mongod as a background process. There were no errors and the program got stuck after printing the following message:
about to fork child process, waiting until server is ready for connections.
Here is the content of the specified mongodb.conf:
# See http://www.mongodb.org/display/DOCS/File+Based+Configuration for format details
# Run mongod --help to see a list of options
bind_ip = 127.0.0.1
port = 27027
quiet = true
fork = true
logpath = /home/mljli/proj/log/mongod.log
dbpath = /home/mljli/proj/db
logRotate = reopen
logappend = true
noscripting = true
noauth = true
Port 27027 was not used according to the output of netstat. dbpath exists and logpath is not a directory. I also tried the following simple configuration and it didn't work either:
$ mongod --fork --logpath mongod.log
about to fork child process, waiting until server is ready for connections.
Using sudo does not help.
My MongoDB version:
db version v3.4.3
git version: f07437fb5a6cca07c10bafa78365456eb1d6d5e1
OpenSSL version: OpenSSL 1.1.0e 16 Feb 2017
allocator: tcmalloc
modules: none
build environment:
distarch: x86_64
target_arch: x86_64

Related

Mongo Shell from local is not getting connected to mongo server running in docker

I ran mongo server in docker and the logs came up just fine.
2019-04-12T10:39:51.334+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=8a03346e57d7
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] db version v3.2.22
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] git version: 105acca0d443f9a47c1a5bd608fd7133840a58dd
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] modules: none
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] build environment:
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] distmod: rhel70
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] distarch: x86_64
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] options: { net: { port: 27017 }, processManagement: { pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/data/db" } }
2019-04-12T10:39:51.339+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),verbose=(recovery_progress),
2019-04-12T10:39:51.389+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-04-12T10:39:51.389+0000 I CONTROL [initandlisten]
2019-04-12T10:39:51.406+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2019-04-12T10:39:51.406+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2019-04-12T10:39:51.406+0000 I NETWORK [initandlisten] waiting for connections on port 27017
But, while connecting the mongodb server from local shell, the connection is getting timedout.
~/mongodb/bin/mongo --host 172.17.0.2
MongoDB shell version v3.6.11
connecting to: mongodb://172.17.0.2:27017/?gssapiServiceName=mongodb
2019-04-12T16:04:45.750+0530 W NETWORK [thread1] Failed to connect to 172.17.0.2:27017 after 5000ms milliseconds, giving up.
2019-04-12T16:04:45.753+0530 E QUERY [thread1] Error: couldn't connect to server 172.17.0.2:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:263:13
#(connect):1:6
exception: connect failed
where 172.17.0.2 is the IP obtained by running docker inspect <container-id
I was able to connect mongo shell with in the docker using the command docker exec --it <container-id> bash.
Here's the Docker file for refrence.
RUN echo -e "\
[mongodb]\n\
name=MongoDB Repository\n\
baseurl=https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/3.2/x86_64/\n\
gpgcheck=0\n\
enabled=1\n" >> /etc/yum.repos.d/mongodb.repo
# Install mongodb
RUN yum update -y && yum install -y mongodb-org
# Set up directory requirements
RUN mkdir -p /data/db /var/log/mongodb /var/run/mongodb
VOLUME ["/data/db", "/var/log/mongodb"]
# Expose port 27017 from the container to the host
EXPOSE 27017
# Start mongodb
ENTRYPOINT ["/usr/bin/mongod"]
CMD ["--port", "27017", "--dbpath", "/data/db", "--pidfilepath", "/var/run/mongodb/mongod.pid"]
Let me know if I am missing something.
Using MacOS

Mongo Restart Error -- /var/run/mongodb/mongod.pid exists

I just started a new AWS Linux AMI 2016.09.1(HVM) and downloaded the latest Mongodb release. I am using MongoDB version 3.0.14. I updated /etc/mongod.conf to the following,
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on
all interfaces.
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
I run Mongodb for the first time using service,
sudo service mongod start
Everything works fine. When I stop Mongodb and restart,
sudo service mongod stop
sudo service mongod restart
I get the following error,
Error starting mongod. /var/run/mongodb/mongod.pid exists.
Here is what is in the logfile, /var/log/mongodb/mongod.log,
2017-01-16T14:11:16.869+0000 I CONTROL ***** SERVER RESTARTED *****
2017-01-16T14:11:16.872+0000 I CONTROL [initandlisten] MongoDB starting :
pid=2820 port=27017 dbpath=/var/lib/mongo 64-bit hos
t=ip-10-0-0-91
2017-01-16T14:11:16.872+0000 I CONTROL [initandlisten] db version v3.0.14
2017-01-16T14:11:16.872+0000 I CONTROL [initandlisten] git version:
08352afcca24bfc145240a0fac9d28b978ab77f3
2017-01-16T14:11:16.872+0000 I CONTROL [initandlisten] build info: Linux
ip-10-63-190-181 3.4.43-43.43.amzn1.x86_64 #1 SMP Mon
May 6 18:04:41 UTC 2013 x86_64 BOOST_LIB_VERSION=1_49
2017-01-16T14:11:16.872+0000 I CONTROL [initandlisten] allocator: tcmalloc
2017-01-16T14:11:16.872+0000 I CONTROL [initandlisten] options: { config:
"/etc/mongod.conf", net: { port: 27017 }, processMan
agement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" },
storage: { dbPath: "/var/lib/mongo", journal: { enabled: t
rue } }, systemLog: { destination: "file", logAppend: true, path:
"/var/log/mongodb/mongod.log" } }
2017-01-16T14:11:16.893+0000 E NETWORK [initandlisten] Failed to unlink
socket file /tmp/mongodb-27017.sock errno:1 Operation
not permitted
2017-01-16T14:11:16.893+0000 I - [initandlisten] Fatal Assertion
28578
2017-01-16T14:11:16.893+0000 I - [initandlisten]
***aborting after fassert() failure
I have seen several blogs posted about this problem with solutions but none of them seem to work. Spent all day Sunday trying to figure this one out. Never had this problem before running an earlier AWS instance and Mongo.
Ok, found the problem. I deleted the /var/run/mongodb/mongod.pid file as suggested by Dave Maples above. However, MongoDB would still not run. I looked at the log file again and now saw it barking about this file,
/tmp/mongodb-27017.sock
It looked like it did not have the correct permissions. I tried,
sudo chown mongod:mongod /tmp/mongodb-27017.sock
And it worked fine. Now when I start/stop/restart MongoDB multiple times I no longer have the problem. I think the file permissions caused MongoDB to not clean itself up properly and left /var/run/mongodb/mongod.pid file in the directory. This caused the "Error starting mongod. /var/run/mongodb/mongod.pid exists" error. However, this was not the real problem. The real problem was the /tmp/ permissions. Looking at the log file after I deleted the mongod.pid file and restarting Mongod showed the permissions problem. So here is what fixed the problem,
sudo rm /var/run/mongodb/mongod.pid
sudo chown mongod:mongod /tmp/mongodb-27017.sock
I bet if I just tried "sudo chown mongod:mongod /tmp/mongodb-27017.sock" right after installing MongoDB on the new server before running MongoDB would have avoided the problem. Wasted a perfectly good Florida sunny day on this one.
Ok, found a better solution to what I had in my first answer. My previous answer simply eliminated the symptoms. I saw that several other people had to chown various other directories. I believe the problem is that mongod does not restart properly and leaves a number of directories incorrectly set up as it fails. I suspect multiple threads are running so what directory that gets incorrectly set up is somewhat random. I am using Amazon's AWS AMI Linux release and installing MongoDB 3.4. I found a very good MongoDB install script at
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-amazon/
So here is the fix. I tested it several times and it worked each time. Install mongo as you normally would. Use the above script if helpful. Before you start mongod execute the following command,
sudo chkconfig mongod on
You will note that the above install script highlights chkconfig but at the bottom of the script where it might not get seen. This will ensure that you can successfully restart mongod each time. This should work on other linux versions.
you might change the ip in configuration file:
vim /etc/mongod.conf
# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on
all interfaces.
bindIp: xxx.xxx.xxx.xxx
You have another option in case of the assignation of user and group dosen't work but this depends directly of the state of sock file.
I moved the mongodb-27017.sock and renamed it, remove the .pid file and start the service and with this the process works
sudo mv /tmp/mongodb-27017.sock /tmp/mongodb-27017.sock2
sudo rm /var/run/mongodb/mongod.pid
sudo service mongod start
Try Rebooting the server , connecting to the server and run the command again. Worked fine for me.
After stopping the server, you are trying to restart. You can only start the server. That's why you are getting the stopping error. And also no need to worry about this error.

mongod doesn't stop (docker debian:wheezy)

I have the following Dockerfile:
FROM debian:wheezy
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.2 main" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list
RUN apt-get update
RUN apt-get install -y mongodb-org
Then I build the image:
docker build -t my/image .
and try to start and stop the server:
$ docker run -it my/image
root#35ba8193f979:/# service mongod start
[ ok ] Starting database: mongod.
root#35ba8193f979:/# service mongod stop
[FAIL] Stopping database: mongod failed!
As you can see, mongod fails to stop. I can verify this by running ps and grepping for the mongod process; it's still there.
Here's the logs:
root#fce8d9638ce4:/# cat /var/log/mongodb/mongod.log
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] MongoDB starting : pid=19 port=27017 dbpath=/var/lib/mongodb 64-bit host=fce8d9638ce4
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] db version v3.2.9
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] modules: none
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] build environment:
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] distmod: debian71
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] distarch: x86_64
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] target_arch: x86_64
2016-09-20T05:01:02.874+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2016-09-20T05:01:02.893+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-09-20T05:01:03.087+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data'
2016-09-20T05:01:03.087+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-09-20T05:01:03.156+0000 I NETWORK [initandlisten] waiting for connections on port 27017
I've googled for a solution already; most of the posts I find are very old, or don't describe the same problem as mine. Any help is greatly appreciated.
There appears to be an issue with service mongod stop since internally it calls a command which looks similar to:
start-stop-daemon --stop --pidfile /var/run/mongod.pid --user mongodb --exec /usr/bin/mongod
but the start-stop-daemon command somehow cannot find the executable /usr/bin/mongod, so it failed to stop the process. You can see the service script in /etc/init.d/mongod.
The solution that I found to be working is to call it without --exec directly from the command line:
start-stop-daemon --stop --pidfile /var/run/mongod.pid
and that seems to be able to stop the service properly.
I believe this issue is not limited to MongoDB, since I found multiple references about services not able to be stopped.

MongoDB 3.2.9 fails to start as a service on CentOS

I am trying to start mongod as a service on CentOS:
mongod --version
db version v3.2.9
git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
distmod: rhel70
distarch: x86_64
target_arch: x86_64
CentOS Linux release 7.2.1511 (Core)
/etc/selinux/config:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
mongod.conf:
systemLog:
destination: file
path: "/mnt/log/mongod.log"
logAppend: true
storage:
dbPath: "/mnt/data"
engine: wiredTiger
journal:
enabled: true
processManagement:
fork: true
pidFilePath: "/var/run/mongodb/mongod.pid"
net:
# bindIp: 127.0.0.1
port: 27017
replication:
replSetName: XXXX
security:
keyFile: "/usr/mongodb/mongodb-keyfile"
The issue states:
Starting mongod (via systemctl): Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
[FAILED]
journalctl -xe
...
Sep 20 13:10:55 ip-10-0-231-19.localdomain systemd[1]: Unit mongod.service entered failed state.
Sep 20 13:10:55 ip-10-0-231-19.localdomain systemd[1]: mongod.service failed.
Sep 20 13:10:55 ip-10-0-231-19.localdomain polkitd[9717]: Unregistered Authentication Agent for unix-process:26567:1630816 (system bus name :1.27, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
Sep 20 13:11:04 ip-10-0-231-19.localdomain sudo[26587]: centos : TTY=pts/1 ; PWD=/home/centos ; USER=root ; COMMAND=/bin/vi /etc/mongod.conf
The server starts using:
sudo mongod -f /etc/mongod.conf
I know that there was a bug opened regarding similar issue but the fix might be available in 3.2.7 already and besides it was related to the scenario when SELINUX=enforcing...
Please support.
Recently encountered a similar problem, but on FC26; here, the problem could be traced back to SELINUX and specifically the permissions on the custom dbPath directory.
After trying many things, I found that the following sequence helped resolve my problem:
MONGODB_DATADIR=/mnt/data
sudo chown -R mongodb:mongodb $MONGODB_DATADIR
sudo chmod -R 700 $MONGODB_DATADIR
SELinux settings:
sudo semanage port -a -t mongod_port_t -p tcp 27017
sudo semanage fcontext -a -t mongod_var_lib_t ${MONGODB_DATADIR}
sudo semanage fcontext -a -t mongod_var_lib_t ${MONGODB_DATADIR}/mongod.lock
sudo restorecon -v ${MONGODB_DATADIR}
You probably also have to add mongod_log_t to the custom log file location, /mnt/log/mongod.log, I did not modify that one on my end.
Actually, for me the fix was:
sudo chown -R mongod:mongod $MONGODB_DATADIR

Error while connecting mongodb shell [duplicate]

when i setup mongodb in my ubuntu , i try : ./mongo it show this error :
couldn't connect to server 127.0.0.1 shell/mongo.js
so what can i do ,
thanks
Manually remove the lockfile: sudo rm /var/lib/mongodb/mongod.lock
Run the repair script: sudo -u mongodb mongod -f /etc/mongodb.conf --repair
Please note the following:
You must run this command as the mongodb user. If you run it as root,
then root will own files in /var/lib/mongodb/ that are necessary to
run the mongodb daemon and therefore when the daemon trys to run
later as the mongodb user, it won't have permissions to start. In
that case you'll get this error: Unable to create / open lock file
for lockfilepath: /var/lib/mongodb/mongod.lock errno:13 Permission
denied, terminating.
On Ubuntu, you must specify the configuration file /etc/mongodb.conf
using the -f flag. Otherwise it will look for the data files in the
wrong place and you will see the following error: dbpath (/data/db/)
does not exist, terminating.
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo service mongodb start
Here is all, sometimes, it takes a little while to start mongo after performing these operations.
Trying running $mongod
If you get en error such as
MongoDB shell version: 2.0.5
connecting to: test
Fri Jun 1 11:20:33 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
hisham-agil:~ hisham$ mongod
mongod --help for help and startup options
Fri Jun 1 11:24:47 [initandlisten] MongoDB starting : pid=53452 port=27017 dbpath=/data/db/ 64-bit host=hisham-agil.local
Fri Jun 1 11:24:47 [initandlisten] db version v2.0.5, pdfile version 4.5
Fri Jun 1 11:24:47 [initandlisten] git version: nogitversion
Fri Jun 1 11:24:47 [initandlisten] build info: Darwin gamma.local 11.3.0 Darwin Kernel Version 11.3.0: Thu Jan 12 18:48:32 PST 2012; root:xnu-1699.24.23~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_49
Fri Jun 1 11:24:47 [initandlisten] options: {}
Fri Jun 1 11:24:47 [initandlisten] exception in initAndListen: 10296 dbpath (/data/db/) does not exist, terminating
Fri Jun 1 11:24:47 dbexit:
Fri Jun 1 11:24:47 [initandlisten] shutdown: going to close listening sockets...
Fri Jun 1 11:24:47 [initandlisten] shutdown: going to flush diaglog...
Fri Jun 1 11:24:47 [initandlisten] shutdown: going to close sockets...
Fri Jun 1 11:24:47 [initandlisten] shutdown: waiting for fs preallocator...
Fri Jun 1 11:24:47 [initandlisten] shutdown: lock for final commit...
Fri Jun 1 11:24:47 [initandlisten] shutdown: final commit...
Fri Jun 1 11:24:47 [initandlisten] shutdown: closing all files...
Fri Jun 1 11:24:47 [initandlisten] closeAllFiles() finished
Fri Jun 1 11:24:47 dbexit: really exiting now
Then you've run into a basic startup error that is pretty common.
By default mongod will try to use /data/db for its database files, which in this case, does not exist.
You can't start
mongo
until you handle
mongod.
Try creating those directories and make sure they are writable by the same user that is running the mongod process.
**See similar question-- Getting an error, "Error: couldn't connect to server 127.0.0.1 shell/mongo.js" & when trying to run mongodb on mac osx lion
This is actually not an error... What happens here is that Mongo relies on a daemon in order to run the local database server, so in order to "fire up" the mongo server in your shell, you have to start the mongo service first.
For Fedora Linux (wich is the Distro I use) You have to run these commands:
1 sudo service mongod start
2 mongo
And there you have it! the server is going to run. Now, If you want Mongo service
to Start when the system boots then you have to run:
sudo chkconfig --levels 235 mongod on
And that's all! If you do that, now in the shell you just have to type mongo in order
to start the server but that's pretty much it, the problem is you have to start the SERVICE first and then the SERVER :)
P.S. The commands I posted might work on other linux distros as well, not just in fedora... In case not maybe you have to tweak some words depending on the distro you're using ;)
I got the same problem when I tried to install mongo. I got Error as,
Error
"Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84"
Solution:
First install mongod by using:
sudo apt-get install mongodb-server
Then type
mongod --dbpath /mongo/db
Then
sudo rm /var/lib/mongodb/mongod.lock
Then
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
Thank You
You need to delete the lockfile mongod.lock or /var/lib/mongodb/mongod.lock on ubuntu, then you need to run mongod.exe or service mongodb start on ubuntu first, then run mongo.exe or mongo on ubuntu.
Either your mongod is not running (check using "ps" command) or it is listening on some outside IP address and not on localhost. So first check the process list if 'mongod' is running. If yes, check with "netstat -nap" for the related port.
Of course you can start mongod on the console manually or even look into the mongod logfile
(if there is one configured...depending on how you installed mongod).
First you have to make sure that all the files and directories in your /var/lib/mongodb/ folder (or whichever folder dbpath points to) belong to the mongodb user and mongodb group.
cd /var/lib/mongodb/
sudo chown mongodb filename.*
sudo chgrp mongodb filename.*
sudo chown -R mongodb directory
sudo chgrp -R mongodb directory
(Replace filename and directory with their respective names)
Then you can remove the lock, repair the database and restart the daemon as other people already mentioned:
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo service mongodb start
First start your mongo server by
Users-MacBook-Pro:csv1 Admin$ mongod
all output going to: /usr/local/var/log/mongodb/mongo.log
Then open another terminal window and open shell
Users-MacBook-Pro:csv1 Admin$ mongo
Also check that your root partition has enough space to start mongod.
df -h /
You'll see smth like this on mongod launch:
Mon Aug 12 17:02:59.159 [initandlisten] recover : no journal files present, no recovery needed
Mon Aug 12 17:02:59.159 [initandlisten]
Mon Aug 12 17:02:59.159 [initandlisten] ERROR: Insufficient free space for journal files
Mon Aug 12 17:02:59.159 [initandlisten] Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles
Mon Aug 12 17:02:59.159 [initandlisten]
Mon Aug 12 17:02:59.159 [initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating
Mon Aug 12 17:02:59.159 dbexit:
Mon Aug 12 17:02:59.159 [initandlisten] shutdown: going to close listening sockets...
On Ubuntu, try this:
sudo invoke-rc.d mongodb start
It could be combination of $PATH and Permission issue.
Try following steps given below:
Update your $PATH variable to point to your MongoDB bin file. In my case brew install MongoDB to this folder:
/usr/local/Cellar/mongodb/2.4.6/
In order to update your $PATH variable, do following:
$ sudo vi /etc/paths
Then, press ‘i’ to insert text in Vi and append the your MongoDB path to the end of the ‘paths’ file and restart the terminal.
/usr/local/Cellar/mongodb/2.4.6/bin
Use ‘Esc : w q’ to save and exit from Vi editor.
Use echo to display your path variable:
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/Cellar/mongodb/2.4.6/bin
Now try to check the Mongo version, if you get following, then you are on the right track!
$ mongo --version
MongoDB shell version: 2.4.6
Now we need to create the database directory. I used the default ‘/data/db’ location suggested in MongoDB docs. I also created a log directory to avoid any permission issues while Mongo tries to create any logs. Change ownership and that will do the job.
$ sudo mkdir /data/db
$ sudo mkdir /data/log
$ whoami
username
$ chown -R username /data
Now, we will create a default config file for MongoDB to be provided for the first time we run ‘mongod’ command. Now, I will also like to point out that ‘mongod’ will start a service, which will listen for incoming data connections. This is similar having ‘$service mysqld start’ executed.Let’s go ahead and create the config file. Please keep in mind that I have created very basic config file. However, you can add many other variables to configure MongoDB. This is the first time I am playing with MongoDB, so I just know as much as I read on MongoDB docs!I created ‘mongodb.conf’.
$ sudo vi /etc/mongodb.conf
Add following:
fork = true
port = 27017
quiet = true
dbpath = /data/db
logpath = /data/log/mongod.log
logappend = true
journal = true
Please note that the default port for MongoDB server is 27017. Use your own path for dbpath and logpath you created in Step – 5. Don’t forget to close and save the conf file.
Now we are all set to start our MongoDB service. Open two instances of Terminal.In Terminal 1, type in:
$ sudo mongod -f /etc/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3516
all output going to: /data/log/mongod.log
child process started successfully, parent exiting
If you get above message, then know that you have successfully started your Mongod service.
Now, to connect to it, in Terminal 2 type following:
$mongo test
MongoDB shell version: 2.4.6
connecting to: test
Server has startup warnings:
Tue Sep 3 16:55:43.527 [initandlisten]
Tue Sep 3 16:55:43.527 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
>
Ignore the warnings, but you are successfully connected to the ‘test’ database! Cool!
That's all. I applied this solution, when I tried to install copy of MongoDB on my Mac for the first time. See if this help you too.
For detailed post you can go here - http://arcanebytes.com/2013/09/03/mongodb-installation-on-mac-os-x/#comment-1036112094.
I hope it helps!
Cheers,
Chinmay
I solved this problem on ubuntu 12.04 by following steps:
1) sudo rm /var/log/mongodb
2) sudo rm /var/lib/mongodb
3) I removed mongo and then installed it again
4) sudo service mongodb restart
and All is Well
For Ubuntu:
Just Open the terminal and enter the below command.
You just have to restart your mongoDB.
sudo service mongodb restart