I have Ubuntu 18.04 VM running on GCP and I have a problem when connecting remote after changing the default port on Mongodb
After the installation on Mongodb I followed a few steps to enable remote access on default port in the file /etc/mongodb.conf changed the bindIP to 0.0.0.0 and open the default port on GCP firewall and I was able to connect to Mongodb.
But I want to change default Mongodb port switch from 27017 to for example: 38018 I changed the port in /etc/mongodb.conf from 27017 to 38018, I've restarted mongo service and open the new port on GCP firewall.
After changing the port I'm able to connect from terminal with the following command
mongo --port 38018 -u "user" -p "pass" --authenticationDatabase "admin"
But when I try to connect from outside on the new port with mongo compass the connection is refused, what I'm missing here?
Also I've checked is it mongo running on the new port with
sudo netstat -tulpn | grep 38018
I get the following message
tcp 0 0 0.0.0.0:38018 0.0.0.0:* LISTEN 6644/mongod
- Ubuntu 18.04.4 LTS
- mongod --version db version v4.2.7
- UFW inactive
Here is my mongo config file
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 38018
bindIp: 0.0.0.0
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
security:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
I execute the following command as @YasBES said
mongod -f your_config_file.conf
and restarted the mongo process, the process was unable to start
After checking the log i found this error Failed to start up WiredTiger under any compatibility version.
And I found the following command to fix the error
sudo chown -R mongodb:mongodb /var/lib/mongodb/
Next I removed 27017 .sock file
sudo rm /tmp/mongodb-27017.sock
and give proper ownership on the newly created file
sudo chown mongodb:mongodb mongodb-38018.sock
after executing those commands the process started successfully when I look at the mongod.log I got those messages
2020-05-28T17:13:06.807+0000 I SHARDING [initandlisten] Marking collection local.startup_log as collection version: <unsharded>
2020-05-28T17:13:06.807+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data'
2020-05-28T17:13:06.811+0000 I SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version: <unsharded>
2020-05-28T17:13:06.812+0000 I SHARDING [LogicalSessionCacheReap] Marking collection config.transactions as collection version: <unsharded>
2020-05-28T17:13:06.812+0000 I NETWORK [listener] Listening on /tmp/mongodb-38018.sock
2020-05-28T17:13:06.812+0000 I NETWORK [listener] Listening on 0.0.0.0
2020-05-28T17:13:06.812+0000 I NETWORK [listener] waiting for connections on port 38018
2020-05-28T17:13:07.003+0000 I SHARDING [ftdc] Marking collection local.oplog.rs as collection version: <unsharded>
Now the process start and it says it's listening on 38018 but still can't connect remotely
2020-05-28T17:13:06.812+0000 I NETWORK [listener] Listening on 0.0.0.0
2020-05-28T17:13:06.812+0000 I NETWORK [listener] waiting for connections on port 38018