changing MongoDB ports

208 views
Skip to first unread message

Raj Rajadurai

unread,
Jun 21, 2016, 5:39:29 PM6/21/16
to mongodb-user
Hi,
I am new to MongoDB and I have a task to change the default ports from 27017 & 27018 to something different.
I tried to change them in mongod.conf & mongodb.conf and also on the mongod.conf on the config servers.

I could bring up the mongod services and also able to login to mongo shell and query.
But the command rs.status() shows the default port not the port which is running as below. 
Any idea, if I missed anything or any other place I have to change or run any command to make the new port?

{
       "set" : "stagerep",
       "date" : ISODate("2016-06-09T08:31:30.151Z"),
       "myState" : 2,
       "members" : [
               {
                       "_id" : 0,
                       "name" : "mongodb-host-cluster1:27017",
                       "health" : 1,
                       "state" : 1,
                       "stateStr" : "PRIMARY",
                       "uptime" : 17,
                       "optime" : Timestamp(1465450298, 2),
                       "optimeDate" : ISODate("2016-06-09T05:31:38Z"),
                       "lastHeartbeat" : ISODate("2016-06-09T08:31:28.411Z"),
                       "lastHeartbeatRecv" : ISODate("2016-06-09T08:31:28.759Z"),
                       "pingMs" : 1,
                       "electionTime" : Timestamp(1465461072, 1),
                       "electionDate" : ISODate("2016-06-09T08:31:12Z"),
                       "configVersion" : 4
               },

Amar

unread,
Jun 29, 2016, 3:28:01 AM6/29/16
to mongodb-user

Hi Raj,

I have a task to change the default ports from 27017 & 27018 to something different. I tried to change them in mongod.conf & mongodb.conf and also on the mongod.conf on the config servers.

Could you clarify on your deployment topology? Config servers implies having a sharded cluster, but you posted the output of rs.status() of a replica set.

If your deployment is a sharded cluster, I would strongly suggest to be careful when manipulating the contents of the config servers manually. The config servers are vital to the operation of a sharded cluster, and their loss could render your cluster inoperable.

However, if your deployment is a replica set, it’s not enough to only change the parameters of mongod process to change the ports. The replica set configuration in rs.conf() should be changed as well to reflect the new settings. You can find the procedure in Change Hostnames in a Replica Set.

If you are still having issues with your deployment, could you post:

  • Your MongoDB and your O/S version
  • The contents of config files you modified (i.e. mongod.conf, mongodb.conf, etc…)
  • What you are trying to achieve, and what you have tried so far

Regards,

Amar

Reply all
Reply to author
Forward
0 new messages