简体   繁体   中英

How to access mongodb remotely in linux

I have successfully installed mongodb into my linux machine.

Please suggest how to access it remotely.

I worked on it and searched for it.

Finally came up with following solution.

Step 1 — Importing the Public Key

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

Step 2 — Creating a List File

echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

sudo apt-get update

Step 3 — Installing and Verifying MongoDB

sudo apt-get install -y mongodb-org

service mongod status

Step 4 - Creating a user

use admin 

db.createUser({user:"<username>", pwd:"<password>", roles:[{role:"root", db:"admin"}]})

Step 5 - Try to Login

mongo -u <username> -p <password> --authenticationDatabase admin

Step 6 - Set vi /etc/mongod.conf

Comment bindIp with #

service mongod restart

Step 7 - allow connections on port 27017, MongoDB default port

ufw allow 27017

ufw status

Step 8 - Enable mongodb authentication on vi /etc/mongod.conf

security: 
      authorization: enabled

Step 9 - To access mongodb remotely the command is:

mongo -u <username> -p <password> <ip-address>:27017/<collection-name>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM