Linux/Python学习论坛-京峰教育

 找回密码
 立即注册

一键登录:

搜索
热搜: 活动 交友 discuz
查看: 2147|回复: 0

Mongodb设置密码与登陆

[复制链接]

238

主题

288

帖子

1925

积分

超级版主

Rank: 8Rank: 8

积分
1925
QQ
发表于 2015-3-18 13:04:43 | 显示全部楼层 |阅读模式
添加一个用户, 在admin数据库添加的是管理员, 在其它数据库的是dbuser
[root@slaver1 ~]# mongo
MongoDB shell version: 2.6.1
connecting to: test
Server has startup warnings:
2014-08-06T12:06:04.293+0800 [initandlisten]
2014-08-06T12:06:04.293+0800 [initandlisten] ** WARNING: You are running on a NUMA machine.
2014-08-06T12:06:04.294+0800 [initandlisten] **          We suggest launching mongod like this to avoid performance problems:
2014-08-06T12:06:04.294+0800 [initandlisten] **              numactl --interleave=all mongod [other options]
2014-08-06T12:06:04.294+0800 [initandlisten]
> use admin
switched to db admin
> db.addUser("cc", "BvsKPbZzvaGdk")
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: { "user" : "cc", "roles" : [ "root" ] }
>
bye
[root@slaver1 ~]# ▊




使用管理员账号登陆认证
[root@slaver1 ~]# ps -ef | grep mongo
root     13208     1 12 Aug04 ?        05:00:45 mongod --dbpath /var/data/shard/ --port 10000 --fork --logpath /var/data/logs/shard.log --logappend
root     13223     1  0 Aug04 ?        00:16:29 mongod --dbpath /var/data/config --port 20000 --fork --logpath /var/data/logs/mongo_config.log --logappend
root     19303     1  0 12:06 ?        00:00:00 mongod --dbpath ccdb --port 27017 --fork --logpath /var/data/logs/ccmongo.log --logappend
root     19325 19261  0 12:06 pts/0    00:00:00 grep mongo
[root@slaver1 ~]# kill 19303
[root@slaver1 ~]# mongod --dbpath ccdb --port 27017 --fork --logpath /var/data/logs/ccmongo.log --logappend --auth
about to fork child process, waiting until server is ready for connections.
forked process: 19329
child process started successfully, parent exiting
[root@slaver1 ~]# mongo
MongoDB shell version: 2.6.1
connecting to: test
Error while trying to show server startup warnings: not authorized on admin to execute command { getLog: "startupWarnings" }
> show dbs
2014-08-06T12:08:43.979+0800 listDatabases failed:{
        "ok" : 0,
        "errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
        "code" : 13
} at src/mongo/shell/mongo.js:47
> use admin
switched to db admin
> db.auth("cc","BvsKPbZzvaGdk")
1
> show dbs;
admin  0.078GB
local  0.078GB
>
bye
[root@slaver1 ~]# ▊

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|京峰教育,只为有梦想的人 ( 京ICP备15013173号 )

GMT+8, 2020-2-23 12:13 , Processed in 0.022580 second(s), 11 queries , Redis On.

快速回复 返回顶部 返回列表