loading docker container from existing project, mongo will not connect to database Ubuntu 18.04 - mongodb

At first I had a problem where the mongod service stopped working altogether. Thereupon I completely uninstalled mongodb and reinstalled it and followed instructions per this thread: https://askubuntu.com/questions/921753/failed-to-start-mongod-service-unit-mongod-service-not-found
This caused the mongod service to finally start.
In order for it to work, I also had to follow instructions from this thread:
mongo - couldn't connect to server 127.0.0.1:27017
So far this configuration has worked only 1 time and that was after I followed the instructions to remove the .lock file in the mongod directory and then repair mongod.
I also tried to remove the sock file like stated here: MongoDB Failing to Start - ***aborting after fassert() failure
Full project reset
Then I tried just disconnecting the project entirely; close nodemon for backend, exit ng serve on frontend, stop and remove mongo docker container... And tried again. Here is my step-by-step process after everything should have been fixed:
Restart mongod service
sudo service mongod restart
Restart frontend (executed from frontend directory)
ng serve frontend
Restart backend (executed from backend directory)
npx nodemon backend
Restart mongo container (executed from deploy directory, mongo is the docker container name, I'm building it from existing provided deploy script)
sudo docker-compose up -d mongo
sudo docker ps -a # check container was created and is running
Debugging information:
sudo service mongod status
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset:
Active: active (running) since Thu 2020-01-09 11:21:43 CET; 3min 40s ago
Docs: https://docs.mongodb.org/manual
Main PID: 17242 (mongod)
CGroup: /system.slice/mongod.service
└─17242 /usr/bin/mongod --config /etc/mongod.conf
janv. 09 11:21:43 junior-LIFEBOOK-E752 systemd[1]: Started MongoDB Database Server
sudo mongod2020-01-09T11:25:45.983+0100 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] MongoDB starting : pid=17727 port=27017 dbpath=/data/db 64-bit host=junior-LIFEBOOK-E752
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] db version v4.2.2
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1d 10 Sep 2019
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] allocator: tcmalloc
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] modules: none
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] build environment:
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] distmod: ubuntu1804
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] distarch: x86_64
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] target_arch: x86_64
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] options: {}
2020-01-09T11:25:45.987+0100 E STORAGE [initandlisten] Failed to set up listener: SocketException: Address already in use
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] now exiting
2020-01-09T11:25:45.987+0100 I CONTROL [initandlisten] shutting down with code:48
sudo mongo
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("8e813fc2-049c-440d-83ce-0b1d8516c4d0") }
MongoDB server version: 4.2.2
Server has startup warnings:
2020-01-09T11:21:43.352+0100 I STORAGE [initandlisten]
2020-01-09T11:21:43.352+0100 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2020-01-09T11:21:43.352+0100 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten]
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2020-01-09T11:21:44.848+0100 I CONTROL [initandlisten]
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
So something weird is happening here, it doesn't find the database from the project and I have no clue why. As far as I can see, it creates a new database including my system details.
How can I fix this please and connect to the project database? I can't move further until I do.

it's been resolved. First I found out I didn't need to have the mongod service running locally because mongo was already included in the docker container. But actually this wasn't a database issue at all. There were a few things going wrong like there was a proxy but the command had been changed to execute the connection, endpoints were on localhost but weren't supposed to be, and the content I was expecting to see had been hidden by a careless push from another developer. Fun times! But we can move on now. Thanks to the people who tried to help!

Related

Rails Exception Mongo::Error::NoServerAvailable

I want to use MongoDB with my Rails app.
The error is not uncommon but none of the suggestions has worked for me.
I've installed mongodb using homebrew and followed the folowing the steps for same
brew update
brew install mongodb
sudo mkdir -p /data/db
sudo chmod 777 /data/db
brew tap homebrew/services
I use brew services start mongodb to start my mongodb server and get the following response
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] MongoDB starting : pid=39164 port=27017 dbpath=/data/db 64-bit host=C168s-iMac.local
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] db version v3.6.2
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2n 7 Dec 2017
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] allocator: system
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] modules: none
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] build environment:
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] distarch: x86_64
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] target_arch: x86_64
2018-02-08T12:27:59.072+0530 I CONTROL [initandlisten] options: {}
2018-02-08T12:27:59.089+0530 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-02-08T12:27:59.089+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2018-02-08T12:28:01.222+0530 I STORAGE [initandlisten] WiredTiger message [1518073081:222686][39164:0x7fffa9db0340], txn-recover: Main recovery loop: starting at 2/18944
2018-02-08T12:28:01.330+0530 I STORAGE [initandlisten] WiredTiger message [1518073081:330012][39164:0x7fffa9db0340], txn-recover: Recovering log 2 through 3
2018-02-08T12:28:01.442+0530 I STORAGE [initandlisten] WiredTiger message [1518073081:442109][39164:0x7fffa9db0340], txn-recover: Recovering log 3 through 3
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten]
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten]
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten]
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten]
2018-02-08T12:28:02.563+0530 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2018-02-08T12:28:02.572+0530 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2018-02-08T12:28:02.572+0530 I NETWORK [initandlisten] waiting for connections on port 27017
2018-02-08T12:28:09.302+0530 I NETWORK [listener] connection accepted from 127.0.0.1:51073 #1 (1 connection now open)
2018-02-08T12:28:09.302+0530 I NETWORK [conn1] received client metadata from 127.0.0.1:51073 conn: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.6.2" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "17.2.0" } }
Along with this I also start mongo
cd /usr/local/bin
mongod
which starts as expected.
I created my rails app without the ActiveRecord and used mongiod gem. Next i created the config file using rails g mongoid:config and added Mongoid.load! './config/mongoid.yml' in application.rb file so the config file is loaded.
The content for mongoid.yml is
development:
clients:
default:
database: mongo_db_demo_development
hosts:
- localhost:27017
test:
clients:
default:
database: mongo_db_demo_test
hosts:
- localhost:27017
options:
read:
mode: :primary
max_pool_size: 1
I created my scaffold for Person and the model was created as expected using include Mongoid::Document. I went ahead and used the index of person as my root_path.
When i run the rails server, I get the following error
ActionView::Template::Error (No server is available matching preference: # using server_selection_timeout=30 and local_threshold=0.015):
I know its an exception by rails but cant seem to resolve it for hours now.
I referred this tutorial to get started. The weird thing is that I was successful to set up the app in accessing it and the next day it crashed with this error without any changes. I'm able to access the books's new page /books/new but cant seem to save it, hence making it clear that the app is unable to access the database.
I've since uninstalled mongodb twice wondering if the installation has some problem but cant seem to figure out whats wrong.
I understand there are many similar questions but none to resolve my issue. I don't understand what I'm missing and going wrong. Any help is appreciated.
Thanks
Update
I was somehow able to run another project that had active record and mongodb in it. Here is the same. I was successful in saving the data to the post model proving that the mongod and mongo are running and the setup is done correctly. Which means that I'm missing something in my app configuration but yet, I've no clue.

mongodump gives segmentation fault

I have MongoDB v3.2.6 installed on my mac macOs High Sierra v10.13.1 and I am trying to make a backup before I upgrade.
I have an instance of $ mongod running in one window using defaut db location and default port.
It is my local database, it is not protected by a password and does not require ssl conncetions.
I can access my databases find using $ mongo or Robomongo but when I run $ mongodump or $ mongodump --db mydatabase I get the following error
[1] 1815 segmentation fault mongodump
UPDATE: I have tried to run mongostat and now I get the following error :
[1] 2404 bus error mongodump
Here is the log I get when starting the db with $ mongod :
2017-12-25T12:36:26.642+0000 I CONTROL [initandlisten] MongoDB starting : pid=3216 port=27017 dbpath=/data/db 64-bit host=MBP-de-Kevin.home
2017-12-25T12:36:26.643+0000 I CONTROL [initandlisten] db version v3.2.6
2017-12-25T12:36:26.643+0000 I CONTROL [initandlisten] git version: 05552b562c7a0b3143a729aaa0838e558dc49b25
2017-12-25T12:36:26.643+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2m 2 Nov 2017
2017-12-25T12:36:26.643+0000 I CONTROL [initandlisten] allocator: system
2017-12-25T12:36:26.643+0000 I CONTROL [initandlisten] modules: none
2017-12-25T12:36:26.643+0000 I CONTROL [initandlisten] build environment:
2017-12-25T12:36:26.643+0000 I CONTROL [initandlisten] distarch: x86_64
2017-12-25T12:36:26.643+0000 I CONTROL [initandlisten] target_arch: x86_64
2017-12-25T12:36:26.643+0000 I CONTROL [initandlisten] options: {}
2017-12-25T12:36:26.644+0000 I - [initandlisten] Detected data files in /data/db created by the 'mmapv1' storage engine, so setting the active storage engine to 'mmapv1'.
2017-12-25T12:36:26.653+0000 I JOURNAL [initandlisten] journal dir=/data/db/journal
2017-12-25T12:36:26.654+0000 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
2017-12-25T12:36:26.674+0000 I JOURNAL [durability] Durability thread started
2017-12-25T12:36:26.675+0000 I JOURNAL [journal writer] Journal writer thread started
2017-12-25T12:36:26.894+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2017-12-25T12:36:26.894+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2017-12-25T12:36:26.894+0000 I NETWORK [initandlisten] waiting for connections on port 27017
What am I doing wrong and How can I debug?
I was experiencing the same problem. I am on macOS High Sierra 10.13.3. My mongo version was mongodb 3.2.7. I read this in the documentation of mongodump:
MAC OSX SIERRA AND GO 1.6 INCOMPATIBILITY
Users running on Mac OSX Sierra require the 3.2.10 or newer version of mongodump.
I upgraded to mongodb 3.6.2 and I my issue was resolved.
I fixed my error using brew upgrade mongodb. Still dont know what was the issue.
That said it is better to follow one of these guide upgrade mongodb to avoid other issues.

Windows Docker mongo container doesn't work with volume mount

I have the following docker command
docker run -v //c/data:/data/db mongo
and I get the following error response from docker / mongo
MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=8706cbf1b78f
db version v3.4.2
git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
allocator: tcmalloc
modules: none
build environment:
distmod: debian81
distarch: x86_64
target_arch: x86_64
options: {}
wiredtiger_open config: create,cache_size=478M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
WiredTiger error (1) [1489982988:687653][1:0x7fec9df0ccc0], connection: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
Assertion: 28595:1: Operation not permitted src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
exception in initAndListen: 28595 1: Operation not permitted, terminating
shutdown: going to close listening sockets...
removing socket file: /tmp/mongodb-27017.sock
shutdown: going to flush diaglog...
now exiting
shutting down with code:100
now when I remove the volume mongo works but I need to persist my data so I need to mount the volume somehow, just not sure what i am doing wrong at this point.
I do see the files appearing in my folder but not sure why I get the 100 error
To get around this, you can employ a tool like rsync to move the db files into mapped directory while Mongo is running. The underlying bug has to do with latency between the Windows mapped volume and that bind path within the container. Offloading the work to rsync decouples the latency from Mongo's runtime requirements.
Example
Create a basic Dockerfile like this:
FROM mongo:latest
RUN apt-get update && \
apt-get install -y \
rsync
ADD init.sh /init.sh
Where init.sh is:
#!/bin/bash
migrate_db() {
while true
do
rsync -avh /data/db/* /data/mapped-db
sleep 5
done
}
migrate_db &
#Execute a command
mongod --smallfiles --logpath=/dev/null --verbose &
#Wait
wait $!
Then, when launching the container, just start with ./init.sh as your ENTRYPOINT.

MongoError: failed to connect to server [localhost:27017] on first connect

I have paid a membership and downloaded this project. After npm install and node app.js, it returns the following error:
Does anyone know what's wrong?
/Users/Thomas/Desktop/mean-stack-tutorial-01$ node app.js
/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb/lib/server.js:265
process.nextTick(function() { throw err; })
^
MongoError: failed to connect to server [localhost:27017] on first connect
at Pool.<anonymous> (/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb-core/lib/topologies/server.js:325:35)
at emitOne (events.js:96:13)
at Pool.emit (events.js:188:7)
at Connection.<anonymous> (/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb-core/lib/connection/pool.js:270:12)
at Connection.g (events.js:292:16)
at emitTwo (events.js:106:13)
at Connection.emit (events.js:191:7)
at Socket.<anonymous> (/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb-core/lib/connection/connection.js:173:49)
at Socket.g (events.js:292:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1281:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
Edit 1: Following the comments, I just installed mongo via brew, and did brew services start mongodb and then mongo:
/Users/Thomas$ mongo
MongoDB shell version v3.4.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.1
Server has startup warnings:
2017-01-12T19:53:01.868+0800 I CONTROL [initandlisten]
2017-01-12T19:53:01.869+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-01-12T19:53:01.869+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-01-12T19:53:01.869+0800 I CONTROL [initandlisten]
Then I did
/Users/Thomas$ mongod -httpinterface --dbpath /Users/Thomas/Desktop/MongoDB/db
2017-01-12T20:14:05.620+0800 I CONTROL [initandlisten] MongoDB starting : pid=47356 port=27017 dbpath=/Users/Thomas/Desktop/MongoDB/db 64-bit host=Pro.local
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] db version v3.4.1
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2j 26 Sep 2016
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] allocator: system
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] modules: none
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] build environment:
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] distarch: x86_64
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] target_arch: x86_64
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] options: { storage: { dbPath: "/Users/Thomas/Desktop/MongoDB/db" } }
2017-01-12T20:14:05.657+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-01-12T20:14:14.108+0800 I CONTROL [initandlisten]
2017-01-12T20:14:14.108+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-01-12T20:14:14.108+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-01-12T20:14:14.108+0800 I CONTROL [initandlisten]
2017-01-12T20:14:14.108+0800 I CONTROL [initandlisten]
2017-01-12T20:14:14.109+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2017-01-12T20:14:15.390+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/Users/Thomas/Desktop/MongoDB/db/diagnostic.data'
2017-01-12T20:14:16.303+0800 I INDEX [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
2017-01-12T20:14:16.304+0800 I INDEX [initandlisten] building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2017-01-12T20:14:16.406+0800 I INDEX [initandlisten] build index done. scanned 0 total records. 0 secs
2017-01-12T20:14:16.407+0800 I COMMAND [initandlisten] setting featureCompatibilityVersion to 3.4
2017-01-12T20:14:16.407+0800 I NETWORK [thread1] waiting for connections on port 27017
Then in another terminal, I did node app.js, which hangs (and does not print anything). Then I does http://localhost:28017 in a browser, it seems to work:
However, how could I see the website?
Edit 2:
The normal process is
install mongo
brew services start mongodb in a terminal
mongo & (assume we use the default folder /data/db/)
npm start
see e.g., bin/www for the port number, then use localhost:the_port_number in a browser
Update 2020 Feb 24:
It would be wise to stay tuned with it. Here is the link for latest library instruction:
https://docs.mongodb.com/manual/administration/install-community/
You haven't started your monogo database. first install mongo install mongo as per your OS https://docs.mongodb.com/v3.0/tutorial/
then follow instructions mentioned on this site:
https://docs.mongodb.com/v3.0/tutorial/getting-started-with-the-mongo-shell/
cd .
mongod --dbpath "any directory path to start your database "
and then start your node server. It will work fine.
Hope this helps!!
First open another terminal an run command mongod to start your mongoDB
Then again start you node server npm start or if you have "nodemon" then using nodemon
I think now everything will be fine it will show
Mongoose connected to mongodb://localhost/your_database
I had the same issue but it worked fine after restarting the service
service mongod start

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!