Why Mongodb config changes not getting applied? - mongodb

I am running Mongodb on AWS windows instance, I changed my config setting as following:
net:
port: 30000
bindIp: 0.0.0.0
As far as my knowledge, Server should get started on port 30000, it can listen request from other ip as well
However, on restarting mongod, it is still running on localhost and listening to port 27017

I have the same problem with you. What I did is a workaround it. I start the service with specifying the port and ip.
mongod --auth --port 30000 --dbpath /data/db --bind_ip_all

Related

How to set up mongoDB bindIp?

Something wrong happens when I'm trying to setup mongod.conf for connection from remote server.
When I paste my server ip address Mongo doesn't allow connection from it.
# network interfaces
net:
port: 27017
bindIp: 111.111.11.111 #my server ip
When I allow connection from any server, mongo allows to connect from my server.
net:
port: 27017
bindIp: 0.0.0.0
I want to have an access to Mongo from localhost and from my server. I'm trying to paste these ip's both but Mongo allow connection from localhost only.
net:
port: 27017
bindIp: 127.0.0.1 111.111.11.111
What's wrong and how to use bindIp ?
According to documentation the value is a string, i.e. a single value.
Try following:
Use only 111.111.11.111, localhost may work by default anyway.
Try these ones:
net:
port: 27017
bindIp:
- 127.0.0.1
- 111.111.11.111
net:
port: 27017
bindIp: 127.0.0.1,111.111.11.111
net:
port: 27017
bindIp: [127.0.0.1,111.111.11.111]
Otherwise use a firewall, either an external one or the internal firewall of your operating system.
I thought there has to be the IP address of the remote server. It's not right. There can be ip addresses of the network interfaces of the current machine.
Looking for here:
ifconfig -a | grep "inet"

Cannot connect remotely after changing the port -Mongodb

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
After some time of research I came to decision to test the same setup on Azure cloud with the same Mongo version, configuration like on GCP.
After changing the default mongo port from 27017 to 38018 I opened the firewall on Azure with the new 38018 port and the remote connection was established.
This is the moment where I discovered that there is something wrong with the port forwarding on GCP.
I was using GCP and I did a lot of forwardings for other machines and other services but this one was strange.
I tried couple of different types of forwarding with different priorities IP ranges etc.
The one that worked is with logs on, priority 100, ip ranges 0.0.0.0/0 and protocol and ports 38018 tcp/udp.

Unable to change the default port of mongodb in CentOS server

Basically I'm trying to change the default port of mongodb by changing the port in mongod.conf file . Then I'm starting the db by mongod --fork --logpath /var/log/mongod.log command . The db is being started in the background but the problem is it's still running on the port 27017.
mongod.conf:
net:
port: 15031
bindIp: 192.168.1.7
Add the parament mongod -f /etc/mongod.conf to specify the configuration file.
net:
port: 15031
Configuration file is written in YAML
You have to use SPACE characters instead of TAB characters for indentation.
Or pass the --port argument when you start mongod
mongod --port 15031

How to configure new port for mongodb

I am currently using port 27017 for mongodb and everything is working proper. We want to configure new port for security purpose.
Can you help me how we can configure this?
This way,
While startiing mongo pass port argument
mongod --port your desired port
mongod --port 19000
Start Mongo with port:
mongo --port your desired port
mongo --port 19000
2.change the port in the mongodb.config file and pass the config file as input.
port = Ur desired port
Change the /etc/mongod.conf file for persistence
change net: section as
net:
bindIp: 127.0.0.1
port: <The port number you want to listen>
Command line option --port <port> can also be used but will not remain persistent and you need to specify the same every time you start Mongod

Got a error message for the command "mongo --port 27003"

Got errno:61 Connection refused when I type mongo --port 27003 on mac osx terminal
but simply mongo it's working fine
By default mongod runs on 27017 port.
When you type "mongo" it connects to that port and not 27003.
Try this "mongo --port 27017"
If you want to run mongod on a different port
Open : /etc/mongodb.conf
Change
port: 27003
Restart mongod service
sudo service mongod restart