LoGWRiTer
LoGWRiTer

Reputation: 129

MongoDB can not start after restart the system on Ubuntu 14.04 LTS

I've installed mongoDB on ubuntu 14.04 according to the official installation guide: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

I enter the terminal using "mongod" and everything is OK.

But when I shut down my ubuntu and restart it, command 'mongod' just cannot start, one error happens below:

2015-01-30T15:47:51.582-0800 [initandlisten] allocator: tcmalloc
2015-01-30T15:47:51.582-0800 [initandlisten] options: {}
2015-01-30T15:47:51.583-0800 [initandlisten] exception in initAndListen: 10296 
*********************************************************************
 ERROR: dbpath (/data/db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating

After that, I tried to create the folder and chmod it using:

sudo mkdir -p /data/db/
sudo chown `id -u` /data/db

but another error happened:

2015-01-30T16:01:43.855-0800 [initandlisten] allocator: tcmalloc
2015-01-30T16:01:43.855-0800 [initandlisten] options: {}
2015-01-30T16:01:43.859-0800 [initandlisten] journal dir=/data/db/journal
2015-01-30T16:01:43.859-0800 [initandlisten] recover : no journal files present, no recovery needed
2015-01-30T16:01:43.994-0800 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2015-01-30T16:01:43.994-0800 [initandlisten] ERROR: addr already in use
2015-01-30T16:01:43.994-0800 [initandlisten] allocating new ns file /data/db/local.ns, filling with zeroes...
2015-01-30T16:01:44.197-0800 [FileAllocator] allocating new datafile /data/db/local.0, filling with zeroes...

I also looked for /etc/mongod.conf,

# Where to store the data.

# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
dbpath=/var/lib/mongodb

#where to log
logpath=/var/log/mongodb/mongod.log

logappend=true

#port = 27017

where I found the default data storage folder is not /data/db

I've tried other ways like

sudo service mongod stop
sudo service mongod restart

But they simply do not work.

May be there's another instance already run when the system starts, but how can I stop it?

Upvotes: 0

Views: 1667

Answers (1)

jbihan
jbihan

Reputation: 3099

ERROR: addr already in use indeed means that you have another instance already running.

Did you try to:

  • type mongo in the terminal and see if it connects to the server?
  • check the logs in /var/log/mongodb/mongod.log? Do they tell you an instance is up?
  • type ps -edf | grep mongod and see if any process is running? I suppose it's not a good practice but did you try to kill it if one shows up, and type mongod again?

Aynway, you may want to try two things:

  • When you type sudo service mongod stop and before the sudo service mongod restart, try to type mongod in the terminal. As you normally stopped the running instance, you should be able to start your own
  • You could try to start another instance. For that, you will have to specify at least the port (and chose a different one than the default one), and preferably the dbpath (make sure to chose a path to a directory that already exists). You can do that on the command line, for example:

$ mongod --port 28000 --dbpath /path/to/your/db

Or you can create your own mongodb.conf, based on the default one, change the values for port and dbpath, and start mongod specifying the path to this config file:

$ mongod -f /path/to/your/mongod.conf

Upvotes: 3

Related Questions