标签:http not 更改 erro command err vim anon 认证
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
sudo echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" > /etc/apt/sources.list.d/mongodb-org.list
sudo apt-get update
sudo apt-get install -y mongodb-org=3.0.5 mongodb-org-server=3.0.5 mongodb-org-shell=3.0.5 mongodb-org-mongos=3.0.5 mongodb-org-tools=3.0.5
cd /etc/
sudo vim /etc/mongod.conf
bind_ip = 0.0.0.0
port = 27017
auth = true
/etc/init.d/mongod restart
show dbs
如果提示错误信息:
root@shener-XPS-8930:/etc# mongo
MongoDB shell version: 3.0.5
connecting to: test
> show dbs
2018-12-26T12:03:01.524+0800 E QUERY Error: listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
"code" : 13
}
at Error (<anonymous>)
at Mongo.getDBs (src/mongo/shell/mongo.js:47:15)
at shellHelper.show (src/mongo/shell/utils.js:630:33)
at shellHelper (src/mongo/shell/utils.js:524:36)
at (shellhelp2):1:1 at src/mongo/shell/mongo.js:47
执行如下,
use admin
db.auth("admin","admin")
> db.auth("admin","admin")
1
> show dbs
admin 0.078GB
local 0.078GB
use admin
db.createUser(
{
user: "root",
pwd: "123456",
roles: [ { role: "readWrite", db: "admin" } ]
}
)
> db.createUser(
... {
... user: "root",
... pwd: "123456",
... roles: [ { role: "readWrite", db: "admin" } ]
... }
... )
Successfully added user: {
"user" : "root",
"roles" : [
{
"role" : "readWrite",
"db" : "admin"
}
]
}
用户认证
db.auth("root","123456")
> db.auth("root","123456")
1
3.给用户添加读写权限
db.auth("root", "123456")
db.grantRolesToUser("root", [ { role: "readWrite", db: "admin" } ])
apt-get --purge remove mongodb*
标签:http not 更改 erro command err vim anon 认证
原文地址:https://www.cnblogs.com/zgcblog/p/10178974.html