Mongodb – How to change default mongo port on a bitnami instance

mongodbmongodb-3.4

I am running a bitnami instance of mongodb for our pre-production. The default port for mongo is 27017. But for security reasons i want to change it but it is not possible.

I have tried these things:

changes the port in mongodb.conf and restarted the server. It shows the below error:

connecting to: mongodb:///opt/bitnami/mongodb/tmp/mongodb-27017.sock/
2018-04-20T12:55:04.373+0530 W NETWORK [thread1]
Failed to connect to /opt/bitnami/mongodb/tmp/mongodb-27017.sock:0, in(connect), reason: Connection refused
2018-04-20T12:55:04.373+0530 E QUERY [thread1] Error: couldn't connect to server /opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed

I restarted mongod with different port. Still i am not able to do it.

when i switch back to 27017. It comes back to normal.

Any suggestions on how to do it the right way?

Best Answer

I am running a bitnami instance of mongodb for our pre-production. The default port for mongo is 27017. But for security reasons i want to change it but it is not possible.

As you mention error code below

Error: couldn't connect to server /opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:237:13 @(connect):1:6 exception: connect failed

As per your error code location (/opt/bitnami/mongodb/tmp/mongodb-27017.sock) mongod tring to connect with port 27017. May be your mongod.conf data files and log files has not configure properly or may be you don't have a authentication permission of that folder where is mongod.conf .

As Bitnami MongoDB documentation here On Unix, the MongoDB clients can connect to the server using a Unix socket file at

installdir/mongodb/tmp/mongodb.sock

The default port in which MongoDB listens is 27017

The main MongoDB log file is at installdir/mongodb/log/mongodb.log

The MongoDB configuration file is located at installdir/mongodb/mongodb.conf

The official MongoDB documentation has more details about how configure the MongoDB database.

For your further ref here , here and here