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:

JavaScript

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:

JavaScript

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:

JavaScript

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:

JavaScript

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:

JavaScript

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