Unable to change the default port of mongodb in CentOS server - mongodb

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

Related

unable to connect mongod from remote and local on IP address

My mongod servers runs on IP 67.219.110.71 and default port 27017
Below is the command to start mongod
mongod --dbpath /data/db --fork --logpath /dev/null
After login to the linux server 67.219.110.71 I'm able to telnet successfully like below:
telnet localhost 27017 ----> SUCCESS
However, when I telnet using the IP address it does not connect from the same host 67.219.110.71 or from a remote hots both fail
telnet 67.219.110.71 27017 ----> FAILS
Note:
have restarted the mongod service several times and after any configuration change.
port 27010 was opened on the firewall using firewall-cmd command.
I'm able to connect on ssh port telnet 67.219.110.71 22 ----> SUCCESS
Below is my mongod configuration file /etc/mongod.conf:
# mongod.conf
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,67.219.110.71,0.0.0.0,:: # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
# bindIpAll: true
# bindIp: 0.0.0.0
security:
authorization: "enabled"
Can you please suggest?

MongoDB - Unrecognized Option: clusterRole

I am new to mongodb, this is my second day learning mongodb and trying to setup a sharded cluster.What I did is created virtual boxes of Ubuntu 18.04.1 LTS and installed mongodb version 4.2.8. after installing MongoDB on all of my VMs, I updated the mongod.conf file as follows (to configure Config Servers Replica Set, I connected to one of my VMs. I will be implementing 3 replica sets of Config servers)
net:
port: 27019
bindIP: 0.0.0.0,192.168.1.22,127.0.0.1
replication:
replSetName: rs01
sharding:
clusterRole: configsvr
after that, I restarted mongodb service using this command
sudo systemctl restart mongod
and when I try to connect to mongo shell or run this command
mongod --config /etc/mongod.conf
I get this error "Unrecognized Option: clusterRole". I am following official mongodb documentation on this link https://docs.mongodb.com/manual/tutorial/deploy-shard-cluster/
Any help would be greatly appreciated.
You are missing indentation in the yaml file. Suboptions need to be indented:
net:
port: 27019
bindIP: 0.0.0.0,192.168.1.22,127.0.0.1
replication:
replSetName: rs01
sharding:
clusterRole: configsvr

Why Mongodb config changes not getting applied?

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

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