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相关教程见以下内容:
Linux CentOS 6.5 yum安装MongoDB
Ubuntu 16.04中安装MongoDB3.4数据库系统