Skip to content
Advertisement

How can we check if our mongodb is running on EC2 linux server?

I have installed and started the MongoDB on EC2 Linux instance. How can I verify whether it is running or not?

1 way I got to know how to verify whether it is started or not is:

By checking the contents of the file at /var/log/mongodb/mongod.log for a line reading: [initandlisten] waiting for connections on port which I have not got.

What can be more ways to check?

Advertisement

Answer

You can check whether using a third party tool such as Mongoclient to check if you’re able to connect your database. Or use one of the below methods:

Check processes that are working on:

ps -efl | grep mongo

ps -efl returns a list of processes that are being worked on your system right now, and you can use a pipe and grep to select only processes you wish, in this situation mongo.

This should return something like:

1 S sandsto+  6997  6992  0  80   0 - 193376 -     May22 ?        00:13:27 /bin/mongod --fork --bind_ip 127.0.0.1 --port 6081 --dbpath /var/mongo --logpath /var/log/mongo.log --pidfilepath /var/pid/mongo.pid --auth --nohttpinterface --noprealloc --nopreallocj --smallfiles --replSet ssrs --oplogSize 16
0 S sercan    8857  8827  0  80   0 - 85041 -      May22 ?        00:20:58 mongod --storageEngine=wiredTiger
0 S sercan   29511 29471  2  80   0 - 67236 futex_ 13:41 pts/21   00:00:00 ./mongod --dbpath /home/sercan/mongo_data/
0 S sercan   29547 29529  0  80   0 -  3907 pipe_w 13:41 pts/22   00:00:00 grep --color=auto mongo

You can see there’s a script ./mongod here that’s working right now.

Either you can check ports that are being used by the system with command:

netstat -an | grep 27017

netstat -an returns all the allocated ports currently in the system and if you know your mongodb’s port you can easily grep it from here. And this will return:

unix  2      [ ACC ]     STREAM     LISTENING     4184968  /tmp/mongodb-27017.sock

If you see LISTENING here, it means it’s currently working.

But best way is adding mongodb to a system service manager such as supervisord, therefore you can simply check if your mongod is running with a single command:

sudo supervisorctl status

p.s. supervisor is just an example, there’re a lot of process managers in linux that you can use, even mongodb documents have explanations about them.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement