MongoDB service won't start after moving location (Centos 7.1.1503) - mongodb

Previously mongodb was located at /var/lib/mongod. I've moved this to /home/mongod, and updated the /etc/mongod.conf file to point to this location. The permissions of the folder look correct:
drwxrwxr-x. 2 mongod mongod 6 Aug 6 10:37 admin
-rw-------. 1 mongod mongod 67108864 Aug 6 11:49 admin.0
-rw-------. 1 mongod mongod 16777216 Aug 6 11:49 admin.ns
drwxrwxr-x. 2 mongod mongod 6 Aug 6 10:40 journal
drwxrwxr-x. 2 mongod mongod 6 Aug 6 10:37 local
-rw-------. 1 mongod mongod 67108864 Aug 6 11:49 local.0
-rw-------. 1 mongod mongod 16777216 Aug 6 11:49 local.ns
-rwxr-xr-x. 1 mongod mongod 0 Aug 6 11:50 mongod.lock
-rwxrwxr-x. 1 mongod mongod 0 Aug 6 10:12 mongod.lock.bak
drwxrwxr-x. 2 mongod mongod 6 Aug 6 10:37 sphere
-rw-------. 1 mongod mongod 67108864 Aug 6 11:50 sphere.0
-rw-------. 1 mongod mongod 134217728 Aug 6 11:49 sphere.1
-rw-------. 1 mongod mongod 268435456 Aug 6 11:49 sphere.2
-rw-------. 1 mongod mongod 536870912 Aug 6 11:49 sphere.3
-rw-------. 1 mongod mongod 1073741824 Aug 6 11:50 sphere.4
-rw-------. 1 mongod mongod 2146435072 Aug 6 11:50 sphere.5
-rw-------. 1 mongod mongod 16777216 Aug 6 11:50 sphere.ns
drwxr-xr-x. 2 mongod mongod 6 Aug 6 11:50 _tmp
and when I run from the command line it works:
[user#localhost home]$ sudo -u mongod mongod --dbpath /home/mongod
[sudo] password for user:
2015-08-06T12:04:35.761+0100 [initandlisten] MongoDB starting : pid=10235 port=27017 dbpath=/home/mongod 64-bit host=localhost.localdomain
2015-08-06T12:04:35.762+0100 [initandlisten] db version v2.6.10
2015-08-06T12:04:35.762+0100 [initandlisten] git version: 5901dbfb49d16eaef6f2c2c50fba534d23ac7f6c
2015-08-06T12:04:35.762+0100 [initandlisten] build info: Linux build18.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-08-06T12:04:35.762+0100 [initandlisten] allocator: tcmalloc
2015-08-06T12:04:35.762+0100 [initandlisten] options: { storage: { dbPath: "/home/mongod" } }
2015-08-06T12:04:35.772+0100 [initandlisten] journal dir=/home/mongod/journal
2015-08-06T12:04:35.773+0100 [initandlisten] recover : no journal files present, no recovery needed
2015-08-06T12:04:36.865+0100 [initandlisten] waiting for connections on port 27017
However running the using systemctl fails:
sudo service mongod restart
Restarting mongod (via systemctl): Job for mongod.service failed. See 'systemctl status mongod.service' and 'journalctl -xn' for details.
[FAILED]
The /etc/mongod.conf file is as follows
logpath=/var/log/mongodb/mongod.log
logappend=true
# fork and run in background
fork=true
#port=27017
dbpath=/home/mongod
# location of pidfile
pidfilepath=/var/run/mongodb/mongod.pid
# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip=127.0.0.1
The output in /var/log/mongod/mongod.log is as follows:
2015-08-06T12:08:35.402+0100 ***** SERVER RESTARTED *****
2015-08-06T12:08:35.407+0100 [initandlisten] MongoDB starting : pid=10370 port=27017 dbpath=/home/mongod 64-bit host=localhost.localdomain
2015-08-06T12:08:35.407+0100 [initandlisten] db version v2.6.10
2015-08-06T12:08:35.407+0100 [initandlisten] git version: 5901dbfb49d16eaef6f2c2c50fba534d23ac7f6c
2015-08-06T12:08:35.407+0100 [initandlisten] build info: Linux build18.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-08-06T12:08:35.407+0100 [initandlisten] allocator: tcmalloc
2015-08-06T12:08:35.407+0100 [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1" }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/home/mongod" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2015-08-06T12:08:35.407+0100 [initandlisten] exception in initAndListen std::exception: boost::filesystem::status: Permission denied: "/home/mongod/local.ns", terminating
2015-08-06T12:08:35.407+0100 [initandlisten] dbexit:
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: going to close listening sockets...
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: going to flush diaglog...
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: going to close sockets...
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: waiting for fs preallocator...
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: lock for final commit...
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: final commit...
2015-08-06T12:08:35.407+0100 [initandlisten] shutdown: closing all files...
2015-08-06T12:08:35.407+0100 [initandlisten] closeAllFiles() finished
2015-08-06T12:08:35.407+0100 [initandlisten] dbexit: really exiting now
I've tried deleting the lock file /home/mongod/mongod.lock and running a repair with sudo -u mongod mongod --dbpath /home/mongod --repair but the error still persists. This is causing major headaches!!

So it turns out the problem was SElinux, and the solution is the same as this question.
It was permission related and is due to the SELinux security context which is set to enforced by default on CentOS.
sudo ausearch -m avc -ts today | audit2allow
On my machine I had some mongo related audits as follows:
#============= mongod_t ==============
allow mongod_t home_root_t:file getattr;
allow mongod_t user_home_dir_t:dir search;
allow mongod_t var_lib_t:lnk_file read;
allow mongod_t default_t:file getattr;
To fix the above, you do the following:
sudo chcon -Rv --type=mongod_var_lib_t /path_to_your_mongo
Where /path_to_your_mongo is where your mongod data files are located (in my case /home/mongod but often /var/lib/mongo or /data/db.

Related

Mongodb error on starting

When i start mongo db it instantly crashes and goes back to the normal command line. I am on Mac runing the MEAN stack if that helps. Below is the error:
$sudo mongod
Sun Jun 1 21:01:01.728 [initandlisten] MongoDB starting : pid=47937 port=3000 dbpath=/usr/local/var/mongodb 64-bit host=NoHax4You
Sun Jun 1 21:01:01.728 [initandlisten]
Sun Jun 1 21:01:01.729 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Sun Jun 1 21:01:01.729 [initandlisten] db version v2.4.9
Sun Jun 1 21:01:01.729 [initandlisten] git version: nogitversion
Sun Jun 1 21:01:01.729 [initandlisten] build info: Darwin minimavericks.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Sun Jun 1 21:01:01.729 [initandlisten] allocator: tcmalloc
Sun Jun 1 21:01:01.729 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb", logappend: "true", logpath: "/usr/local/var/log/mongodb/mongo.log", port: 3000 }
Sun Jun 1 21:01:01.729 [initandlisten] exception in initAndListen: 10310 Unable to lock file: /usr/local/var/mongodb/mongod.lock. Is a mongod instance already running?, terminating
Sun Jun 1 21:01:01.729 dbexit:
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: going to close listening sockets...
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: going to flush diaglog...
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: going to close sockets...
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: waiting for fs preallocator...
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: lock for final commit...
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: final commit...
Sun Jun 1 21:01:01.729 [initandlisten] shutdown: closing all files...
Sun Jun 1 21:01:01.729 [initandlisten] closeAllFiles() finished
Sun Jun 1 21:01:01.729 dbexit: really exiting now
Thanks,
Ewan
First of all, look for other instances of mongod running on the system using the age-old command:
ps ax | grep mongod
If you see a line like -
98555 ?? S 4:40.89 mongod --dbpath /Volumes/ComputerName/data/db
-PID- -name- -------------path------------
then there is a mongod process running already. If so kill it and then start mongod again.
To kill a process with PID = 0000, in Unix like environment use -
kill -9 0000
If your console returns something like, -bash: kill: (98555) - Operation not permitted, use
sudo !!
to repeat the command as super user. This should get you going.
PS: If you haven't stored any data in your db yet, delete /data and then create the /data/db directory again. Do a sudo mongod and it should work.
I had the same issue, and this one liner fix my issue
killall mongod
Run the above command inside your Terminal
Hope that helps!
I first opened the /data/db/mongod.lock file, found my process number there, then killed it with kill -9 <processnumber>. That worked for me.

MongoDB Start several mongod with different ports

I can't change port in second mongod in my cmd
1 I'm starting mongod in c:\mongodb\bin
2 I'm starting cmd and writing
cd c:\mongodb\bin
mongod --port 10003
But second mongod not work.
Help me.Thank you!
This is error what show me
C:\Windows\system32> cd c:\mongodb\bin
c:\mongodb\bin>mongod --port 10003
Wed Apr 16 22:15:56.619
Wed Apr 16 22:15:56.620 warning: 32-bit servers don't have journaling enabled by
default. Please use --journal if you want durability.
Wed Apr 16 22:15:56.622
Wed Apr 16 22:15:56.635 [initandlisten] MongoDB starting : pid=8240 port=10003 d
bpath=\data\db\ 32-bit host=Danil
Wed Apr 16 22:15:56.637 [initandlisten]
Wed Apr 16 22:15:56.638 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary
.
Wed Apr 16 22:15:56.640 [initandlisten] ** 32 bit builds are limited to le
ss than 2GB of data (or less with --journal).
Wed Apr 16 22:15:56.641 [initandlisten] ** Note that journaling defaults t
o off for 32 bit and is currently off.
Wed Apr 16 22:15:56.643 [initandlisten] ** See http://dochub.mongodb.org/c
ore/32bit
Wed Apr 16 22:15:56.645 [initandlisten]
Wed Apr 16 22:15:56.646 [initandlisten] db version v2.4.10
Wed Apr 16 22:15:56.648 [initandlisten] git version: e3d78955d181e475345ebd60053
a4738a4c5268a
Wed Apr 16 22:15:56.650 [initandlisten] build info: windows sys.getwindowsversio
n(major=6, minor=0, build=6002, platform=2, service_pack='Service Pack 2') BOOST
_LIB_VERSION=1_49
Wed Apr 16 22:15:56.651 [initandlisten] allocator: system
Wed Apr 16 22:15:56.653 [initandlisten] options: { port: 10003 }
Wed Apr 16 22:15:56.655 [initandlisten] exception in initAndListen: 13627 Unable
to create/open lock file: \data\db\mongod.lock ??????? ?? ????? ???????? ??????
? ?????, ??? ??? ???? ???? ????? ?????? ?????????.. Is a mongod instance alread
y running?, terminating
Wed Apr 16 22:15:56.657 dbexit:
Wed Apr 16 22:15:56.658 [initandlisten] shutdown: going to close listening socke
ts...
Wed Apr 16 22:15:56.660 [initandlisten] shutdown: going to flush diaglog...
Wed Apr 16 22:15:56.662 [initandlisten] shutdown: going to close sockets...
Wed Apr 16 22:15:56.663 [initandlisten] shutdown: waiting for fs preallocator...
Wed Apr 16 22:15:56.665 [initandlisten] shutdown: closing all files...
Wed Apr 16 22:15:56.666 [initandlisten] closeAllFiles() finished
Wed Apr 16 22:15:56.668 dbexit: really exiting now
c:\mongodb\bin>
try to start mongod with admin option as it is not able to open the file mongod.lock
You can't start multiple MongoDB processes on the same database.
What you need to do is:
mongod --dbpath c:\database1 --port 27017
mongod --dbpath c:\database2 --port 27018
Remember that you must manually create the database folders.
Usually if you read carefully the error log you will find the problem:
"13627 Unable to create/open lock file: \data\db\mongod.lock.
Is a mongod instance already running?"

New to MongoDB: Can't get into mongo shell

I've just installed MongoDB via Homebrew, and I'm trying to get it up and running. I've launched it using mongodin the command line, and now I'm trying to get into the shell by using the command mongo once it is running. However, nothing happens when I run the command. Here is a paste of my log:
Fri Sep 6 16:54:02.458 [initandlisten] MongoDB starting : pid=17731 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=lsadmin’s-MacBook-Pro
Fri Sep 6 16:54:02.458 [initandlisten]
Fri Sep 6 16:54:02.458 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Fri Sep 6 16:54:02.458 [initandlisten] db version v2.4.6
Fri Sep 6 16:54:02.458 [initandlisten] git version: nogitversion
Fri Sep 6 16:54:02.458 [initandlisten] build info: Darwin minimountain.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/ RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Fri Sep 6 16:54:02.458 [initandlisten] allocator: tcmalloc
Fri Sep 6 16:54:02.458 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb", logappend: "true", logpath: "/usr/local/var/log/mongodb/mongo.log" }
Fri Sep 6 16:54:02.458 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Fri Sep 6 16:54:02.459 [initandlisten] recover : no journal files present, no recovery needed
Fri Sep 6 16:54:02.543 [websvr] admin web console waiting for connections on port 28017
Fri Sep 6 16:54:02.543 [initandlisten] waiting for connections on port 27017
Fri Sep 6 16:55:02.552 [PeriodicTask::Runner] task: WriteBackManager::cleaner took: 14ms
And this is a paste of my config file:
# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /usr/local/var/mongodb
# Append logs to /usr/local/var/log/mongodb/mongo.log
logpath = /usr/local/var/log/mongodb/mongo.log
logappend = true
# Only accept local connections
bind_ip = 127.0.0.1
And a paste of command line:
-> mongod
all output going to: /usr/local/var/log/mongodb/mongo.log
mongo
Running a second shell and then running ./mongo in /usr/local/cellar/mongodb/2.4.6/ allowed me access to the shell.
Obvious solution, but documentation makes it seem like you can run it from the mongod prompt.

mongodb crashes after unexpected shutdown

after our vps got down and we boot it, mongod service didnt start automatically and we cannot start it by service mongod start,
file /var/log/mongo/mongod.log contains following log:
***** SERVER RESTARTED *****
Thu Oct 11 13:51:18
Thu Oct 11 13:51:18 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Oct 11 13:51:18
Thu Oct 11 13:51:18 [initandlisten] MongoDB starting : pid=3821 port=27017 dbpath=/var/lib/mongo 32-bit host=server2.paransa.org
Thu Oct 11 13:51:18 [initandlisten]
Thu Oct 11 13:51:18 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Oct 11 13:51:18 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Oct 11 13:51:18 [initandlisten] ** with --journal, the limit is lower
Thu Oct 11 13:51:18 [initandlisten]
Thu Oct 11 13:51:18 [initandlisten] ** WARNING: You are running in OpenVZ. This is known to be broken!!!
Thu Oct 11 13:51:18 [initandlisten]
Thu Oct 11 13:51:18 [initandlisten] db version v2.2.0, pdfile version 4.5
Thu Oct 11 13:51:18 [initandlisten] git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207
Thu Oct 11 13:51:18 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49
Thu Oct 11 13:51:18 [initandlisten] options: { config: "/etc/mongod.conf", dbpath: "/var/lib/mongo", fork: "true", logappend: "true", logpath: "/var/log/mongo/mongod.log", pidfilepath: "/var/run/mongodb/mongod.pid" }
Thu Oct 11 13:51:18 [initandlisten] couldn't open /var/lib/mongo/mydb_main.ns errno:13 Permission denied
Thu Oct 11 13:51:18 [initandlisten] error couldn't open file /var/lib/mongo/mydb_main.ns terminating
Thu Oct 11 13:51:18 dbexit:
Thu Oct 11 13:51:18 [initandlisten] shutdown: going to close listening sockets...
Thu Oct 11 13:51:18 [initandlisten] shutdown: going to flush diaglog...
Thu Oct 11 13:51:18 [initandlisten] shutdown: going to close sockets...
Thu Oct 11 13:51:18 [initandlisten] shutdown: waiting for fs preallocator...
Thu Oct 11 13:51:18 [initandlisten] shutdown: closing all files...
Thu Oct 11 13:51:18 [initandlisten] closeAllFiles() finished
Thu Oct 11 13:51:18 [initandlisten] shutdown: removing fs lock...
Thu Oct 11 13:51:18 dbexit: really exiting now
as you may see, log says mongo server cant open *.ns file cause lake of permission
but if i run the server manually by following command:
mongod --dbpath=/var/lib/mongo -f /etc/mongod.conf
it seems everything is fine and about the log file:
***** SERVER RESTARTED *****
Thu Oct 11 14:02:06
Thu Oct 11 14:02:06 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Thu Oct 11 14:02:06
Thu Oct 11 14:02:06 [initandlisten] MongoDB starting : pid=4090 port=27017 dbpath=/var/lib/mongo 32-bit host=server2.paransa.org
Thu Oct 11 14:02:06 [initandlisten]
Thu Oct 11 14:02:06 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Thu Oct 11 14:02:06 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Oct 11 14:02:06 [initandlisten] ** with --journal, the limit is lower
Thu Oct 11 14:02:06 [initandlisten]
Thu Oct 11 14:02:06 [initandlisten] ** WARNING: You are running in OpenVZ. This is known to be broken!!!
Thu Oct 11 14:02:06 [initandlisten]
Thu Oct 11 14:02:06 [initandlisten] db version v2.2.0, pdfile version 4.5
Thu Oct 11 14:02:06 [initandlisten] git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207
Thu Oct 11 14:02:06 [initandlisten] build info: Linux domU-12-31-39-01-70-B4 2.6.21.7-2.fc8xen #1 SMP Fri Feb 15 12:39:36 EST 2008 i686 BOOST_LIB_VERSION=1_49
Thu Oct 11 14:02:06 [initandlisten] options: { config: "/etc/mongod.conf", dbpath: "/var/lib/mongo", fork: "true", logappend: "true", logpath: "/var/log/mongo/mongod.log", pidfilepath: "/var/run/mongodb/mongod.pid" }
Thu Oct 11 14:02:07 [websvr] admin web console waiting for connections on port 28017
Thu Oct 11 14:02:07 [initandlisten] waiting for connections on port 27017
and using --repair arg didnt help
(maybe because it could start manually with mongod --dbpath=/var/lib/mongo -f /etc/mongod.conf and adding --repair arg to the command, logs everything is fine!...)
any suggestion?
This is a permissions issue, you are running as mongod (or mongodb etc.) user when you start via service, and you are likely running as root (you confirm this in the comments above) when you are using sudo or invoking as root. You need to fix the permissions for all the files in that folder and not start the service as root, ever.
To fix the files based on what you have posted, assuming your relevant user is mongodb and the group is mongodb, you would do the following with sudo (or as root) - substitute for the appropriate user for your system:
chown -R mongodb:mongodb /var/lib/mongo
chown -R mongodb:mongodb /var/run/mongodb
chown mongodb:mongodb /var/log/mongo/mongod.log
Once you fix the permissions on these folders you should be able to start via service again. Note: if you post the output of ls -al /var/lib/mongo then I can give you the exact commands you need to run
sudo rm /data/db/mongod.lock
sudo mongod --dbpath /data/db --repair
sudo mongod --dbpath /data/db
Try deleting the *.lock file in "\data\db" folder before starting mongod.exe in CMD.
Stop the MongoDB service
sudo service mongodb stop
Remove the MongoDB lock file
sudo rm /var/lib/mongodb/mongod.lock
Change ownership from root to the MongoDB path
sudo chown -R mongodb:mongodb /var/lib/mongodb/
Access the mongodb Shell
sudo mongod --dbpath=/var/lib/mongodb
Start the MongoDB service
sudo service mongodb start
Test the mongo application
mongo
You can run automatically your mongodb forever from the rc.local, using this command:
su pi -c 'sudo mongod --repairpath your_path'
and don't worry about the unexpected shutdown.

How to resolve error :dbpath (/data/db/) does not exist permanently in MongoDB

I have installed mongodb in my Ubuntu 10.04.
I know that when it comes to start the mongodb server with the command "mongod",then it expects /data/db folder and it can be easily resolved by creating "/data/db/". One more way is to provide your own path using mongod --dbpath "path",when we intend to give our own custom path for db.
But while going through http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ link i found that there is a configuration file.
I made the following changes to it.
# mongodb.conf
dbpath=/EBS/Work/mongodb/data/db/
logpath=/EBS/Work/mongodb/mongodb.log
logappend=true
But still when I try to start the server with "mongod" it throws the same error
i.e error :dbpath (/data/db/) does not exist .
I wanted to know that how can I permanently redirect my dbpath to my own custom folder cause everytime you don't want to type the path using "mongod --dbpath path".Rather we look to make some changes in configuration file.
Assuming you have followed the instructions to install a packaged version of MongoDB, you should be starting and stopping mongod using service.
To start mongod:
sudo service mongodb start
To stop mongod:
sudo service mongodb stop
If you use the service command to start and stop, it should be using the configuration file: /etc/mongodb.conf.
Starting mongod from the command line
If you run mongod directly instead of using the service definition, you will also have to specify a configuration file as a command line parameter if you want one to be used:
mongod --config /etc/mongodb.conf
Here is how I got this resolved, simply by following their official Doc . HERE.
Step by step from teminal (running ubuntu) :
cd into /srv folder =>> cd /srv/
make directory =>> mkdir -p mongodb
From within /srv/ give the newly created mongodb folder the right permissions and group ......
Lastly, run this => mongod --dbpath /srv/mongodb/
"step by step" Copy of the terminal ...... :)
~$ mongod
Tue Jun 3 20:27:39.564 [initandlisten] MongoDB starting : pid=5380 port=27017 dbpath=/srv/mongodb/ 64-bit host= -SVE1411EGXB
Tue Jun 3 20:27:39.564 [initandlisten] db version v2.4.10
Tue Jun 3 20:27:39.564 [initandlisten] git version: e3d78955d181e475345ebd60053a4738a4c5268a
Tue Jun 3 20:27:39.564 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Tue Jun 3 20:27:39.564 [initandlisten] allocator: tcmalloc
Tue Jun 3 20:27:39.564 [initandlisten] options: { dbpath: "/srv/mongodb/" }
Tue Jun 3 20:27:39.565 [initandlisten] exception in initAndListen: 10296
*********************************************************************
ERROR: dbpath (/srv/mongodb/) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
Tue Jun 3 20:27:39.565 dbexit:
Tue Jun 3 20:27:39.565 [initandlisten] shutdown: going to close listening sockets...
Tue Jun 3 20:27:39.565 [initandlisten] shutdown: going to flush diaglog...
Tue Jun 3 20:27:39.565 [initandlisten] shutdown: going to close sockets...
Tue Jun 3 20:27:39.565 [initandlisten] shutdown: waiting for fs preallocator...
Tue Jun 3 20:27:39.565 [initandlisten] shutdown: lock for final commit...
Tue Jun 3 20:27:39.565 [initandlisten] shutdown: final commit...
Tue Jun 3 20:27:39.565 [initandlisten] shutdown: closing all files...
Tue Jun 3 20:27:39.565 [initandlisten] closeAllFiles() finished
Tue Jun 3 20:27:39.565 dbexit: really exiting now
~$ mongod --dbpath /srv/mongodb/
Tue Jun 3 20:27:55.616 [initandlisten] MongoDB starting : pid=5445 port=27017 dbpath=/srv/mongodb/ 64-bit host= -SVE1411EGXB
Tue Jun 3 20:27:55.616 [initandlisten] db version v2.4.10
Tue Jun 3 20:27:55.616 [initandlisten] git version: e3d78955d181e475345ebd60053a4738a4c5268a
Tue Jun 3 20:27:55.616 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Tue Jun 3 20:27:55.616 [initandlisten] allocator: tcmalloc
Tue Jun 3 20:27:55.616 [initandlisten] options: { dbpath: "/srv/mongodb/" }
Tue Jun 3 20:27:55.617 [initandlisten] exception in initAndListen: 10296
~$ sudo service mongodb start
start: Job is already running: mongodb
~$ sudo service mongodb stop
mongodb stop/waiting
~$ cd /srv/
~$~$/srv$ ls
~$ /srv$ mkdir mongodb
~$ sudo chgrp /srv
~$ sudo chmod 775 /srv
~$ cd /srv/
/srv$ ls
/srv$ mkdir mongodb
/srv$ ls mongodb
/srv$ cd
~$ mongod --dbpath /srv/mongodb/
Tue Jun 3 20:40:57.457 [initandlisten] MongoDB starting : pid=6018 port=27017 dbpath=/srv/mongodb/ 64-bit host= -SVE1411EGXB
Tue Jun 3 20:40:57.457 [initandlisten] db version v2.4.10
Tue Jun 3 20:40:57.457 [initandlisten] git version: e3d78955d181e475345ebd60053a4738a4c5268a
Tue Jun 3 20:40:57.457 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Tue Jun 3 20:40:57.457 [initandlisten] allocator: tcmalloc
Tue Jun 3 20:40:57.457 [initandlisten] options: { dbpath: "/srv/mongodb/" }
Tue Jun 3 20:40:57.520 [initandlisten] journal dir=/srv/mongodb/journal
Tue Jun 3 20:40:57.521 [initandlisten] recover : no journal files present, no recovery needed
Tue Jun 3 20:41:00.545 [initandlisten] preallocateIsFaster=true 36.86
Tue Jun 3 20:41:03.489 [initandlisten] preallocateIsFaster=true 35.06
Tue Jun 3 20:41:07.456 [initandlisten] preallocateIsFaster=true 34.44
Tue Jun 3 20:41:07.456 [initandlisten] preallocateIsFaster check took 9.935 secs
Tue Jun 3 20:41:07.456 [initandlisten] preallocating a journal file /srv/mongodb/journal/prealloc.0
Tue Jun 3 20:41:10.009 [initandlisten] File Preallocator Progress: 985661440/1073741824 91%
Tue Jun 3 20:41:22.273 [initandlisten] preallocating a journal file /srv/mongodb/journal/prealloc.1
Tue Jun 3 20:41:25.009 [initandlisten] File Preallocator Progress: 933232640/1073741824 86%
Tue Jun 3 20:41:37.119 [initandlisten] preallocating a journal file /srv/mongodb/journal/prealloc.2
Tue Jun 3 20:41:40.093 [initandlisten] File Preallocator Progress: 1006632960/1073741824 93%
Tue Jun 3 20:41:52.450 [FileAllocator] allocating new datafile /srv/mongodb/local.ns, filling with zeroes...
Tue Jun 3 20:41:52.450 [FileAllocator] creating directory /srv/mongodb/_tmp
Tue Jun 3 20:41:52.503 [FileAllocator] done allocating datafile /srv/mongodb/local.ns, size: 16MB, took 0.022 secs
Tue Jun 3 20:41:52.517 [FileAllocator] allocating new datafile /srv/mongodb/local.0, filling with zeroes...
Tue Jun 3 20:41:52.537 [FileAllocator] done allocating datafile /srv/mongodb/local.0, size: 64MB, took 0.02 secs
Tue Jun 3 20:41:52.538 [websvr] admin web console waiting for connections on port 28017
Tue Jun 3 20:41:52.538 [initandlisten] waiting for connections on port 27017
Change the user of the new data directory:
chown mongodb [rute_directory]
And try another time to start the mongo service
service mongodb start
I solve the same problem with this.
Find mongo log file from root system folder
sudo find / -name "mongodb.log" -type f
result:
/var/log/mongodb/mongodb.log
open /var/log/mongodb/mongodb.log
search for last "exception" word
try to correct exception
In my case exception was the next:
2015-07-30T15:09:15.806+0300 [initandlisten] exception in initAndListen: 13597 can't start without --journal enabled when journal/ files are present, terminating
I made the next:
cd /var/lib/mongodb
rm -r journal/
If you are using mac catalina:
mongod --dbpath=/Users/user/data/db
leave this window
then you can type in another window.
mongo
show dbs