MongoDB service not working after upgrade to Ubuntu 15.04 - linux

I have recently upgraded my ubuntu from 14.10 to 15.04. All features seems to be working fine except MongoDB. I am using mongoDB with ruby on rails application using Mongoid gem. MongoDB is not controllable from service as we do normally in ubuntu.
sudo service mongodb start
or
sudo service mongod start
I get this error message
Failed to restart mongod.service: Unit mongod.service failed to load:
No such file or directory.
But i have to start it manually each time i have to connect my application to MongoDB server using
sudo mongod -f /etc/mongod.conf
So mongodb is connected as long as that terminal is opened. I am using MongoDB in Ruby on Rails application using Mongoid adapater/ORM.
When i run
sudo service mongodb status
i get following output
mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since بدھ 2015-05-06 14:47:53 PKT; 5s ago
Docs: man:mongod(1)
Process: 28602 ExecStart=/usr/bin/mongod --config /etc/mongodb.conf (code=exited, status=4)
Main PID: 28602 (code=exited, status=4)
مٓی 06 14:47:53 NX00443 systemd[1]: Started An object/document-oriented database.
مٓی 06 14:47:53 NX00443 systemd[1]: Starting An object/document-oriented database...
مٓی 06 14:47:53 NX00443 systemd[1]: mongodb.service: main process exited, code=exited, status=4/NOPERMISSION
مٓی 06 14:47:53 NX00443 systemd[1]: Unit mongodb.service entered failed state.
مٓی 06 14:47:53 NX00443 systemd[1]: mongodb.service failed.
Any help in this regard will be appreciated.

It turns out that Mongo>2.6.3 has a known issue with start:
Support Systemd (cannot start mongodb with init scripts with Fedora 15 or above)
As noted here: in this link and it seems that this possibly won't be fully fixed for >2.6.3 until Ubuntu 16.04, unless there is a strong outcry.
So the solution is to issue:
sudo apt-get install --reinstall mongodb
This reverted back to mongo 2.6.3 and NOW ALL WORKS! For those that run across this...

You need to change the path configuration of the db:
for example in the file "/etc/mongod.conf" set "dbPath: /data/db"
You need to give the right to mongodb user to access this path:
sudo chown -R mongodb /data/db

The above solution works for me too:
> sudo apt-get install --reinstall mongodb
I've tried several methods that I found in this site and other sites, but only this one works for me! So, for now, back to Mongodb 2.6.3!
Update: problem fixed (2015/8/2 14:39):
I just found out that MongoDB 3.0.5 is released, so I purged version 2.6.3 and tried to install 3.0.5 on my Ubuntu 15.04. But the problem remains! However, after I reintalled it with the Debian wheezy package instead, finally the sudo service mongod start command works (it didn't work when I install 3.0.4 debian wheezy version). Now the new MongoDB 3.0.5 is running fine on my Ubuntu 15.04!
To install Debian wheezy version, please refer to the official installation guide on MongoDB:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-debian/

i saw /var/log/mongodb/mongodb.log and it need to move authentication 2.6 schema to 3.0.5 schema and i just removed journal and all DBs in /var/lib/mongodb/ then restart the service and it worked again.
2016-01-17T14:43:08.529+0200 I CONTROL [initandlisten] allocator: tcmalloc
2016-01-17T14:43:08.529+0200 I CONTROL [initandlisten] options: { command: [ "run" ], config: "/etc/mongodb.conf", net: { bindIp: "127.0.0.1,10.0.0.170", http: { enabled: false }, port: 27017 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongodb.pid" }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", path: "/var/log/mongodb/mongodb.log", quiet: true } }
2016-01-17T14:43:08.834+0200 I STORAGE [initandlisten] Old 2.4 style user index identified. The authentication schema needs to be updated by running authSchemaUpgrade on a 2.6 server.

None of the above solution worked for me. There are few kernel level changes in ubuntu 15.04 and they are not going to resolve this issue in current release. Hopefully it will be fixed in next stable release of ubuntu.

It helped me on Ubuntu 16.04:
cd /var/lib
sudo rm -rf ./mongodb
sudo mkdir mongodb
sudo chown -R mongodb mongodb/
sudo service mongodb restart

Related

Mongod does not start (mongod.service: Failed with result 'signal')

After command sudo service mongod start && sudo service mongod status
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: failed (Result: signal) since Wed 2021-08-18 11:58:29 MSK; 4s ago
Docs: https://docs.mongodb.org/manual
Process: 13899 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=killed, signal=ILL)
Main PID: 13899 (code=killed, signal=ILL)
авг 18 11:58:29 400sk systemd[1]: Started MongoDB Database Server.
авг 18 11:58:29 400sk systemd[1]: mongod.service: Main process exited, code=killed, status=4/ILL
авг 18 11:58:29 400sk systemd[1]: mongod.service: Failed with result 'signal'.
Does not write logs in /var/logs
Debian 10, try MongoDB 4.2 and 5.0, Intel(R) Xeon(R) E5540 # 2.53GHz
Installation from official site (https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/)
Signal "ILL" is illegal instruction.
MongoDB 5.0 requires Advanced Vector Extensions, Xeon E5540 does not have them.
For a list of processors that support AVX, see https://en.wikipedia.org/wiki/Advanced_Vector_Extensions#CPUs_with_AVX
Make sure libmkl-dev and lib-avx2 are installed and available on your OS. On Debian 10, these packages are in Nonfree amd64 repository. Add the repo to your /etc/apt/sources.list Enable the repo then do apt-get update followed by:
apt-get install libmkl-dev libmkl-avx2 mongodb-org

Service tomcat8 failed to start by using service tomcat8 start

I'm using Vagrant to deploy to Ubuntu Linux and try to start a tomcat8 service.
Tomcat 8 was installed by apt-get install tomcat8.
When using the service tomcat8 start command, I got the following error:
Job for tomcat8.service failed. See "systemctl status tomcat8.service" and "journalctl -xe" for details.
Then I tracked the systemctl status tomcat8.service, found that:
? tomcat8.service - LSB: Start Tomcat.
Loaded: loaded (/etc/init.d/tomcat8)
Active: failed (Result: exit-code) since Mon 2016-03-28 09:44:17 GMT; 5s ago
Docs: man:systemd-sysv-generator(8)
Process: 884 ExecStop=/etc/init.d/tomcat8 stop (code=exited, status=0/SUCCESS)
Process: 1312 ExecStart=/etc/init.d/tomcat8 start (code=exited, status=1/FAILURE)
Mar 28 09:44:12 vagrant-ubuntu-trusty systemd[1]: Starting LSB: Start Tomcat....
Mar 28 09:44:12 vagrant-ubuntu-trusty tomcat8[1312]: * Starting Tomcat servlet engine tomcat8
Mar 28 09:44:17 vagrant-ubuntu-trusty tomcat8[1312]: ...fail!
Mar 28 09:44:17 vagrant-ubuntu-trusty systemd[1]: tomcat8.service: control process exited, code=exited status=1
Mar 28 09:44:17 vagrant-ubuntu-trusty systemd[1]: Failed to start LSB: Start Tomcat..
Mar 28 09:44:17 vagrant-ubuntu-trusty systemd[1]: Unit tomcat8.service entered failed state.
Mar 28 09:44:17 vagrant-ubuntu-trusty systemd[1]: tomcat8.service failed.
I'm unsure of how to proceed to get my Tomcat 8 service running.
This issue can be caused when the tomcat8 server runs under user tomcat8 and the catalina.out was created by root.
To solve this, delete catalina.out and let tomcat8 recreate it.
This could be related to this bug. Recent versions of Java deprecate the use of endorsed directories and fail if one is specified, but Tomcat8 specifies one even if it doesn't exist. Check the log in /var/log/tomcat8/ as suggested in the comments to your question to see whether this is indeed the source of your problem. If it is, you can either wait for the bug to be fixed or try the updated catalina.sh file suggested in the linked bug report.
What I did to solve the issue :
Process: 1312 ExecStart=/etc/init.d/tomcat8 start (code=exited, status=1/FAILURE)
See tomcat's dependencies
dpkg -s tomcat8-common|grep Depends
and the system java version
javar -version
And try to sort out things with the appropriate java version if things don't match.
If that's not the case, continue :
Never bad to start with
sudo apt-get update
Check eventual running tomcat processes
ps aux | grep java
Test the pid you're going to kill
pgrep -f tomcat
Targeted action
sudo pkill -f tomcat
Start removing by typing sudo apt-get remove tomcat8-tab.
You might find :
tomcat8-common tomcat8-user
Complete remove with ( I don't know which of these below is the most appropriate to run )
sudo apt-get purge tomcat8 or
sudo apt-get --auto-remove purge tomcat8 or just
sudo apt-get remove tomcat8
You can also
sudo apt-get autoremove
Carefully sudo rm -r folders like
/var/lib/tomcat*
/usr/share/tomcat*
/etc/tomcat*
Reboot
sudo systemctl reboot
When back on track install
sudo apt-get install tomcat8
Check how's going
sudo systemctl status tomcat8.service
sudo /usr/share/tomcat8/bin/version.sh
Better ?
Verify your tomcat8 configuration file in /etc/default/tomcat8. See if there are badly configured variables.
For me, this error was caused by the following variables in my configuration file:
-Djava.awt.headless=true -XX:+UseConcMarkSweepGC
JAVA_OPTS="-Djava.awt.headless=true -Xss4m -Xmx2g -XX:+UseConcMarkSweepGC"
I commented and it worked.

Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused

while trying this mongo command in ubuntu
I am getting this error.
ritzysystem#ritzysystem-Satellite-L55-A:~$ mongo
MongoDB shell version: 2.6.1
connecting to: test
2014-10-06T12:59:35.802+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-10-06T12:59:35.802+0530 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
how can I rectify this is anyone had the same problem.
Run the following command :
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart
Connection refused to MongoDB errno 111
MacOS:
rm /usr/local/var/mongodb/mongod.lock
sudo service mongod restart
I had the same problem on Mac OS
Try to run sudo mongod and in a new terminal tab run mongo
thank you everyone I tried running mongo it was not running finally I found there was no space in my hard disc I emptied some of the space and finally re installed it the same installation procedure as followed to install as given in mongodb docs finally restarted the server and it is running.
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu
In my case the error was due to missing /data/db folder which the mongodb uses to store your data. Please type this command $sudo mongod in your terminal. If the error message is something like :
missing data/db folder error
Simply create the folder and you are good to go.
First,
Start MongoDB:
sudo service mongod start
Then, Run:
mongo
Probably you don't have space in your hard drive.
Check it by typing in the promt df -h
Please note that mongo might fail even with 3gb available in the corresponding partition. For details, you might want to check the log: cat /var/log/mongodb/mongod.log
Make sure you have run the MongoDB's Service before you want to connect the console.
run and start the server:
$ sudo mongod
then:
$ mongo
...
>
I had the same problem on my Mac, and I installed mongodb via homebrew. I solve this problem by the homebrew services command.
First start mongodb service:
$ brew services start mongodb
Start mongodb terminal
$ mongo
Stop mongodb service:
$ brew services stop mongodb
Do this:
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart
If you are on Ubuntu 16.04 which you can figure out by runnign this:
lsb_release -a
You need to Create a new file at /lib/systemd/system/mongod.service with the following contents:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
In my case the problem was caused due to an apparent lost of permission over mongodb.lock file. I could solve the problem changing the permission with the following command :
sudo chown mongodb:mongodb /var/lib/mongodb/mongodb.lock
There follows my investigation:
I think except for disk space issuse, you should check the log in /var/log/mongodb to know the details for why mongodb start failed.
cat /var/log/mongodb/mongod.log
2016-06-26T15:26:26.642+0800 I CONTROL [main] ***** SERVER RESTARTED *****
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] MongoDB starting : pid=8130 port=27017 dbpath=/var/lib/mongodb 64-bit host=hadoop-master
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] db version v3.2.7
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] git version: 4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] allocator: tcmalloc
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] modules: none
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] build environment:
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] distmod: ubuntu1404
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] distarch: x86_64
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] target_arch: x86_64
2016-06-26T15:26:26.649+0800 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,192.168.3.10", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2016-06-26T15:26:26.678+0800 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-06-26T15:26:26.678+0800 I - [initandlisten] Fatal Assertion 28578
2016-06-26T15:26:26.678+0800 I - [initandlisten]
***aborting after fassert() failure
So, here I need to rm all the files in the /tmp. That works fine for me.
For mongo v3.6.3+ (or 2019 versions)
rm /var/lib/mongodb/mongod.lock
service mongodb restart
I understand the question is with regards to Ubuntu.
But if you're getting the same error on a Mac and don't want $ sudo mongod running on a separate tab, you can do the following to fix the connection error, if you have Homebrew -
brew services start mongodb
Based on the answer from this thread - Cannot connect to mongodb errno:61 Connection refused
In my case bind_ip was not 127.0.0.1 in /etc/mongodb.conf file so change bind_ip to 127.0.0.1(it may be comma separated values so make sure 127.0.0.1 is one of them) Then restart your system to take effect.
Restart only to the those who are facing
$sudo service mongod restart
Failed to restart mongod.service: Unit mongod.service not found.
Follow this simple steps; (Works on MAC OS too)
Open terminal and run sudo mongod
Open a new terminal tab(Don't close step 1 tab) and run sudo mongo
That's all
is very simple, only delete a file /var/lib/mongodb/mongodb.lock. after only execute: mongo. finished
It is possible that the data directory for mongo specified in /etc/mongod.conf is not a valid path.
Try rechecking the path if it really exists sudo vi /etc/mongod.conf and check dbPath.
Just some thoughts on my case.
If you have changed the dbPath and logPath dirs to your custom values (say /data/mongodb/data, /data/mongodb/log), you must chown them to mongodb user, otherwise, the non-existent /data/db/ dir will be used.
sudo chown -R mongodb:mongodb /data/mongodb/
sudo service mongod restart
I have the same error with you, this is my case:
~# mongod
2018-07-15T05:27:08.265+0000 I JOURNAL [initandlisten] journal dir=/data/db/journal
2018-07-15T05:27:08.265+0000 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
2018-07-15T05:27:08.301+0000 I JOURNAL [durability] Durability thread started
2018-07-15T05:27:08.301+0000 I JOURNAL [journal writer] Journal writer thread started
2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] MongoDB starting : pid=26796 port=27017 dbpath=/data/db 64-bit host=ubuntu-s-2vcpu-4gb-sfo2-01
2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten]
2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten]
2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten]
2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] db version v3.0.6
2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] git version: 1ef45a23a4c5e3480ac919b28afcba3c615488f2
2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] build info: Linux build6.ny.cbi.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
2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] allocator: tcmalloc
2018-07-15T05:27:08.302+0000 I CONTROL [initandlisten] options: {}
2018-07-15T05:27:08.308+0000 I NETWORK [initandlisten] waiting for connections on port 27017
I type mongod to start the server, and I type control + c to exit to shell
then I type mongo and I got
~# mongo
MongoDB shell version: 3.0.6
connecting to: test
2018-07-15T05:05:02.738+0000 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2018-07-15T05:05:02.739+0000 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
As you can see, my error info is same with you.
This is case mongod doesn't start with backend process, when I type control + c I quit mongod.
We can add --fork args to make the process daemon process.
# mongod --logpath /usr/local/mongodb/log.txt --fork
you have to set --logpath if you want to use --fork
then you will success to connect to mongo
I faced the same problem, so please check is there mongodb folder, firstly try to remove that folder
rm -rf /var/lib/mongodb/*
Now try to start mongo and if same problem then its mongodb lock file which prevent to start mongo, so please delete the mongo lock file
rm /var/lib/mongodb/mongod.lock
For forcefully rm -rf /var/lib/mongodb/mongod.lock
service mongodb restart if already in sudo mode
otherwise you need to use like sudo service mongod start
or you can start the server using fork method
mongod --fork --config /etc/mongod.conf
and for watching the same is it forked please check using the below command
ps aux | grep mongo
Mongo 3.*.* - OSX - 2017
From README
RUNNING
Change directory to mongodb-osx-x86_64-3.*.*/bin
To run a single server database:
$ mkdir /data/db
$ ./mongod
Go to new Terminal
$ # The mongo javascript shell connects to localhost and test database
$ # by default -Run the following command in new terminal
$ ./mongo
> help
I solved that simply by entering sudo mongo after mongod command.
I just removed mongo following the instructions here: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ And then I installed again following the instructions in the given link. Everything worked smoothly!
There are changes in mongod.conf file in the latest MongoDB v 3.6.5 +
Here is how I fixed this issue on mac os High Sierra v 10.12.3
Note: I assume that you have installed/upgrade MongoDB using homebrew
mongo --version
MongoDB shell version v3.6.5
git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
OpenSSL version: OpenSSL 1.0.2o 27 Mar 2018
allocator: system modules: none build environment:
distarch: x86_64
target_arch: x86_64
find mongod.conf file
sudo find / -name mongod.conf`
/usr/local/etc/mongod.conf > first result .
open mongod.conf file
sudo vi /usr/local/etc/mongod.conf
edit in the file for remote access under net: section
port: 27017
bindIpAll: true
#bindIp: 127.0.0.1 // comment this out
restart mongodb
if you have installed using brew than
brew services stop mongodb
brew services start mongodb
otherwise, kill the process.
sudo kill -9 <procssID>
Issue was with the connection to the database, it could be due to several reasons.
For me it was low disk space on my server machine, and when mongo tries to connect it refuse because of low disk, check your server machine local storage with du -sh if you have low storage space, check your logs size and take step accordingly, issue may exist because of dbpath contradict in /etc/mongod.conf and server actually running dbpath with mongod
If you are facing such type of issue, please check my answer in the given link below.
https://stackoverflow.com/a/53057695/8247133
For those with Windows. I had the same problem on Windows.
Restarting Mongodb service solves this.
Following are the steps to restart on Windows:
i). Go To "Services" on Windows.
ii). Search for "MongoDB" in the list of services.
iii). Right click "start"/"restart" depending on your status.
iv). After the status turns to "running" check if issue is resolved by running "Mongo" or connecting your Mongo client.
For macOS many of the answers are already outdated according to official docs. Somehow the brew has changed and how we should install MongoDB, firstly uninstall it from your macOS (even though it might be not necessary) and then install it using these steps:
brew tap mongodb/brew
brew install mongodb-community#4.4
brew services start mongodb-community#4.4
Watch out for the 4.4 part, it'll change. If in the future it would break then refer to the official docs and install the version, which is suggested in the linked tutorial.

MongoDB service not running in Fedora

Just installed a clean version of mongodb on Fedora 17 64-bit, but the Mongo service wont run.
I followed these instructions during installation
Running
service mongod start
results in
Starting mongod (via systemctl): Job failed. See system journal and 'systemctl status' for details. [FAILED]
So I ran
systemctl status mongod.service
which gives me
mongod.service - SYSV: Mongo is a scalable, document-oriented database.
Loaded: loaded (/etc/rc.d/init.d/mongod)
Active: failed (Result: exit-code) since Mon, 18 Jun 2012 13:15:56 +0200; 58s ago
Process: 13584 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=1/FAILURE)
CGroup: name=systemd:/system/mongod.service
Mongo logs in /var/log/mongo/mongod.log is empty
Thanks
How to install mongodb and mongodb-server on fedora linux (verified on f16 & f17). All commands are intended to be run in a su session.
1) make sure you have no mongodb installation lying around
# yum erase mongodb
# yum erase mongo-10gen (if it is installed)
2) install from fedora yum repository
# yum --disablerepo=* --enablerepo=fedora,updates install mongodb mongodb-server
3) start mongod (mongodb daemon)
# systemctl start mongod.service
4) verify mongod is running
# systemctl status mongod.service
# tail /var/log/mongodb/mongodb.log
# nmap -p27017 localhost
or running client
# mongo
MongoDB shell version: 2.0.2
connecting to: test
> db.test.save( { a: 1 } )
> db.test.find()
{ "_id" : ObjectId("4fdf28f09d16204d66082fa3"), "a" : 1 }
5) customize configuration
# vim /etc/mongodb.conf
# systemctl restart mongod.service
6) make mongodb service automatically start at boot
# systemctl enable mongod.service
Update for Fedora 18
When started for the first time by systemd on a slow or loaded machine, mongod service might timeout before finishing its initialization, with systemd flagging the service as failed.
Symptoms:
# journalctl -xn
-- Unit mongod.service has begun starting up.
10:38:43 local mongod[24558]: forked process: 24560
10:38:43 local mongod[24558]: all output going to: /var/log/mongodb/mongodb.log
10:40:13 local systemd[1]: mongod.service operation timed out. Terminating.
10:40:13 local systemd[1]: Failed to start High-performance, schema-free document-oriented database.
-- Subject: Unit mongod.service has failed
Very easy cure, restart the service:
# systemctl restart mongod.service
this should finish the initialization successfully and leave the daemon in running state.
I just had the same issue and in my case it was caused by installing mongodb following instructions of some websites using non-official repo. If you have the same issue and the answer above are not solving your problem, try uninstalling "mongodb-org" package and reinstalling it following the instructions of the official documentation : https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
Remainder to uninstall package in fedora:
sudo dnf remove <package-name>

couldn't connect to server 127.0.0.1 shell/mongo.js

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

Resources