创建管理员

use admin

db.createUser(
{
user: “admin”,
pwd: “admin”,
roles: [ { role: “userAdminAnyDatabase”, db: “admin” } ]
}
)
重启MongoDB实例

mongod –auth –port 27017 –dbpath <关联路径>

连接并认证

mongo –port 27017 -u “admin” -p “admin” –authenticationDatabase “admin”

添加额外权限用户

use test
db.createUser(
{
user: “test”,
pwd: “test123”,
roles: [ { role: “readWrite”, db: “test” } ]
}
)

连接并认证
mongo –port 27017 -u “test” -p “test123” –authenticationDatabase “test”
注意:如果是配置文件/etc/mongod.conf 启动的记得 在配置文件中写一行  auth=true #window   security:  authorization: enabled #linux
客户端认证 db.auth(“someAdminUser”, password)

mongodb 添加用户名密码

其他参数:

processManagement.fork: true 以daemon模式启动mongod

net.bindIp: 指定IP,逗号分隔,注释掉的情况下,服务启动在0.0.0.0

systemLog.quiet: true 日志输出使用quiet模式,只输出critical

storage.dbPath: 指定数据的存放位置

replication.replSetName: 副本集的名字

security.authorization: enabled 使用认证

security.keyFile: 使用keyFile

verbosity: 日志开启debug模式,0-5

operationProfiling.slowOpThresholdMs: slowlog设定,默认100

net.http.RESTInterfaceEnabled: rest接口是否有效

net.maxIncomingConnections: 最大连接数,默认65536,不能超过系统设置,# ulimit -n

Comments are closed.

Post Navigation