MongoDB3.X单机及shading cluster集群的权限管理(基于(2)

systemLog: destination: file path: "/home/gaoze/platform/logs/mongodb/shardsvr.log" logAppend: true storage: dbPath: "/home/gaoze/platform/data/shardData" journal: enabled: true setParameter: enableLocalhostAuthBypass: 0 processManagement: fork: true replication: replSetName: "shardsvr1" sharding: clusterRole: "shardsvr" security: keyFile: "/home/gaoze/platform/mongodb-3.4.5/keyfile0" authorization: enabled

  config节点:

systemLog: destination: file path: "/home/gaoze/platform/logs/mongodb/configsvr.log" logAppend: true storage: dbPath: "/home/gaoze/platform/data/configData" journal: enabled: true setParameter: enableLocalhostAuthBypass: 0 processManagement: fork: true replication: replSetName: "configsvr0" sharding: clusterRole: "configsvr" security: keyFile: "/home/gaoze/platform/mongodb-3.4.5/keyfile0" authorization: enabled

  mongos(可以看到,mongos不必指定security.authorization):

systemLog: destination: file path: "/home/gaoze/platform/logs/mongodb/mongos.log" logAppend: true net: bindIp: 192.168.2.48 port: 27017 setParameter: enableLocalhostAuthBypass: 0 processManagement: fork: true sharding: configDB: "configsvr0/192.168.2.48:27019,192.168.2.49:27019" security: keyFile: "/home/cloud/platform/mongodb-3.4.5/keyfile0"

4、验证下的集群使用

  shell登录进去需要进行验证才可以使用集群,简而言之就是:

use admin db.auth("gaoze", "gaolaoban")

  我们在其他库上创建个使用者(在目标库上创建用户!):

use test db.createUser({user: "rw", pwd: "1", roles: [{role: "readWrite", db: "test"}]})

  然后我们在test库上使用新用户来进行操作:

use test db.auth("rw", "1")

  可以试验我们的新用户是可以读写的。

更多MongoDB相关教程见以下内容

MongoDB文档、集合、数据库简介 

MongoDB 3分片部署及故障模拟验证 

Linux CentOS 6.5 yum安装MongoDB 

CentOS 7 yum方式快速安装MongoDB 

MongoDB的查询操作 

在 Azure 虚拟机上快速搭建 MongoDB 集群 

MongoDB复制集原理 

MongoDB 3.4 远程连接认证失败 

Ubuntu 16.04中安装MongoDB3.4数据库系统 

MongoDB权威指南第2版PDF完整带书签目录 下载见

MongoDB 的详细介绍请点这里
MongoDB 的下载地址请点这里

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/207d753560a3c47a18f77c3b5cacac9e.html