非法入侵 发表于 2017-12-16 09:56:00

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
页: [1]
查看完整版本: MongoDB 3.4.2 配置 CentOS 6.5 远程连接