2016.10.13 mongo故障小结

简介:

一、tokumx 2.4 用户管理操作

  db.isMaster()

  use admin

  db.addUser("root","rootpwd")   默认为管理员用户

  db.auth("root","rootpwd")        验证用户

   db.system.users.find()                 查看用户

    db.system.users.update({"user":"zayhuroot"},{"$set":{"roles":["userAdminAnyDatabase","dbAdminAnyDatabase","clusterAdmin"]}})  更新用户的roles

   db.system.users.find()

   db.system.users.remove({"user":"root"})  删除指定用户


二、mongodb3.2 管理用户操作方法总结:

db.addUser()          Deprecated. Adds a user to a database, and allows administrators to configure the user’s privileges.

db.changeUserPassword()      Changes an existing user’s password.

db.createUser()        Creates a new user.

db.dropAllUsers()    Deletes all users associated with a database.

db.dropUser()           Removes a single user.

db.getUser()             Returns information about the specified user.

db.getUsers()           Returns information about all users associated with a database.

db.grantRolesToUser()      Grants a role and its privileges to a user.

db.removeUser()      Deprecated. Removes a user from a database.

db.revokeRolesFromUser()     Removes a role from a user.

db.updateUser()        Updates user data.

db.grantRolesToUser( "myuser" , [ { role: "dbOwner", db: "mydb" } ])

db.system.users.find() 


三、在mongo 3.2上创建集群时遇到的一些问题

配置文件略...

zayhurs2:PRIMARY> rs.initiate()

zayhurs2:PRIMARY> rs.add("mongo04-mb:27027")

1
2
3
4
5
6
7
8
9
10
2016-10-12T17:15:03.927+0800 E QUERY    [thread1] Error: count failed: {
"ok"  : 0,
"errmsg"  "not authorized on local to execute command { count: \"system.replset\", query: {}, fields: {} }" ,
"code"  : 13
} :
_getErrorWithCode@src /mongo/shell/utils .js:25:13
DBQuery.prototype.count@src /mongo/shell/query .js:370:11
DBCollection.prototype.count@src /mongo/shell/collection .js:1713:12
rs.add@src /mongo/shell/utils .js:1143:1
@(shell):1:1

zayhurs2:PRIMARY> admin.createUser(

... {

... user: "root",

... pwd: "rootpwd",

... roles: [

... { role: "userAdminAnyDatabase", db: "admin" },

... { role: "clusterAdmin", db: "admin" },

... { role: "root", db: "admin" }

... ]

... }

... )

zayhurs2:PRIMARY> show dbs

1
2
3
4
5
6
7
8
9
10
2016-10-12T17:21:35.797+0800 E QUERY    [thread1] Error: listDatabases failed:{
"ok"  : 0,
"errmsg"  "not authorized on admin to execute command { listDatabases: 1.0 }" ,
"code"  : 13
} :
_getErrorWithCode@src /mongo/shell/utils .js:25:13
Mongo.prototype.getDBs@src /mongo/shell/mongo .js:62:1
shellHelper.show@src /mongo/shell/utils .js:761:19
shellHelper@src /mongo/shell/utils .js:651:15
@(shellhelp2):1:1

zayhurs2:PRIMARY> db.getSiblingDB("admin").auth("root","rootpwd")

1

zayhurs2:PRIMARY> show dbs

admin  0.000GB

local  0.000GB

zayhurs2:PRIMARY> rs.add("mongo04-mb:27027")

{ "ok" : 1 }

zayhurs2:PRIMARY> rs.status()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{
"set"  "zayhurs2" ,
"date"  : ISODate( "2016-10-12T09:22:53.435Z" ),
"myState"  : 1,
"term"  : NumberLong(1),
"heartbeatIntervalMillis"  : NumberLong(2000),
"members"  : [
{
"_id"  : 0,
"name"  "mongo03-mb:27027" ,
"health"  : 1,
"state"  : 1,
"stateStr"  "PRIMARY" ,
"uptime"  : 1095,
"optime"  : {
"ts"  : Timestamp(1476264168, 1),
"t"  : NumberLong(1)
},
"optimeDate"  : ISODate( "2016-10-12T09:22:48Z" ),
"electionTime"  : Timestamp(1476263343, 2),
"electionDate"  : ISODate( "2016-10-12T09:09:03Z" ),
"configVersion"  : 2,
"self"  true
},
{
"_id"  : 1,
"name"  "mongo04-mb:27027" ,
"health"  : 1,
"state"  : 2,
"stateStr"  "SECONDARY" ,
"uptime"  : 5,
"optime"  : {
"ts"  : Timestamp(1476264168, 1),
"t"  : NumberLong(1)
},
"optimeDate"  : ISODate( "2016-10-12T09:22:48Z" ),
"lastHeartbeat"  : ISODate( "2016-10-12T09:22:52.243Z" ),
"lastHeartbeatRecv"  : ISODate( "2016-10-12T09:22:50.301Z" ),
"pingMs"  : NumberLong(0),
"configVersion"  : 2
}
],
"ok"  : 1
}

zayhurs2:PRIMARY>

zayhurs2:PRIMARY> use news

switched to db news

zayhurs2:PRIMARY> db.createUser(

... { user:"news",pwd:"newspwd",

... roles:[ {role:"readWrite",db:"news"},

... {role:"dbAdmin",db:"News"} ]

... })

zayhurs2:PRIMARY> db.getUsers()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[
{
"_id"  "news.news" ,
"user"  "news" ,
"db"  "news" ,
"roles"  : [
{
"role"  "readWrite" ,
"db"  "news"
},
{
"role"  "dbAdmin" ,
"db"  "News"
}
]
}
]

zayhurs2:PRIMARY> db.updateUser("news",

... {

...   roles:[

...     { "role" : "readWrite","db" : "news" },

...     { "role" : "dbAdmin","db" : "news" }

...   ]

...  }

... )

zayhurs2:PRIMARY> db.getUsers()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[
{
"_id"  "news.news" ,
"user"  "news" ,
"db"  "news" ,
"roles"  : [
{
"role"  "readWrite" ,
"db"  "news"
},
{
"role"  "dbAdmin" ,
"db"  "news"
}
]
}
]

zayhurs2:PRIMARY> db.dropUser("news")

true

zayhurs2:PRIMARY> db.dropDatabase()

{ "ok" : 1 }











本文转自 meteor_hy 51CTO博客,原文链接:http://blog.51cto.com/caiyuanji/1861591,如需转载请自行联系原作者
目录
相关文章
|
存储 NoSQL
MongoDB无法启动,如何恢复数据?
近日有 MongoDB 用户遇到一个问题,使用 Wiredtiger 存储引擎的 MongoDB 无法启动,咨询我数据能否恢复回来,能恢复多少是多少 ... 问题出现的场景据用户描述是「mongod磁盘写满了,导致进程 crash」,尝试重新启动,结果 wiredtiger 报错,错误信息类似如下,类似的问题 mongodb jira 上也有人提过,可以参考 SERVER-26924,说明此时 MongoDB 数据文件已经损坏。
|
NoSQL 算法 容灾
『MongoDB』MongoDB高可用部署架构——复制集篇(Replica Set)
读完这篇文章里你能收获到 1. MongoDB是如何通过复制集实现高可用的 2. 主节点宕机后如何通过选举做到故障恢复 3. 在复制集中常见的可调整参数有哪些 4. 在Linux原生环境搭建MongoDB复制集 5. 在Winodws环境搭建MongoDB复制集
775 1
『MongoDB』MongoDB高可用部署架构——复制集篇(Replica Set)
|
运维 NoSQL MongoDB
(2)MongoDB副本集自动故障转移原理(含客户端)
前文我们搭建MongoDB三成员副本集,了解集群基本特性,今天我们围绕下图聊一聊背后的细节。
(2)MongoDB副本集自动故障转移原理(含客户端)
|
监控 安全 关系型数据库
|
数据库 安全 NoSQL
mongo数据库单节点搭建
mongo数据库单节点搭建
1223 0
|
监控 NoSQL
MongoDB副本集--管理命令
这篇文档主要介绍MongoDB副本集的日常查看和管理的命令. 1)命令行的查看命令:db.serverCmdLineOpts() 点击(此处)折叠或打开 arps:SECONDARY> db.
1051 0