舒适提示:要看高清无码套图,请使用手机打开并单击图片放大查看。node
1.文档编写目的数据库
本文文档主要讲述如何使用Sentry管理Hive/Impala外部表权限。oop
1.建立测试库及外部表测试
2.建立角色并受权操作系统
3.受权测试3d
4.测试总结code
1.操做系统为CentOS6.5blog
2.CM和CDH版本为5.12.1图片
3.采用root用户操做ip
1.集群运行正常
2.集群已启用Kerberos且正常使用
3.HDFS/Hive/Impala/Hue服务已与Sentry集成
4.Hive用户为超级用户
友情提示:总结是精华。
2.建立测试库及外部表
建立fayson数据库
0: jdbc:hive2://localhost:10000/> create database fayson; INFO : Compiling command(queryId=hive_20170916155353_12e7c551-6a72-4ff3-b581-353c4dbd0fb0): create database fayson INFO : Semantic Analysis Completed … INFO : OK No rows affected (0.232 seconds) 0: jdbc:hive2://localhost:10000/>
2.在fayson库下建立外部表student_hive,建表语句以下
create external table if not exists student_hive( name string, age int, addr string ) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LOCATION '/extwarehouse/student_hive';
向/extwarehouse/student_hive表put数据
[root@ip-172-31-6-148 ~]# hadoop fs -put student.txt /extwarehouse/student_hive [root@ip-172-31-6-148 ~]# hadoop fs -ls /extwarehouse/student_hive Found 1 items -rw-r--r-- 3 hive supergroup 59 2017-09-16 16:05 /extwarehouse/student_hive/student.txt [root@ip-172-31-6-148 ~]#
/extwarehouse/student_hive数据目录不存,在建立外部表时自动生成,且数据目录属主为hive。
0: jdbc:hive2://localhost:10000/> select * from student_hive; ... INFO : OK +--------------------+-------------------+--------------------+--+ | student_hive.name | student_hive.age | student_hive.addr | +--------------------+-------------------+--------------------+--+ | fayson | 23 | guangdong | | zhangsan | 24 | shenzhen | | lisi | 55 | guangzhou | +--------------------+-------------------+--------------------+--+ 3 rows selected (0.216 seconds) 0: jdbc:hive2://localhost:10000/>
3.建立角色并受权
受权fayson用户组拥有fayson库全部权限
create role faysonall; grant all on database fayson to role faysonall; grant role faysonall to group fayson;
4.受权测试
[fayson@ip-172-31-6-148 root]$ beeline Beeline version 1.1.0-cdh5.12.1 by Apache Hive beeline> !connect jdbc:hive2://localhost:10000/;principal=hive/ip-172-31-6-148.fayson.com@FAYSON.COM scan complete in 2ms Connecting to jdbc:hive2://localhost:10000/;principal=hive/ip-172-31-6-148.fayson.com@FAYSON.COM Connected to: Apache Hive (version 1.1.0-cdh5.12.1) Driver: Hive JDBC (version 1.1.0-cdh5.12.1) Transaction isolation: TRANSACTION_REPEATABLE_READ 0: jdbc:hive2://localhost:10000/>
2.切换至fayson数据库对student_hive表操做
能够向表中插入数据
0: jdbc:hive2://localhost:10000/> insert into student_hive values('lisi', 22, 'beijing'); ... INFO : OK No rows affected (22.501 seconds) 0: jdbc:hive2://localhost:10000/>
能够查询表数据
0: jdbc:hive2://localhost:10000/> select * from student_hive; ... INFO : OK +--------------------+-------------------+--------------------+--+ | student_hive.name | student_hive.age | student_hive.addr | +--------------------+-------------------+--------------------+--+ | lisi | 22 | beijing | | fayson | 23 | guangdong | | zhangsan | 24 | shenzhen | | lisi | 55 | guangzhou | +--------------------+-------------------+--------------------+--+ 4 rows selected (0.215 seconds) 0: jdbc:hive2://localhost:10000/>
3.HDFS验证
fayson用户能够浏览student_hive的数据目录,查看数据目录下文件内容,但没有delete和put文件的权限。
[fayson@ip-172-31-6-148 ~]$ hadoop fs -ls /extwarehouse/student_hive Found 2 items -rwxr-xr-x 3 hive supergroup 16 2017-09-16 16:16 /extwarehouse/student_hive/000000_0 -rw-r--r-- 3 hive supergroup 59 2017-09-16 16:05 /extwarehouse/student_hive/student.txt [fayson@ip-172-31-6-148 ~]$ hadoop fs -rmr /extwarehouse/student_hive/student.txt rmr: DEPRECATED: Please use 'rm -r' instead. rmr: Failed to move to trash: hdfs://ip-172-31-6-148.fayson.com:8020/extwarehouse/student_hive/student.txt: Permission denied: user=fayson, access=WRITE, inode="/extwarehouse/student_hive":hive:supergroup:drwxr-xr-x [fayson@ip-172-31-6-148 ~]$ hadoop fs -put student1.txt /extwarehouse/student_hive/ put: Permission denied: user=fayson, access=WRITE, inode="/extwarehouse/student_hive":hive:supergroup:drwxr-xr-x [fayson@ip-172-31-6-148 ~]$
测试总结:
hive建立的外部表,经过Sentry受权后,fayson用户组使用beeline和Hue能对该表进行查询和插入操做。但不能对HDFS和Hue FileBrowser上的数据目录进行新增和删除操做,因为fayson用户无操做数据目录的权限。
5.测试总结
若是这个外部表的目录没有在cm里配置成须要sentry管理的目录,经过Sentry赋权后,是无法作ACL同步的,不建议在生产系统中这样使用。若是你须要管理外部表,那么你就须要按照以前的标准文档来操做。如何使用Sentry管理Hive外部表权限
醉酒鞭名马,少年多浮夸! 岭南浣溪沙,呕吐酒肆下!挚友不愿放,数据玩的花! 舒适提示:要看高清无码套图,请使用手机打开并单击图片放大查看。
推荐关注Hadoop实操,第一时间,分享更多Hadoop干货,欢迎转发和分享。