ubuntu install mongodb error :Failed to connect to 127.0.0.1:27017 - mongodb

I use sudo mongod --repair
win#win-VirtualBox:/var/lib/mongodb$sudo mongod --repair
2014-09-02T22:57:35.759+0800 [initandlisten] MongoDB starting : pid=28790 port=27017 dbpath=/data/db 64-bit host=winsome-VirtualBox
2014-09-02T22:57:35.760+0800 [initandlisten] db version v2.6.4
2014-09-02T22:57:35.761+0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-02T22:57:35.761+0800 [initandlisten] build info: Linux build7.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
2014-09-02T22:57:35.762+0800 [initandlisten] allocator: tcmalloc
2014-09-02T22:57:35.762+0800 [initandlisten] options: { repair: true }
2014-09-02T22:57:35.776+0800 [initandlisten] finished checking dbs
2014-09-02T22:57:35.776+0800 [initandlisten] dbexit:
2014-09-02T22:57:35.777+0800 [initandlisten] shutdown: going to close listening sockets...
2014-09-02T22:57:35.777+0800 [initandlisten] shutdown: going to flush diaglog...
2014-09-02T22:57:35.778+0800 [initandlisten] shutdown: going to close sockets...
2014-09-02T22:57:35.778+0800 [initandlisten] shutdown: waiting for fs preallocator...
2014-09-02T22:57:35.779+0800 [initandlisten] shutdown: closing all files...
2014-09-02T22:57:35.779+0800 [initandlisten] closeAllFiles() finished
2014-09-02T22:57:35.780+0800 [initandlisten] shutdown: removing fs lock...
2014-09-02T22:57:35.780+0800 [initandlisten] dbexit: really exiting now
win#win-VirtualBox:/var/lib/mongodb$ sudo service mongod start
mongod start/running, process 28806
But still can't connect to mongodb
win#win-VirtualBox:/var/lib/mongodb$ mongo
MongoDB shell version: 2.6.4
connecting to: test
2014-09-02T22:58:07.395+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-09-02T22:58:07.396+0800 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
Can someone tell me how to fix it ? or how to install mongodb correctly?
Thanks

When you typed in the mongod command, did you also give it a path? This is usually the issue. You don't have to bother with the conf file. simply type
mongod --dbpath="put your path to where you want it to save the working area for your database here!! without these silly quotations marks I may also add!"
example: mongod --dbpath=C:/Users/Kyle-3/Desktop/DEV/dangerzonearea/test/mongodb
That is my path and don't forget if on windows to flip the slashes forward if you copied it from the or it won't work!

Related

Failing to start mongo on a remote machine that I SSH into

I'm having some trouble starting up mongo. I am using it on a remote machine that I SSH into where. The remote machine is where I do everything (nothing is done on my own machine). Should I change the bind_ip from 127.0.0.1 to the remote machine's IP address? But regardless of whether I leave the IP as it is or change it to the IP of my remote machine, I get the same error message below:
melissa#simba:~$ mongo --version
MongoDB shell version: 2.6.11
melissa#simba:~$ sudo service mongod start
mongod start/running, process 10623
melissa#simba:~$ mongo
MongoDB shell version: 2.6.11
connecting to: test
2015-09-24T19:27:55.279+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-09-24T19:27:55.280+0000 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
My remote machine is: Ubuntu 11.10 (GNU/Linux 2.6.35.4-rscloud x86_64) where the user melissa is a sudoer.
And this is the message I get when starting mongod &
melissa#simba:~$ mongod
mongod --help for help and startup options
2015-09-24T19:40:20.706+0000 [initandlisten] MongoDB starting : pid=10656 port=27017 dbpath=/data/db 64-bit host=simba
2015-09-24T19:40:20.707+0000 [initandlisten] db version v2.6.11
2015-09-24T19:40:20.707+0000 [initandlisten] git version: d00c1735675c457f75a12d530bee85421f0c5548
2015-09-24T19:40:20.707+0000 [initandlisten] build info: Linux build4.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
2015-09-24T19:40:20.707+0000 [initandlisten] allocator: tcmalloc
2015-09-24T19:40:20.707+0000 [initandlisten] options: {}
2015-09-24T19:40:20.746+0000 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2015-09-24T19:40:20.746+0000 [initandlisten] dbexit:
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: going to close listening sockets...
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: going to flush diaglog...
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: going to close sockets...
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: waiting for fs preallocator...
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: lock for final commit...
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: final commit...
2015-09-24T19:40:20.746+0000 [initandlisten] shutdown: closing all files...
2015-09-24T19:40:20.746+0000 [initandlisten] closeAllFiles() finished
2015-09-24T19:40:20.747+0000 [initandlisten] shutdown: removing fs lock...
2015-09-24T19:40:20.747+0000 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
2015-09-24T19:40:20.747+0000 [initandlisten] dbexit: really exiting now
More info:
melissa#simba:~$ ps -edaf | grep mongo
melissa 10748 10555 0 19:45 pts/1 00:00:00 grep --color=auto mongo
melissa#simba:~$ service mongod status
status: Unable to connect to system bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
melissa#simba:~$ sudo service mongod status
mongod stop/waiting
melissa#simba:~$ ps -aux | grep mongo
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
melissa 10786 0.0 0.3 8148 904 pts/1 S+ 19:47 0:00 grep --color=auto mongo
melissa#simba:~$ mongod --shutdown
There doesn't seem to be a server running with dbpath: /data/db
Then I tried to change the permission based on this, but got a new error:
melissa#simba:~/meeth-app$ sudo chown -R `id -u` /data/db
[sudo] password for melissa:
melissa#simba:~/meeth-app$ mongo
MongoDB shell version: 2.6.11
connecting to: test
2015-09-25T01:57:54.966+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-09-25T01:57:54.967+0000 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
melissa#simba:~/meeth-app$ mongod &
[1] 16467
melissa#simba:~/meeth-app$ mongod --help for help and startup options
2015-09-25T01:55:07.366+0000 [initandlisten] MongoDB starting : pid=16467 port=27017 dbpath=/data/db 64-bit host=simba
2015-09-25T01:55:07.366+0000 [initandlisten] db version v2.6.11
2015-09-25T01:55:07.366+0000 [initandlisten] git version: d00c1735675c457f75a12d530bee85421f0c5548
2015-09-25T01:55:07.366+0000 [initandlisten] build info: Linux build4.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
2015-09-25T01:55:07.366+0000 [initandlisten] allocator: tcmalloc
2015-09-25T01:55:07.366+0000 [initandlisten] options: {}
2015-09-25T01:55:07.369+0000 [initandlisten] journal dir=/data/db/journal
2015-09-25T01:55:07.369+0000 [initandlisten] recover : no journal files present, no recovery needed
2015-09-25T01:55:07.370+0000 [initandlisten]
2015-09-25T01:55:07.370+0000 [initandlisten] ERROR: Insufficient free space for journal files
2015-09-25T01:55:07.370+0000 [initandlisten] Please make at least 3379MB available in /data/db/journal or use --smallfiles
2015-09-25T01:55:07.370+0000 [initandlisten]
2015-09-25T01:55:07.370+0000 [initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating
2015-09-25T01:55:07.370+0000 [initandlisten] dbexit:
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: going to close listening sockets...
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: going to flush diaglog...
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: going to close sockets...
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: waiting for fs preallocator...
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: lock for final commit...
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: final commit...
2015-09-25T01:55:07.370+0000 [initandlisten] shutdown: closing all files...
2015-09-25T01:55:07.370+0000 [initandlisten] closeAllFiles() finished
2015-09-25T01:55:07.370+0000 [initandlisten] journalCleanup...
2015-09-25T01:55:07.370+0000 [initandlisten] removeJournalFiles
2015-09-25T01:55:07.371+0000 [initandlisten] shutdown: removing fs lock...
2015-09-25T01:55:07.371+0000 [initandlisten] dbexit: really exiting now
Permission for /data are wrong. Startup cannot write the PID file or likely the db files either. Try
sudo chmod -R mongodb /data
Here is what happened that made mongo work again. Btw, I'm on Ubuntu 11.10.
Change the owner of /data from root to mongodb: sudo chown -R mongodb /data.
Add a line to turn smallfiles on in /etc/mongod.conf: smallfiles = true
Do NOT run mongod & because it's not running from a place with the right permissions, instead do sudo service mongod start and you can open the mongo shell with mongo.
Thanks to r05c03 and oldlaptop from freenode irc #linux for their help.

MongoDB running locally but when trying to access remotely it failed

Able to run MongoDB locally but when trying to access remotely it failed. Havent done any firewall setup. What could be the issue? How to do troubleshoot?
Also the MongoDB status show running
service mongod status
mongod (pid 25342) is running...
But when trying to restart the service it says
service mongod restart
Stopping mongod: [ OK ]
Starting mongod: [FAILED]
But still the process is running
Update
Tried mongod --repair here is the update
2015-01-10T10:46:33.109-0500 [initandlisten] MongoDB starting : pid=29018 port=2 7017 dbpath=/data/db 64-bit host=ns4008927.ip-192-99-3.net
2015-01-10T10:46:33.109-0500 [initandlisten] db version v2.6.6
2015-01-10T10:46:33.109-0500 [initandlisten] git version: 608e8bc319627693b04cc7 da29ecc300a5f45a1f
2015-01-10T10:46:33.109-0500 [initandlisten] build info: Linux build10.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_LI B_VERSION=1_49
2015-01-10T10:46:33.109-0500 [initandlisten] allocator: tcmalloc
2015-01-10T10:46:33.109-0500 [initandlisten] options: { repair: true }
2015-01-10T10:46:33.112-0500 [initandlisten] finished checking dbs
2015-01-10T10:46:33.112-0500 [initandlisten] dbexit:
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: going to close listening sockets...
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: going to flush diaglog...
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: going to close sockets...
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: waiting for fs preallocat or...
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: closing all files...
2015-01-10T10:46:33.112-0500 [initandlisten] closeAllFiles() finished
2015-01-10T10:46:33.112-0500 [initandlisten] shutdown: removing fs lock...
2015-01-10T10:46:33.112-0500 [initandlisten] dbexit: really exiting now
You need to remove this line from mongo's config file (on Ubuntu, mine is at /etc/mongod.conf):
bind_ip = 127.0.0.1
Or, if it's YAML,
bindIp: 127.0.0.1
Source: http://docs.mongodb.org/manual/reference/configuration-options/
"Changed in version 2.6.0: The deb and rpm packages include a default configuration file that sets net.bindIp to 127.0.0.1."
The default value for bindIp/bind_ip is "all interfaces" - so that's where the deletion comes in handy.

sudo service mongod start failed on RHEL system

I have followed the instructions on MongoDB's website to install MongoDB on RHEL systems. Whenever I use the command sudo service mongod start I get the message Starting mongod: [FAILED]. Does anyone know what I am doing wrong? I already changed the permissions to the /var/lib/mongo and /var/log/mongodb directories.
In addition, this is what my log file reads for the last time I tried to start mongoDB
2014-11-28T16:52:42.532-0600 ***** SERVER RESTARTED *****
2014-11-28T16:52:42.535-0600 [initandlisten] MongoDB starting : pid=2846 port=27017 dbpath=/var/lib/mongo$
2014-11-28T16:52:42.535-0600 [initandlisten] db version v2.6.5
2014-11-28T16:52:42.535-0600 [initandlisten] git version: e99d4fcb4279c0279796f237aa92fe3b64560bf6
2014-11-28T16:52:42.535-0600 [initandlisten] build info: Linux build8.nj1.10gen.cc 2.6.32-431.3.1.el6.x86$
2014-11-28T16:52:42.535-0600 [initandlisten] allocator: tcmalloc
2014-11-28T16:52:42.535-0600 [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0$
2014-11-28T16:52:42.535-0600 [initandlisten] exception in initAndListen: 10310 Unable to lock file: /var/$
2014-11-28T16:52:42.535-0600 [initandlisten] dbexit:
2014-11-28T16:52:42.535-0600 [initandlisten] shutdown: going to close listening sockets...
2014-11-28T16:52:42.535-0600 [initandlisten] shutdown: going to flush diaglog...
2014-11-28T16:52:42.535-0600 [initandlisten] shutdown: going to close sockets...
2014-11-28T16:52:42.535-0600 [initandlisten] shutdown: waiting for fs preallocator...
2014-11-28T16:52:42.535-0600 [initandlisten] shutdown: lock for final commit...
2014-11-28T16:52:42.535-0600 [initandlisten] shutdown: final commit...
2014-11-28T16:52:42.536-0600 [initandlisten] shutdown: closing all files...
2014-11-28T16:52:42.536-0600 [initandlisten] closeAllFiles() finished
2014-11-28T16:52:42.536-0600 [initandlisten] dbexit: really exiting now
that looks very similar to the output when you have a mongo already running.
probably you have a startup script installed in /etc/init.d/mongod
Your log file is clipped. Please include an unclipped version where we can see the entire line. From what's there, mongod couldn't lock something, which likely means you already have a mongod running in that directory or the permissions aren't set to allow mongod to take the lock.

MongoDB won't start as service [duplicate]

This question already has answers here:
unable to start mongodb local server
(25 answers)
Closed 8 years ago.
I recently installed mongodb on a Centos Dedicated Server. When i try to start mongodb as a service it is give me the following error.
Starting mongod: [FAILED]
When i just execute mongod this is what i receive.
2014-10-27T03:54:46.184+0100 [initandlisten] MongoDB starting : pid=2566 port=27017 dbpath=/data/db 64-bit host=sv.redswitches.com
2014-10-27T03:54:46.184+0100 [initandlisten] db version v2.6.5
2014-10-27T03:54:46.184+0100 [initandlisten] git version: e99d4fcb4279c0279796f237aa92fe3b64560bf6
2014-10-27T03:54:46.184+0100 [initandlisten] build info: Linux build8.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
2014-10-27T03:54:46.184+0100 [initandlisten] allocator: tcmalloc
2014-10-27T03:54:46.184+0100 [initandlisten] options: {}
2014-10-27T03:54:46.195+0100 [initandlisten] journal dir=/data/db/journal
2014-10-27T03:54:46.196+0100 [initandlisten] recover : no journal files present, no recovery needed
2014-10-27T03:54:46.233+0100 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2014-10-27T03:54:46.233+0100 [initandlisten] ERROR: addr already in use
2014-10-27T03:54:46.234+0100 [initandlisten] now exiting
2014-10-27T03:54:46.234+0100 [initandlisten] dbexit:
2014-10-27T03:54:46.234+0100 [initandlisten] shutdown: going to close listening sockets...
2014-10-27T03:54:46.234+0100 [initandlisten] shutdown: going to flush diaglog...
2014-10-27T03:54:46.234+0100 [initandlisten] shutdown: going to close sockets...
2014-10-27T03:54:46.234+0100 [initandlisten] shutdown: waiting for fs preallocator...
2014-10-27T03:54:46.234+0100 [initandlisten] shutdown: lock for final commit...
2014-10-27T03:54:46.234+0100 [initandlisten] shutdown: final commit...
2014-10-27T03:54:46.244+0100 [initandlisten] shutdown: closing all files...
2014-10-27T03:54:46.244+0100 [initandlisten] closeAllFiles() finished
2014-10-27T03:54:46.244+0100 [initandlisten] journalCleanup...
2014-10-27T03:54:46.244+0100 [initandlisten] removeJournalFiles
2014-10-27T03:54:46.254+0100 [initandlisten] shutdown: removing fs lock...
2014-10-27T03:54:46.254+0100 [initandlisten] dbexit: really exiting now
I have already tried to re-install it twice still nothing. I also have cPanel installed on this server.
Appears it is already running:
ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2014-10-27T03:54:46.233+0100 [initandlisten] ERROR: addr already in use
Another process is already using that port which is most likely another Mongo instance. Try running
mongo
from your command line prompt to see if you can connect using the MongoDB shell utility. Alternatively try
sudo netstat -tlnp | grep 27017
and see which process is using port 27017. On my system it's mongo:
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 25480/mongod

mongodb suddenly stopped to work

I've had mongo running for a while on my dev server running Centos 6.5 and mongo 2.6.4.
But then I needed to install mysql for a different project and now suddenly mongo doesn't work.
I tried to re-install it and upgrade it to 2.6.5 at the same time. I've tried to start it and restart it:
# sudo service mongod restart
Stopping mongod: [FAILED]
Starting mongod: [FAILED]
Repairing it said I missed /data/db which I then created. The repair responds like this:
# sudo mongod --repair
2014-10-24T15:52:14.710-0400 [initandlisten] MongoDB starting : pid=1182 port=27017 dbpath=/data/db 64-bit host=myhost
2014-10-24T15:52:14.710-0400 [initandlisten] db version v2.6.5
2014-10-24T15:52:14.710-0400 [initandlisten] git version: e99d4fcb4279c0279796f237aa92fe3b64560bf6
2014-10-24T15:52:14.710-0400 [initandlisten] build info: Linux build8.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
2014-10-24T15:52:14.710-0400 [initandlisten] allocator: tcmalloc
2014-10-24T15:52:14.710-0400 [initandlisten] options: { repair: true }
2014-10-24T15:52:14.726-0400 [initandlisten] repairDatabase local
2014-10-24T15:52:14.726-0400 [initandlisten] allocating new ns file /data/db/_tmp_repairDatabase_0/local.ns, filling with zeroes...
2014-10-24T15:52:14.843-0400 [FileAllocator] allocating new datafile /data/db/_tmp_repairDatabase_0/local.0, filling with zeroes...
2014-10-24T15:52:14.843-0400 [FileAllocator] creating directory /data/db/_tmp_repairDatabase_0/_tmp
2014-10-24T15:52:14.879-0400 [FileAllocator] done allocating datafile /data/db/_tmp_repairDatabase_0/local.0, size: 64MB, took 0.017 secs
2014-10-24T15:52:14.897-0400 [initandlisten] finished checking dbs
2014-10-24T15:52:14.897-0400 [initandlisten] dbexit:
2014-10-24T15:52:14.897-0400 [initandlisten] shutdown: going to close listening sockets...
2014-10-24T15:52:14.897-0400 [initandlisten] shutdown: going to flush diaglog...
2014-10-24T15:52:14.897-0400 [initandlisten] shutdown: going to close sockets...
2014-10-24T15:52:14.897-0400 [initandlisten] shutdown: waiting for fs preallocator...
2014-10-24T15:52:14.897-0400 [initandlisten] shutdown: closing all files...
2014-10-24T15:52:14.897-0400 [initandlisten] closeAllFiles() finished
2014-10-24T15:52:14.897-0400 [initandlisten] shutdown: removing fs lock...
2014-10-24T15:52:14.897-0400 [initandlisten] dbexit: really exiting now
Starting it again, and fails.
did this:
#semanage port -a -t mongodb_port_t -p tcp 27017
Killed
Trying to enter the mongo shell responds with this:
# mongo
MongoDB shell version: 2.6.5
connecting to: test
2014-10-24T15:59:40.243-0400 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-10-24T15:59:40.244-0400 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
I'm out of ideas. Any suggestions?