From the system shell you can use lsof
or netstat -an
as you mentioned to view what a process is doing in terms of open ports. As an alternative you can run the db.getCmdLineOpts()
command from the mongo
shell. That output will give you all the arguments passed on the command line (argv) to the server and the ones from the config file (parsed) and you can infer the ports mongod
is listening based on that information. Here's an example:
{
"argv" : [
"/usr/bin/mongod",
"--config",
"/etc/mongod.conf",
"--fork"
],
"parsed" : {
"bind_ip" : "127.0.0.1",
"config" : "/etc/mongodb/mongodb.conf",
"dbpath" : "/srv/mongodb",
"fork" : true,
"logappend" : "true",
"logpath" : "/var/log/mongodb/mongod.log",
"quiet" : "true",
"port" : 30001
},
"ok" : 1
}
If you have not passed specific port options like the one above, then the mongod
will be listening on 27017 (normal) and 28017 (http status interface) by default.
Note: there are a couple of other arguments that can alter ports without being explicit, see here:
https://docs.mongodb.org/manual/reference/configuration-options/#sharding.clusterRole
I mention this because your lsof
output also shows port 27018 open, which is the default if you have the shardsvr
option set. Hence, your output suggests that you may have a mongos
on 27017 and a (shard) mongod
on 27018. If you connect to each and run the getCmdLineOpts()
you should be able to figure out how things are configured.
netstat
as root?Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.