Mongodb won't start - reason: errno:111 Connection refused - node.js

All of a sudden I can't get mongodb to work.
Usually I will start with
mongo
however I get this when trying to start.
MongoDB shell version: 3.0.6
connecting to: test
2016-10-11T15:36:56.462+0100 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-10-11T15:36:56.464+0100 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
exception: connect failed
I haven't updated anything on the server or even logged into it until the website broke. Any ideas why this is happening? I have tried to comment out the bind_ip but I don't get why it would just stop working and failing to start.
I have also tried
sudo service mongo start
mongod start/running, process 1529
Then when I tried -
sudo service mongod status
mongod stop/waiting.
I can't start my nodejs app because it returns
/node_modules/mongoose/node_modules/mongodb/lib/server.js:22‌​8 process.nextTick(function() { throw err; }) ^ Error: connect ECONNREFUSED at exports._errnoException (util.js:746:11) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
I think that is because mongodb isn't starting correctly but not sure.
The error produces this
2016-10-11T15:40:30.400+0100 E JOURNAL [initandlisten] Insufficient free space for journal files
2016-10-11T15:40:30.400+0100 I JOURNAL [initandlisten] Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles
2016-10-11T15:40:30.400+0100 I JOURNAL [initandlisten]
2016-10-11T15:40:30.402+0100 I STORAGE [initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating
2016-10-11T15:40:30.402+0100 I CONTROL [initandlisten] now exiting
2016-10-11T15:40:30.402+0100 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2016-10-11T15:40:30.402+0100 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2016-10-11T15:40:30.402+0100 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2016-10-11T15:40:30.402+0100 I NETWORK [initandlisten] shutdown: going to close sockets...
2016-10-11T15:40:30.402+0100 I STORAGE [initandlisten] shutdown: waiting for fs preallocator...
2016-10-11T15:40:30.402+0100 I STORAGE [initandlisten] shutdown: final commit...
2016-10-11T15:40:30.402+0100 I STORAGE [initandlisten] shutdown: closing all files...
2016-10-11T15:40:30.402+0100 I STORAGE [initandlisten] closeAllFiles() finished
2016-10-11T15:40:30.402+0100 I CONTROL [initandlisten] dbexit: rc: 100
2016-10-11T15:45:36.614+0100 I CONTROL ***** SERVER RESTARTED *****
2016-10-11T15:45:36.642+0100 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-10-11T15:45:36.642+0100 I - [initandlisten] Fatal Assertion 28578
2016-10-11T15:45:36.642+0100 I - [initandlisten]
***aborting after fassert() failure
2016-10-11T15:46:21.636+0100 I CONTROL ***** SERVER RESTARTED *****
2016-10-11T15:46:21.663+0100 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-10-11T15:46:21.663+0100 I - [initandlisten] Fatal Assertion 28578
2016-10-11T15:46:21.663+0100 I - [initandlisten]
I broswed to that dir and saw this!!! Why are those files so huge?

It seems that your error is similar to this
Removing the /tmp/mongodb-27017.sock file should do the trick.
Also check your disk space, as it seems the process is not starting because you are missing space for the journal files (check #dave-v comment below)

i open file /etc/mongodb.conf and put a # in begin of line bind_ip = 127.0.0.1 (#bind_ip = 127.0.0.1) .Then restart mongodb, it's work fine again !
Warning: If you use mongodb in online server, please don't do that. Hacker can attack for this port !

I faced same issue , solution is here
1) Once the mongo installation done by downloading or yum install
2) Create folder db under /home/scc-dev/data/db/
3)Goto mongo folder under bin , open terminal run the below command
sudo ./mongod dbpath /home/scc-dev/data/db
4)Check few lines command running in the console
5)open new terminal under bin run the below command
sudo ./mongo
6) type command -> show dbs (it should show default dbs like local..) then it is working fine
7) if you get error like Failed to connect to 127.0.0.1:27017, reason: errno: 61 Connection refused then
8) restart the linux m/c command - > /sbin/reboot (do the steps from 3 - issue will be resolved )
To open the any ports in linux m/c
sudo iptables -I INPUT -p tcp -m tcp --dport 27017 -j ACCEPT
sudo iptables-save

Related

Impossible to connect to mongo after server shutdown

I am running a mongo cluster (v 3.4.1) on a remote Ubuntu server. This server had an unexpected shutdown yesterday. Since that, I cannot connect to mongo.
I connected by ssh to the server to check if mongo was running. It seems to be the case because if I use the mongo command, I get the following output:
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.1
Server has startup warnings:
2017-09-28T08:01:43.906+0000 I STORAGE [initandlisten]
2017-09-28T08:01:43.906+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-09-28T08:01:43.906+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-09-28T08:01:44.204+0000 I CONTROL [initandlisten]
2017-09-28T08:01:44.204+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-09-28T08:01:44.204+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-09-28T08:01:44.204+0000 I CONTROL [initandlisten]
Now if I run "mongod" I get the exception:
...
2017-09-28T10:10:26.065+0200 I STORAGE [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
2017-09-28T10:10:26.065+0200 I NETWORK [initandlisten] shutdown: going to close listening sockets...
...
I tried in sudo mode, I got:
...
2017-09-28T10:12:21.857+0200 E NETWORK [initandlisten] listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
2017-09-28T10:12:21.857+0200 E NETWORK [initandlisten] addr already in use
2017-09-28T10:12:21.857+0200 E NETWORK [initandlisten] Failed to set up sockets during startup.
2017-09-28T10:12:21.857+0200 E STORAGE [initandlisten] Failed to set up listener: InternalError: Failed to set up sockets
2017-09-28T10:12:21.857+0200 I NETWORK [initandlisten] shutdown: going to close listening sockets...
...
Which would mean that an instance of mongo is already running...
Then I tried to kill mongo process, either with sudo service mongod stop or sudo pkill mongod or sudo kill <PID> after listing processes with ps -ef | grep mongo. But the process does not disappear from the list (seems that it restarts immediately).
So if I try to run sudo mongod --dbpath /data/db --repair (there is a mongod.lock file in the directory), I still get the error "Address already in use".
Any help would be really appreciated!

mongod facing with file permission on linux mint

what is the exact file permission for data/db?
why this problem occurs?
2016-10-18T17:19:28.378+0600 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2016-10-18T17:19:28.378+0600 E NETWORK [initandlisten] addr already in use
2016-10-18T17:19:28.378+0600 E STORAGE [initandlisten] Failed to set up sockets during startup.
2016-10-18T17:19:28.378+0600 I CONTROL [initandlisten] dbexit: rc: 48
Restart your computer and then try again.

aborting after fassert() failure On Mac

I am creating an express app with Nodejs & MongoDB, this is my first time.
When I run this command,
mongod --dbpath SM:NodeTestApp101\data
I am getting this error
015-11-08T08:24:01.771-0700 E NETWORK [initandlisten] Failed to
unlink socket file /tmp/mongodb-27017.sock errno:13 Permission denied
2015-11-08T08:24:01.771-0700 I - [initandlisten] Fatal
Assertion 28578
2015-11-08T08:24:01.771-0700 I - [initandlisten]
***aborting after fassert() failure
I am new with MongoDB and have no idea what it means, I have google it and have had no luck solving this issue.
Is there anyone that can help me with it? I can provide more information if needed, Please just let me know.

nodejs application - mongodb connection fails with error "ECONNREFUSED"

Background Information
I'm playing around with my first nodejs test app that is attempting to connect to a remote mongodb.
Problem:
The connection is failing with the following message:
admin#testdev:~/Documents/nodejs_tests$ sudo nodejs index.js
Server has started.
Request for / received
About to route a request for: /
inside db connect method
Request for /favicon.ico received
About to route a request for: /favicon.ico
inside db connect method
MongoError: connect ECONNREFUSED
null
MongoError: connect ECONNREFUSED
null
Here's the logic to connect:
function connect_nimble() {
console.log("inside db connect method");
MongoClient.connect("mongodb://10.1.1.1:27017/test", function(err,db) {
console.log(err);
console.log(db);
if(!err) {
console.log("booya! Connected to mongo");
return true;
}
});
}
What I've checked so far:
I've made sure that the database server is using port 27017. Here's what I see in the mongodb logs when i restart the database:
admin#mongotest:~$ tail -f /var/log/mongodb/mongod.log
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten]
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] db version v3.0.4
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] git version: 0481c958daeb2969800511e7475dc66986fa9ed5
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] build info: Linux ip-10-45-73-23 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] allocator: tcmalloc
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1" }, storage: { dbPath: "/var/lib/mongodb" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
**2015-07-21T09:52:41.470-0500 I NETWORK [initandlisten] waiting for connections on port 27017**
I've made sure I have a database called "test" by starting "mongo"... and then switching in and out of the test database using the "use test" / "use admin" commands.
I don't believe I have authorization turned on. This is what I have in the mongo.conf file:
# Turn on/off security. Off is currently the default
#noauth = true
#auth = true
And to prove it, in order to get into the test database on the server via command line, I just have to type "mongo" and then by default, I'm in the test database. So I think I can safely assume I don't have any authentication going on.
Just in case, I also checked netstat for the port number:
admin#mongotest:~$ sudo netstat -taupen | grep mongo
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 117 6465150 18792mongod
admin#mongotest:~$
I'm currently reading the manual to see if there's anything else I should be checking. I'm also reading through the various stackoverflow posts that are similar, but I haven't found me an answer yet.
Any suggestions?
I can see in your logs that Mongo is listening on 127.0.0.1. This is likely your problem. You will have to change the bind-ip address configuration setting to allow Mongo to listen to specific or all IP addresses. You can find how to do this here: Cannot connect to mongodb using machine ip
Open a terminal.
Type mongod & and check the stacktrace.
This is an example of a failing start
I STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
I NETWORK [initandlisten] shutdown: going to close listening sockets...
I NETWORK [initandlisten] shutdown: going to flush diaglog...
I CONTROL [initandlisten] now exiting
To fix this, Create the folder /data/db
In the terminal, type mkdir /data/db
Type againmongod
It works !!
[initandlisten] ** WARNING: Access control is not enabled for the database.
I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
I CONTROL [initandlisten]
I CONTROL [initandlisten]
I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000

MEAN.js Could not connect to MongoDB

in creating my app with MEAN.js can not do mongodb connect on port 27017 in any way.
I installed mongodb manually in directory
~$ ls -la /etc/init.d/mongod
output
lrwxrwxrwx 1 root root 56 Nov 4 20:45 /etc/init.d/mongod -> /home/myuser/projects/packages/linux-mongodb/bin/mongod
I try to run the file or `` server.js` grunt` the NASC repository command and got the following error:
Running node server.js i receive this output:
Application loaded using the "development" environment configuration
Failed to load c ++ bson extension, using pure JS version
Insecurely using http protocol
MEAN.JS application started on port 27017
Could not connect to MongoDB!
Error: connection closed
Repository URL:
https://github.com/meanjs/mean
Some hint of what might be?
I look forward personal contact.
Thanks in advance!
Link for reference:
https://stackoverflow.com/a/22557417/3332734
running cat /etc/mongod.conf
# 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
###dbpath=/home/myuser/projects/packages/mongodb-linux/databases
#where to log
logpath=/var/log/mongodb/mongod.log
###logpath=/home/myuser/projects/packages/mongodb-linux/mongod.log
logappend=true
port = 27017
# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip = 127.0.0.1
# Disables write-ahead journaling
# nojournal = true
# Enables periodic logging of CPU utilization and I/O wait
#cpu = true
# Turn on/off security. Off is currently the default
#noauth = true
#auth = true
# Verbose logging output.
#verbose = true
# Inspect all client data for validity on receipt (useful for
# developing drivers)
#objcheck = true
# Enable db quota management
#quota = true
# Set oplogging level where n is
# 0=off (default)
# 1=W
# 2=R
# 3=both
# 7=W+some reads
#diaglog = 0
# Ignore query hints
#nohints = true
# Enable the HTTP interface (Defaults to port 28017).
#httpinterface = true
httpinterface = true
# Turns off server-side scripting. This will result in greatly limited
# functionality
#noscripting = true
# Turns off table scans. Any query that would do a table scan fails.
#notablescan = true
# Disable data file preallocation.
#noprealloc = true
# Specify .ns file size for new databases.
# nssize = <size>
# Replication Options
# in replicated mongo databases, specify the replica set name here
#replSet=setname
# maximum size in megabytes for replication operation log
#oplogSize=1024
# path to a key file storing authentication info for connections
# between replica set members
#keyFile=/path/to/keyfile
Run mongo in console and retrieve output:
$ mongo
MongoDB shell version: 2.6.5
connecting to: test
2014-11-05T19:23:18.957-0200 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-11-05T19:23:18.958-0200 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
Run mongod in console and retrieve output:
$ mongod
mongod --help for help and startup options
2014-11-05T19:26:53.215-0200 [initandlisten] MongoDB starting : pid=3487 port=27017 dbpath=/data/db 64-bit host=francis-tosystems
2014-11-05T19:26:53.215-0200 [initandlisten] db version v2.6.5
2014-11-05T19:26:53.215-0200 [initandlisten] git version: e99d4fcb4279c0279796f237aa92fe3b64560bf6
2014-11-05T19:26:53.215-0200 [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-11-05T19:26:53.215-0200 [initandlisten] allocator: tcmalloc
2014-11-05T19:26:53.215-0200 [initandlisten] options: {}
2014-11-05T19:26:53.215-0200 [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
2014-11-05T19:26:53.215-0200 [initandlisten] dbexit:
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: going to close listening sockets...
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: going to flush diaglog...
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: going to close sockets...
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: waiting for fs preallocator...
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: lock for final commit...
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: final commit...
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: closing all files...
2014-11-05T19:26:53.216-0200 [initandlisten] closeAllFiles() finished
2014-11-05T19:26:53.216-0200 [initandlisten] dbexit: really exiting now
Or run mongod
$ mongod --config /etc/mongod.conf &
[1] 3568 2014-11-05T19:28:16.867-0200 SEVERE: Failed global initialization: FileNotOpen Failed to open "/var/log/mongodb/mongod.log"
EDIT
I am no longer using MEAN.js, but I continue my studies with MongoDB and node.js
The problem was that I did not know how to start mongodb to connect to the database
This year I learned a lot about mongodb and node.js and I understood what I needed to do.
With your help I have three steps:
Open a console with mongod --dbpath /project/path-do-database/
I connected my API to mongodb, passing the right port
Open a second console by starting the node.js API with node ornodemon and passing the project's main javascript file.
Basically, you need to have 2 terminals running at the same folder.
One for mongoDB, one for your application.
On the first terminal,
1>> npm install -g meanjs
1>> yo meanjs
then fill up your application name, author name, etc.
1>> npm install
Open up a 2nd terminal to start the mongodb server
2>> mongod
Go back to the first terminal and run it
1>> npm start
You are starting your meanjs app on the same port as your mongodb server (27017). If you do not specify a port for meanjs, it will start on 3000 in a development environment.
I know it is probably late, but error logs says it all:
ERROR: dbpath (/data/db) does not exist.
I belive you need to create /data/db folders or it was created somewhere else.
It is already answered here:
mongodb Mongod complains that there is no /data/db folder

Resources