1

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?

4
  • Is there firewall with (just) 27017 opening?
    – JJussi
    Apr 20, 2018 at 7:44
  • No.. there is no firewall and ip tables rule. however i dont think it should matter right? if i get it on then i need to worry about the inbound and outbound. And one more thing is that even though i change the port. it is taking 27017 while starting.. dont know why?
    – ajit hegde
    Apr 20, 2018 at 8:52
  • Don't know bitnami, but it looks like that mongod was started with some other config-file than what you changed. However that error message indicate that it still tried to connect 27017 and there was nothing. If you can connect your mongodb server with terminal, you can always check netstat -anp|grep mongo what port mongod uses.
    – JJussi
    Apr 20, 2018 at 9:10
  • @ajit hegde, Could you update your "mongod.conf " file location in linux. Apr 20, 2018 at 20:26

2 Answers 2

0

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

0

I got the answer to this. What I was doing in mongodb.conf was correct but when the default port is changed we need to include --host 127.0.0.1 too in addition to --port which I was missing. silly.

Thank you for the suggestions though.

Regards, Ajit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.