MongoDB 3.4.2 配置 CentOS 6.5 遠程連接


1.新建用戶

db.createUser({user: 'test', pwd: 'myPassword', roles: [{role: 'readWrite', db: 'test_db'}]})

 給 test_db 庫新建一個 test 用戶,該用戶具有讀寫權限

如果沒有庫,先新建庫:

mongo // 進入mongo shell
> use test // 使用 test 庫,如果沒有則新建
> db.createCollection('user') // 在 test 庫中新建一個叫 user 的 collection

 

2.修改mongoDB配置

sudo vim /etc/mongod.conf

注釋下面的 bindIp 那一行:

# network interfaces
net:
  port: 27017
# bindIp: 127.0.0.1  <- comment out this line

取消注釋 security, 下面添加一行如下:

security:
  authorization: 'enabled'

重啟 mongod

sudo service mongod restart

 

3. 防火牆放行 27017 端口

sudo iptables -A INPUT -p tcp --dport 27017 -j ACCEPT

 

4. 最后用遠程client連接即可,如 Robomongo

 

參考:

How to connect to your remote MongoDB server


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM