报错:
Failed with exception java.io.IOException:java.io.IOException: com.mongodb.MongoQueryException: Query failed with error code 13 and error message 'not authorized on config to execute command { find: "shards", filter: { _id: "shard3" }, $db: "config", $clusterTime: { clusterTime: Timestamp(1523976947, 82), signature: { hash: BinData(0, F7C01D37922251A3F06742233682D804A0D03735), keyId: 6515979220739424275 } }, lsid: { id: UUID("19e4658e-86d3-4dbf-b3e2-e26f75fafc7b") } }' on server 192.168.9.12:20000
分析:
mongodb 集群模式是 sharding + Replicate Set 模式,之前是没用开启用户认证的,而且hive 服务之前的抽数一直正常,最近把集群的重启开启认证后,hive 服务抽数一直失败。
mongodb 在没有开启认证中心的时候,任何登陆都拥有最高的权限,对任何库都拥有读写操作权限。开启认证后,用户只拥有之前建立用户时所分配的权限,hive 服务在抽数过程中会读取 mongodb 集群 的config 库的信息,mongodb 单机模式是没有config 这个库的。所以mongodb 集群模式在分配hive 抽数用户时,要分配config库的读取权限
解决:
1、重新添加用户,指定risk、config库读取权限
mongos> db.createUser({user:"xxx",pwd:"riskRead",roles:[{"role":"read","db":"riskion"},{"role":"read","db":"config"}]})
Successfully added user: {
"user" : "xxx",
"roles" : [
{
"role" : "read",
"db" : "riskion"
},
{
"role" : "read",
"db" : "config"
}
]
}
2、
利用MongoDB的SplitVector命令实现并发数据迁移,授权给该用户
添加角色:
db.createRole({role: "hadoopSplitVector",privileges: [{resource: {db: "riskion",collection: "installmentRiskControlResult"},actions: ["splitVector"]}],roles:[]})
更新用户角色:
> db.updateUser("xxx",{roles: [{role:"read",db:"riskion"},{"role":"read","db":"config"},{role:"hadoopSplitVector", db:"riskion"}]})
数据迁移是数据库运维中一个很常见的场景。数据迁移分为全量和增量。为了追求速度,通常我们会采用并发的方式对数据进行全量迁移。在全量导出数据时,通常都会选择做到记录级的并发,因此通常会涉及到对需要导出的某个表(集合)按照并发度进行切分(分区)的过程。事实上MongoDB还有一个SplitVector命令特别适合用来做集合的分区。
SplitVector命令原是在sharding中chunk分裂时需要用的一个内部命令,是mongos在准备分裂某个chunk前发给这个chunk所在shard以计算分裂点(SplitPoint)时使用的。