Check whether you already have Mongodb process listening on the port
netstat -tulpen | grep 017
or
apt-get install procinfo
socklist - display
//Change authorization setting to disabled if you've enabled in
nano /etc/mongod.conf
//Change authorization setting to disabled if you've enabled in
nano /etc/mongod.conf
sudo service mongod restart
Adding database authorisation (RoboMongo failed from Mongodb 3.0)
Creating a new user
cd /usr/bin/mongo to run mongodb shell
use admin
db.createUser( { user: "admin", pwd: "yourpassword", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } )
use <databasename>
db.createUser( { user: "accountUser", pwd: "password", roles: [ "readWrite", "dbAdmin" ] } ) db.auth("accountUser", "password")
db.getUsers()
db.dropUser(<username>)
//Now enable authorization again and restart the mongodb server
Filter IPTables to allow incoming and outgoing traffic from mongodb server
iptables -L to list the current rules
sudo iptables -L INPUT to see all the input values
sudo iptables -L INPUT to see all the input values
iptables -A OUTPUT -d <ip-address> -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
iptables-save to save the rules
then type reboot to restart your terminal and now you'll be able to acces your mongodb
The first rule allows all incoming traffic from <ip-address> on port 27017, which allows the application server to connect to the mongod instance. The second rule, allows outgoing traffic from the mongod to reach the application server.
Lastest MongoDb package on debian is bind to 127.0.0.1, this address doesn’t allow the connection by remote hosts, to change it u must set bind to 0.0.0.0 for eg
root@debian:/var/www# nano /etc/mongodb.conf
bind_ip = 0.0.0.0
port = 27017
root@debian:/var/www/lithium# /etc/init.d/mongodb restart
Done! Remember to secure the connection by password in production mode.
Binding IP
bindip=<youridaddress> and then run the following command.. make sure that /db0 folder is existed
mongod --dbpath /var/lib/mongodb/ --repairpath /var/lib/mongodb/db0
/var/log/mongodb/mongodb.log to see log file if the service can't be started
rm /var/lib/mongodb/mongod.lock to remove the lock file
mongod --repair to repair the service
sudo service mongod restart
No comments:
Post a Comment