Mongodb 设置密码

Mongodb 配置用户密码:

首先创建admin数据库的用户密码

再创建pics的用户名密码

> show databases;
admin	0.203125GB
local	0.078125GB
pics	0.953125GB
test	(empty)
> use admin;
switched to db admin
> db.addUser('pics','xxx');
{
	"_id" : ObjectId("56aadcf700e771cecded4a57"),
	"user" : "pics",
	"readOnly" : false,
	"pwd" : "626c9a7149b1a2708fd5a35a1a7f5fd3"
	
	
重启Mongdodb

在没有加--auth的情况下 可以正常访问admin喜爱默认的两个表。

启用的时候需要加--auth 
 /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf --auth
 
 
redis01:/root# mongo
MongoDB shell version: 2.4.9
connecting to: test
> use admin;
switched to db admin
> show tables;
Thu Apr 21 15:45:19.616 error: {
	"$err" : "not authorized for query on admin.system.namespaces",
	"code" : 16550
} at src/mongo/shell/query.js:128

> use pics;
switched to db pics
> show tables;
Thu Apr 21 15:45:31.008 error: {
	"$err" : "not authorized for query on pics.system.namespaces",
	"code" : 16550
} at src/mongo/shell/query.js:128


进入MongoDB:

redis01:/root# mongo
MongoDB shell version: 2.4.9
connecting to: test
> use admin;
switched to db admin
> show tables;
Thu Apr 21 16:16:03.812 error: {
	"$err" : "not authorized for query on admin.system.namespaces",
	"code" : 16550
} at src/mongo/shell/query.js:128


> db.auth('pics','jh7y,xxx') ;
1
> show tables;
system.indexes
system.users

http://114.55.x.xx:8080/pics/weixin_qrcode_b_YH.jpg


http://192.168.32.34:8080/pics/q.jpg

http://192.168.32.34/pics/20160421151012b4509158cc6e4136a5af52be573f9b6a

nginx-gridfs 配置用户名密码:

   location /pics/ {
                 gridfs 
                  pics 
                  field=filename type=string
                   user=pics
                   pass=jh7y,xxx;
		   mongo 192.168.32.34:27017;
       }

redis01:/root# mongofiles -u "pics" -p "xx" -h 192.168.32.34 list -db pics

转载于:https://www.cnblogs.com/zhaoyangjian724/p/6200147.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值