MongoDB learning issue - mongodb

Greetings I am learning mongodb and have encountered with following issue. I am pretty newbie in all of that and dived to into meanstack development after spending some hours messing with setups, I decided to spend some time learning first before doing something and found great corse of mongodb on their official website, following their lessons I cant start mongo server as it says I have already started it somewhere... :)
Error message:
2015-10-13T21:55:01.900+0200 E NETWORK [initandlisten] listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
2015-10-13T21:55:01.900+0200 E NETWORK [initandlisten] addr already in use
2015-10-13T21:55:01.912+0200 W - [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
2015-10-13T21:55:01.935+0200 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2015-10-13T21:55:01.935+0200 I CONTROL [initandlisten] dbexit: rc: 100
Can you please explain how can I find and remove that one or at least shut it down?

There may be already a mongodb instance running. Check it with below command.
ps -ef | grep 'mongo'
You can shutdown existing mongod instance using: http://docs.mongodb.org/master/tutorial/manage-mongodb-processes/#use-shutdown
mongod --shutdown
If no instance is running then go to the data location and remove the lock file.
cd /data/db/
sudo rm mongod.lock
Note: This is only for learning / local machine. This process might not be suitable for production.

Related

Unable to start mongod with one missing collection wt file

I have a working mongod instance (v3.2.21).
But suddenly it stopped working. When i run mongo command it is throwing me following error:
2019-06-04T13:52:41.725+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
When i checked log its showing:
2019-06-04T13:36:43.388+0000 E STORAGE [initandlisten] WiredTiger (2) [1559655403:388180][8404:0x7fb74e904c80], file:collection-1-1305830686620002691.wt, WT_SESSION.open_cursor: /mnt/volume-fra1-01//collection-1-1305830686620002691.wt: handle-open: open: No such file or directory
2019-06-04T13:36:43.388+0000 E STORAGE [initandlisten] no cursor for uri: table:collection-1-1305830686620002691
2019-06-04T13:36:43.388+0000 F - [initandlisten] Invalid access at address: 0x58
2019-06-04T13:36:43.398+0000 F - [initandlisten] Got signal: 11 (Segmentation fault).
The collection which was earlier there is now missing in data directory
I tried to use --repair but the process gets stop at this collection.
I have looked at various resources but couldn't figure out how to make it working? Is there way so that wiredtiger escape this collection?
MongoD 4.0.3 and newer has better repair facilities as per SERVER-19815.
One thing you can try:
Copy your original dbpath so if the attempt is not successful, you don't clobber your original data
Download the 4.0.3 binaries (or newer, currently the latest is 4.0.10)
mongod --repair using the 4.0.3 binaries to attempt to repair the copied dbpath
If the repair is successful, try to run the 3.2.21 binaries pointing to the repaired dbpath
Please note that this repair attempt is best-effort and there's no guarantee of success. Having an up-to-date backup is still recommended. You might also want to investigate how the dbpath is missing a file to begin with.

MongoDB suddenly missing / data not found

Our MongoDB database in Digital Ocean suddenly went missing. When I run mongod, it says:
MongoDB starting : pid=27161 port=27017 dbpath=/data/db 64-bit host=unifyhub-db
2017-01-07T17:36:06.617+0800 I CONTROL [initandlisten] db version v3.0.11
2017-01-07T17:36:06.617+0800 I CONTROL [initandlisten] git version: 48f8b49dc30cc2485c6c1f3db31b723258fcbf39
2017-01-07T17:36:06.617+0800 I CONTROL [initandlisten] build info: Linux ip-10-65-215-98 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2017-01-07T17:36:06.617+0800 I CONTROL [initandlisten] allocator: tcmalloc
2017-01-07T17:36:06.617+0800 I CONTROL [initandlisten] options: {}
2017-01-07T17:36:06.676+0800 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2017-01-07T17:36:06.677+0800 E NETWORK [initandlisten] addr already in use
2017-01-07T17:36:06.677+0800 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2017-01-07T17:36:06.677+0800 I CONTROL [initandlisten] dbexit: rc: 100
Do you have any idea what happen here? We actually didn't do anything, we just found out that the whole application was not working because the database can't be found.
I think you were hijacked!
according to http://thehackernews.com/2017/01/secure-mongodb-database.html and http://securityaffairs.co/wordpress/55018/cyber-crime/mongodb-hacked.html there is a hacker targeting the opened MongoDB databases, and asks for ransom to return your data back.
I faced the exact same problem as yours. I thought it is something related to digital-ocean but after reading those posts, I checked my server and it is confirmed that it was hijacked.
I opened a mongo shell
mongo;
listed the databases
show dbs;
found a database called READ1 I checked it and found a collection with only one record, a message from the hijacker
use READ1;
show collections; // found a collection called info
db.info.find()
found this document:
{ "_id" : ObjectId("5877674456ae6684507ac017"), "mail" :
"ha******#si*****.org", "text" : "SEND 0.1 BTC TO THIS ADDRESS *****
AND CONTACT THIS EMAIL WITH IP OF YOUR SERVER TO RECOVER YOUR DATABASE
!" }
unfortunately, I didn't check the server since a while and I only keep the last five backups, so I lost my data. But luckily we are still in development mode and we don't have sensitive data.
anyway, I found my Mongodb version (2.4.10 Tokumx distribution) allows remote access by default. I tried the following from my local machine and it is surprisingly connected!!
mongo server-ip:27017/database-name
Finally, I made the following steps to disable the remote access
ps aux | grep mongo //found path of the configuration file (/etc/tokumx.conf)
then as described here, I used vim to append the line bind_ip = 127.0.0.1 to the configuration files
then restarted my tokumx service (mongodb in your case)
sudo service tokumx restart
Now remote access is disabled.
Make sure your config file is loaded by explicitly calling it when running mongod:
mongod --config /etc/mongod.conf
And in your /etc/mongod.conf file make sure you have
bindIp: 127.0.0.1
Now after restarting with this config file, like Ahmed ElBayaa says (I could not comment because of low reputation), try from a remote machine to connect using:
mongo server-ip:27017/
If all is configured correctly this connection should be refused!

Mongodb service not running

I'm working on this automatic drink dispenser and ran into an issue when I downloaded the Mongo 3.0.7 I tried to run it but I keep getting this error:
I got the idea from this website. http://yujiangtham.com/2014/05/30/build-your-very-own-drink-mixing-robot-part-2/
2016-02-02T15:56:42.585-0500 E NETWORK [initandlisten] listen():
bind() failed errno:48 Address already in use for socket:
0.0.0.0:27017
2016-02-02T15:56:42.585-0500 E NETWORK [initandlisten] addr already
in use 2016-02-02T15:56:42.593-0500 W - [initandlisten]
Detected unclean shutdown - /data/db/mongod.lock is not empty.
2016-02-02T15:56:42.593-0500 I STORAGE [initandlisten] exception in
initAndListen: 98 Unable to lock file: /data/db/mongod.lock errno:35
Resource temporarily unavailable. Is a mongod instance already
running?, terminating
2016-02-02T15:56:42.593-0500 I CONTROL [initandlisten] dbexit: rc:
100
I need help on how to run this. The website I'm using as a reference is
http://yujiangtham.com/2014/05/30/build-your-very-own-drink-mixing-robot-part-2/
It is stating that Mongo is already running. If you are certain it is not, then the lock file still exists from a previous unclean shutdown.
ps aux | grep mongo
if that returns nothing, it will mean the lock file still exists. looking at your error, the file is /data/db/mongod.lock
rm /data/db/mongod.lock
Should get rid of it so you'll be able to start the mongo service running again.
Try running pkill mongod to kill the process

Mongodb not working properly : Socket already in use?

I am taking the mongodb university class and having problems getting mongod to work properly. I have been trying for hours to try to get it to work properly, but I keep getting the same error.
When I try to run mongod I am getting this error:
erics-mbp:~ emlandst$ mongod --dbpath data
2015-08-16T18:55:24.186-0400 E NETWORK [initandlisten] listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
2015-08-16T18:55:24.186-0400 E NETWORK [initandlisten] addr already in use
2015-08-16T18:55:24.186-0400 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory data not found., terminating
2015-08-16T18:55:24.186-0400 I CONTROL [initandlisten] dbexit: rc: 100
If I am correct the server is set to run on port 27017 by default and for some reason it is being blocked. I tried the ps waux | grep mongo and then I killed the instance, but still i get the same error.
I am trying to just delete everything so I can start all over, but I have no idea how to do that. I'm sure it is simple I just don't have a lot of experience. Thank you

Mongodb wont start: addr already in use

when I try to start my database, mongodb is logging the following messages:
2014-08-12T08:42:17.522-0300 [initandlisten] journal dir=/www/mongodb/data/journal
2014-08-12T08:42:17.523-0300 [initandlisten] recover : no journal files present, no recovery needed
2014-08-12T08:42:17.564-0300 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
2014-08-12T08:42:17.564-0300 [initandlisten] ERROR: addr already in use
2014-08-12T08:42:17.567-0300 [initandlisten] now exiting
2014-08-12T08:42:17.567-0300 [initandlisten] dbexit:
2014-08-12T08:42:17.567-0300 [initandlisten] shutdown: going to close listening sockets...
And it wont start.
But then I run the next command nothing is returned:
sudo netstat -ltnp | grep 27017
The server was manually shutdown (db.shutdownServer()) and it is a part of a replica set.
I noticed that the mongod.lock is created in the process, but removing it doesnt solve the problem.
So i guess the error message isnt quite right.
I'm using MongoDB shell version: 2.6.1
Anyone knows what could be the problem?
I had same issue.
In my config file in bindIp I had 2 ports specified, and for some reason mongo tried to run both of them simultaneously.
Leave only one and make sure it is in etc/hosts.