I have two mongoDBs running on port 27017 and 27018 and now it happened twice, that someone patched the server (Red Hat Enterprise Linux Server release 7.8 Maipo ) and the configuration of mongodb has been lost, so I had to fix it manually by
mongod -port 27017 -config /etc/mongod.conf
mongod -port 27018 -config /etc/mongod_second.conf
Can you tell me who is responsible for that issue, so that this configuration is set automatically?
Do I need to
enable the mongod as a service, so it start up with the right configuration after every patch of the server?
an sudo systemctl enable mongod is not working for me
or
tell the admin who is patching the server to run this mongod -port 27018 - config ... everytime he is restarting the server
Thanks for your help
MongoDB provides installation instructions. Follow them to get the database properly installed. Then edit the configuration file instead of passing arguments when starting mongod.
Related
Normally the answer to question is to set:
bindIp: 127.0.0.1
I have this set in /etc/mongod.conf. Unfortunately I am still allowed access to this database remotely. I have restarted the Mongo service a couple times, to no avail.
Does anyone have an idea as to why my database is still accessible remotely?
I'm using MongoDB version 3.0.9
Remoting in to mongod clients using bindIp = 127.0.0.1 is possible through an SSH tunnel because the shell session is seen as 127.0.0.1.
Enabling bind_ip = 127.0.0.1 should be sufficient. Restart MongoDB server after the changes are done.
References:
http://greenwireit.com/it-tech-support-articles/enable-remote-access-default-mongodb-installation/
https://www.mkyong.com/mongodb/mongodb-allow-remote-access/
http://wptrafficanalyzer.in/blog/enabling-and-disabling-remote-access-to-a-mongodb-server/
Perhaps you must specify the mongodb.conf file when loading your mongod instance. Like so:
mongod --fork --config /etc/mongodb.conf --logpath mongodblogs/mongodb.log --dbpath mongod
This is best variant in security aspect:
su <NOTROOTUSER>
mongod --dbpath data --bind_ip localhost
Create new user on you server then log in.
Root is not recommended for running mongo server.
No suitable servers found (serverselectiontryonce set): [Failed connecting to '127.0.0.1:27107': Connection refused]
I install "jenssegers/mongodb": "^3.0" using composer, but am getting error, i can't connect mongodb.
I got this error when I had mistaken the IP of my machine. I was in VM and used 127.0.0.1, when I needed to use 10.0.2.2, IP of my host machine. Wasted an hour for this. Maybe it saves someone's time...
According to MongoDB documentation
mongod is the primary daemon process for the MongoDB system
According to above mentioned description ,it seems that mongod process is not running on your server and 27017 is default port for mongod instance
Please try executing following command to verify if mongod process is running on server
pgrep mongod
It will return process ID if mongod process is running on server otherwise nothing.
Issue following command in shell to start mongod process
mongod --noauth --dbpath /var/lib/mongodb
I had this error.
I had to restart mongodb to make this work.
I used the command below
sudo service mongod restart
I have mongod 3.0.4 installed. I followed the steps from here. I also want to install mongo 2.6.10 as one of my project uses it. How can I have two versions installed so that I can use either one ?
You can run multiple mongoDB version on the same host as long as these version are not in the same Replica Set as a general rule (which judging by your question will not be a problem).
Deploy 2 installation paths.
Start the application using:
mongod --port 12345
(where 12345 is the port you specified)
To start the exe on a different port.
Default port is 27017 if port not specified in the command.
See http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/
Example:
Deploy:
C:\mongo1\bin\mongod.exe
C:\mongo1\data\
C:\mongo2\bin\mongod.exe
C:\mongo2\data\
Execute:
start /b c:\mongo1\bin\mongod --dbpath "c:\mongo1\data" --port 27017
start /b c:\mongo2\bin\mongod --dbpath "c:\mongo2\data" --port 27050
When connecting using MONGO.exe be sure to specify port to connect to correct instance.
If I try to run mongodb shell with the mongo command alone, I get:
Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
However, if I stipulate localhost's LAN IP address like this:
mongo 10.10.5.90
...it connects fine.
Any clues??
Do you have a bind_ip set in your mongodb.conf (or startup script)? edit for clarity A bind_ip setting limits the IP it will listen on to that IP only.
See the IP Address Binding section: http://www.mongodb.org/display/DOCS/Security+and+Authentication
If not, do you have any firewall rules blocking the localhost access? That would be kind of strange, but I can't think of another reason why it wouldn't work while the LAN IP would work.
This error could also appear if mongodb was not properly shutdown. If you type sudo start mongodb and if it gives a new process id on every execution then your mongodb was not properly shutdown. To resolve this type
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo start mongodb
Just follow all these steps to solve this problem
Step 1: Remove lock file.
sudo rm /var/lib/mongodb/mongod.lock
Step 2: Repair mongodb.
mongod --repair
Step 3: start mongodb.
sudo start mongodb
or
sudo service mongodb start
Step 4: Check status of mongodb.
sudo status mongodb
or
sudo service mongodb status
Step 5: Start mongo console.
mongo
I added localhost along with the ip I had in bind_ip while starting mongo and it solved my problem, for example:
bin/mongod --dbpath data --logpath mongo.log --fork --bind_ip localhost,10.100.1.2
For people using MongoDB Compass on VMWare windows:
C:\Program Files\MongoDB\Server\5.0\bin by default is the Mongo server directory. You can change bindIp and port in mongod.cfg
Also make sure to check if the mongo server service is running:
win + r > services.msc > MongoDB Server (MongoDB) > Rightclick > Start.
Should save some time, hope it helps.
Edit your mongod.conf as follow
bindIp: 0.0.0.0,localhost
It works for me.
I've installed mongodb on Linux(CenOS) server as it's written in docs. But still remote access is impossible (although conecting from mongo shell locally is ok). Can someone provide docs on proper configuring of mongodb?
Thank you in advance!
Source: MongoDb setup config to connect by remote hosts
On ubuntu:
root#debian:$ sudo nano /etc/mongodb.conf
Make sure you have the following lines
bind_ip = 0.0.0.0
port = 27017
root#debian:$ /etc/init.d/mongodb restart
Either running behind a firewall or mongod is bound to localhost only (use --bind-ip option to configure the IP address if necessary).