mongoDB-3.x启用认证

mongoDB-3.x启用认证
官方文档:

环境:
CentOS6.5 x64
mongoDB-3.2.0

一.创建管理员用户
在启用认证前要先创建制授权用户
use admin
db.createUser(
{
user: "myUserAdmin",
pwd: "abc123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)

二.启用认证
命令行启动时加上 --auth 
配置文件
security:
  authorization: enabled

三.认证用户登录
mongo --host 192.168.192.10 --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"
mongo shell交互式登录
mongoDB-3.x启用认证
注意: 用户是建在mongo内嵌的admin库中,验证时也需指定认证库
说明: 通过mongo shell命令行认证和登录都没问题,但通过第三方gui工具(如robomongo,目前还没适配3.x)可能会报认证失败的错,具体解决方法请参看mongoDB跨平台图形管理工具之robomongo
2015-12-30T18:11:20.019+0800 I ACCESS   [conn7] Failed to authenticate myUserAdmin@admin with mechanism MONGODB-CR: AuthenticationFailed UserNotFound Could not find user myUserAdmin@admin

个人使用来看,mongoboost还是挺不错的
mongoDB-3.x启用认证

mongoDB-3.x启用认证

原文地址:https://www.cnblogs.com/lixuebin/p/10814264.html