复制集群信息
[root@mongo2 ~]# cat /etc/hosts
10.xx.xx.01 mongo1 member1.mongo.com
10.xx.xx.02 mongo2 member2.mongo.com
10.xx.xx.03 mongo3 member3.mongo.com
----------------------------------------------------------
mongo shell 常用操作
[root@mongo2 ~]# mongo --port 28017
rs0:PRIMARY> show dbs
admin 0.000GB
config 0.000GB
local 0.005GB
test 0.000GB
rs0:PRIMARY> show roles
{
"role" : "__queryableBackup",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "__system",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "backup",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "clusterAdmin",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "clusterManager",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "clusterMonitor",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "dbAdmin",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "dbAdminAnyDatabase",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "dbOwner",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "enableSharding",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "hostManager",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "read",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "readAnyDatabase",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "readWrite",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "readWriteAnyDatabase",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "restore",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "root",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "userAdmin",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
{
"role" : "userAdminAnyDatabase",
"db" : "admin",
"isBuiltin" : true,
"roles" : [ ],
"inheritedRoles" : [ ]
}
rs0:PRIMARY> show users
{
"_id" : "admin.adminUser",
"userId" : UUID("aa541ec9-8ef7-4dfc-ad31-7f32fc7ca256"),
"user" : "adminUser",
"db" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
],
"mechanisms" : [
"SCRAM-SHA-1",
"SCRAM-SHA-256"
]
}
rs0:PRIMARY> db.system.users.find().pretty()
{
"_id" : "admin.adminUser",
"userId" : UUID("aa541ec9-8ef7-4dfc-ad31-7f32fc7ca256"),
"user" : "adminUser",
"db" : "admin",
"credentials" : {
"SCRAM-SHA-1" : {
"iterationCount" : 10000,
"salt" : "9a5X76YmW/xqQwTxlb8ZEw==",
"storedKey" : "WMK+BO4mBnCSzjmQao+yoWPEg9U=",
"serverKey" : "x1JTfD/zza8y2JeGR8PMG48946A="
},
"SCRAM-SHA-256" : {
"iterationCount" : 15000,
"salt" : "80OxkOW8hlnoBMQzUFuzJgWU7E0zR+PrnZf+/A==",
"storedKey" : "WBo+djeM/rug1CJ7LgBufhSKQX4SbzzLahsZhaTYrLw=",
"serverKey" : "W51vHZ7xgmWLXFFKcN9J5Zs7V3mEduufpSLMZElRmi0="
}
},
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
rs0:PRIMARY> db.dropUser("adminUser", {w: "majority", wtimeout: 5000})
rs0:PRIMARY> db.system.users.find().pretty()
rs0:PRIMARY> db.isMaster()
rs0:PRIMARY> db.serverStatus()
rs0:PRIMARY> db.serverStatus().connections
{ "current" : 12, "available" : 807, "totalCreated" : 2239, "active" : 2 }
rs0:PRIMARY> db.createUser({user: "adminUser",pwd: "admin123",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})
Successfully added user: {
"user" : "adminUser",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
rs0:PRIMARY> db.version()
4.2.6
rs0:PRIMARY> use test
rs0:PRIMARY> show tables
rs0:PRIMARY> db.test.find()
rs0:PRIMARY> exit
-----------------------------------------
常见监控性能
[root@mongo2 ~]# cd /root/mongodb-linux-x86_64-rhel70-4.2.6/bin/
[root@mongo2 bin]# mongostat --port 28017
[root@mongo2 bin]# mongotop --port 28017
-----------------------------------------
mongo shell 常用操作
最新推荐文章于 2022-11-04 11:40:04 发布