CDH安装SENTRY

1.  背景
虽然在集群上部署了kerberos认证,但是kerberos只是对用户层面进行认证,凡是认证通过的用户都有全量的访问权限,这很不安全,需要进一步对用户的权限进行控制,Sentry 的作用就是这个。

2.  添加Sentry服务
2.1.进入CM首页-->选择集群-->添加服务

2.2.选择Sentry,点击继续

2.3.给Sentry分配主机,继续


2.4.给Sentry指定数据库
此处填写最初搭建CDH的时候,给Sentry预留的数据库名称和用户名密码,点击继续

3.  启动Sentry服务
3.1.准备工作
使用默认的Hive仓库目录,如果启用了Kerberos,需要切换到hdfs用户
将仓库的权限设置为771,所属设置为hive:hive
hdfs dfs -chmod -R 771 /user/hive/warehouse

hdfs dfs -chown -R hive:hive /user/hive/warehouse

在CM中禁用HiveServer2的模拟
Hive-->配置 -->HiveServer2--> 主要 -->取消勾选“HiveServer2 启用模拟”

若配置了MR/YARN,要给Hive向MR/YARN提交任务的权限
MR/YARN-->配置-->范围:TaskTracker/NodeManager-->类别:安全-->最小用户ID为0/允许的系统用户:有hive-->重启YARN

关闭Hive CLI用户接触Hive元数据的渠道
Hive-->配置-->搜proxyuser-->添加三个用户 hive、hue、sentry

 

3.2.给Hive启用Sentry服务
Hive-->配置-->范围:Hive-->类别:主要-->选择Sentry服务-->搜索到启用数据库中的存储通知,打开 -->重启

 

3.3.把Hive添加的Sentry的管理员组里
Sentry-->配置-->范围:Sentry-->类别:主要-->管理组-->保存

 
--------------------- 

在CDH中添加完Sentry服务后,需要更改一下hive配置才能通过beeline访问。 
第一,修改Hive下的HiveServer2配置,如下所示: 

将HiveServer2 Load Balancer中的admin去掉和HiveServer2 启用模拟的√去掉。 
这里的admin是默认的,跟前面配置有关,之前没有去掉直接导致beeline连接不上。更改后如下: 

第二,将Hive服务的Sentry勾上,默认是none 

在YARN的NodeManger在查看“允许的系统用户”项,看到下图所示就不用更改了(默认) 

重启Hive过时服务

紧接着,开启HDFS角色的acl(这里主要控制用户访问的HDFS目录,因为在生产环境中会指定一些目录是该用户可以访问的,而其他一些目录该用户访问不了) 

重启过期HDFS配置: 

然后到Sentry服务下的“管理员组”查看有没有hive/impala/hbase/hue,没有添加上(默认是已经存在) 


紧接着,生成hive.keytab文件 
这里,集群有wlint01、wlnamenode01、wldatanode001~wldatanode018一个20个节点,需要生成的hive的keytab文件最后汇集到hive.keytab一个文件中。 
首先在Kerberos数据库中创建principal:

[wlbd@wlint01 ~]$ sudo kadmin.local -q "addprinc -randkey hive/wlint01@HXDI.COM"
[wlbd@wlint01 ~]$ sudo kadmin.local -q "addprinc -randkey hive/wlnamenode01@HXDI.COM"
[wlbd@wlint01 ~]$ for i in {1..9}; do sudo kadmin.local -q "addprinc -randkey hive/wldatanode00$i@HXDI.COM"; done
[wlbd@wlint01 ~]$ for i in {0..8}; do sudo kadmin.local -q "addprinc -randkey hive/wldatanode01$i@HXDI.COM"; done
1
2
3
4
5
这里用sudo是因为在生产环境下只能用wlbd这个用户,而且要用到sudo这个命令才能启用kadmin.local这个命令。如果你是root用户,不需要加sudo。

然后,在当前目录下生成hive.keytab文件。

[wlbd@wlint01 ~]$ sudo kadmin.local -q "xst -norandkey -k hive.keytab hive/wlint01@HXDI.COM"
[wlbd@wlint01 ~]$ sudo kadmin.local -q "xst -norandkey -k hive.keytab hive/wlnamenode01@HXDI.COM"
[wlbd@wlint01 ~]$ for i in {1..9}; do sudo kadmin.local -q "xst -norandkey -k hive.keytab hive/wldatanode00$i@HXDI.COM"; done
[wlbd@wlint01 ~]$ for i in {0..8}; do sudo kadmin.local -q "xst -norandkey -k hive.keytab hive/wldatanode01$i@HXDI.COM"; done
1
2
3
4
修改hive-site.xml文件

[root@wlint01 ~]# vi /etc/hive/conf/hive-site.xml
1
注意,这里是root权限 
在hive-site.xml后面加入下面几句:

 <property>
    <name>hive.server2.authentication</name>
    <value>kerberos</value>
  </property>
  <property>
    <name>hive.metastore.kerberos.principal</name>
    <value>hive/_HOST@HXDI.COM</value>
  </property>
  <property>
    <name>hive.server2.authentication.kerberos.principal</name>
    <value>hive/_HOST@HXDI.COM</value>
  </property>
  <property>
  <name>hive.metastore.kerberos.keytab.file</name>
  <value>/etc/hive/conf/hive.keytab</value>
  </property>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
最后一句就是你接下来放置hive.keytab的路径。这里需要注意的是当重启hive时,hive的配置文件可能会更改为之前默认情况下,而且/etc/hive/conf/下的hive.keytab也会被删除,需要重启拷贝和重新修改hive-site.xml。所以这里我们选择先修改配置文件再拷贝hive.keytab文件。 
将修改后的hive-site.xml文件scp到各个节点

[root@wlint01 wlbd]# for i in {10..28}; do  scp /etc/hive/conf/hive-site.xml 192.168.32.$i:/etc/hive/conf; done
1
这里的ip地址对应上面的hostname

同样将hive.keytab文件拷贝到每一台主机的/etc/hive/conf目录下。

[root@wlint01 wlbd]# for i in {9..28}; do  scp  hive.keytab 192.168.32.$i:/etc/hive/conf; done
1
修改每个节点keytab权限:

[root@wlint01 wlbd]#for i in {9..28}; do ssh 192.168.32.$i "cd /etc/hive/conf; chmod 400 hive.keytab; chown hive:hadoop hive.keytab"; done
1
2. 权限测试

创建两个系统用户user1和user2

[root@wlint01 wlbd]# useradd user1
[root@wlint01 wlbd]# passwd user1
[root@wlint01 wlbd]# useradd user2
[root@wlint01 wlbd]# passwd user2
1
2
3
4
创建Kerberos用户

[wlbd@wlint01 ~]$ sudo kadmin.local -q "addprinc user1"
[wlbd@wlint01 ~]$ sudo kadmin.local -q "addprinc user2"
1
2
创建数据库和表。这里需要kinit之前生成的hive.keytab,然后进入Hive CLI创建数据库,再通过beeline创建role。 
当前目录下有events.csv文件

[wlbd@wlint01 ~]$ cat events.csv 
10.1.2.3,US,android,createNote
10.200.88.99,FR,windows,updateNote
10.1.2.3,US,android,updateNote
10.200.88.77,FR,ios,createNote
10.1.4.5,US,windows,updateTag
1
2
3
4
5
6
7
[wlbd@wlint01 ~]$ kinit -kt hive.keytab hive/wlint01
1

创建两个数据库

create database db1;
create database db2;
1
2


在数据库中创建表 
在db1中创建table1,在db2中创建table1和table2

create table db1.table1 (
ip STRING, country STRING, client STRING, action STRING
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
create table db2.table1 (
ip STRING, country STRING, client STRING, action STRING
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';
create table db2.table2 (
ip STRING, country STRING, client STRING, action STRING
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';


load data local inpath '/home/wlbd/events.csv' overwrite into table db1.table1;
load data local inpath '/home/wlbd/events.csv' overwrite into table db2.table1;
load data local inpath '/home/wlbd/events.csv' overwrite into table db2.table2;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
赋予用户权限

这里是通过beeline连接进行操作的 
给user1赋予db1的所有权限

 beeline -u "jdbc:hive2://wlint01:10000/;principal=hive/wlint01@HXDI.COM"
1
create role user1_role;
GRANT ALL ON DATABASE db1 TO ROLE user1_role;
GRANT ROLE user1_role TO GROUP user1;
1
2
3

给user2赋予db2的所有权限

create role user2_role;
GRANT ALL ON DATABASE db2 TO ROLE user2_role;
GRANT ROLE user2_role TO GROUP user2;
1
2
3
测试用户权限 
user1用户只具有db1和default的权限

[wlbd@wlint01 ~]$ kinit user1
Password for user1@HXDI.COM: 
[wlbd@wlint01 ~]$ beeline -u "jdbc:hive2://wlint01:10000/;principal=hive/wlint01@HXDI.COM"
scan complete in 2ms
Connecting to jdbc:hive2://wlint01:10000/;principal=hive/wlint01@HXDI.COM
Connected to: Apache Hive (version 1.1.0-cdh5.14.2)
Driver: Hive JDBC (version 1.1.0-cdh5.14.2)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 1.1.0-cdh5.14.2 by Apache Hive
0: jdbc:hive2://wlint01:10000/> show databases;
INFO  : Compiling command(queryId=hive_20180618150404_d26fd5a2-8c54-44d5-9df8-38f362535491): show databases
INFO  : Semantic Analysis Completed
INFO  : Returning Hive schema: Schema(fieldSchemas:[FieldSchema(name:database_name, type:string, comment:from deserializer)], properties:null)
INFO  : Completed compiling command(queryId=hive_20180618150404_d26fd5a2-8c54-44d5-9df8-38f362535491); Time taken: 0.38 seconds
INFO  : Executing command(queryId=hive_20180618150404_d26fd5a2-8c54-44d5-9df8-38f362535491): show databases
INFO  : Starting task [Stage-0:DDL] in serial mode
INFO  : Completed executing command(queryId=hive_20180618150404_d26fd5a2-8c54-44d5-9df8-38f362535491); Time taken: 0.281 seconds
INFO  : OK
+----------------+--+
| database_name  |
+----------------+--+
| db1            |
| default        |
+----------------+--+
2 rows selected (0.884 seconds)
0: jdbc:hive2://wlint01:10000/> 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
user2用户只具有db2和default的权限

[wlbd@wlint01 ~]$ kinit user2
Password for user2@HXDI.COM: 
[wlbd@wlint01 ~]$ beeline -u "jdbc:hive2://wlint01:10000/;principal=hive/wlint01@HXDI.COM"
scan complete in 2ms
Connecting to jdbc:hive2://wlint01:10000/;principal=hive/wlint01@HXDI.COM
Connected to: Apache Hive (version 1.1.0-cdh5.14.2)
Driver: Hive JDBC (version 1.1.0-cdh5.14.2)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 1.1.0-cdh5.14.2 by Apache Hive
0: jdbc:hive2://wlint01:10000/> show databases;
INFO  : Compiling command(queryId=hive_20180618151010_397e7de5-2bd7-4bd7-90d7-bbfabcab48e8): show databases
INFO  : Semantic Analysis Completed
INFO  : Returning Hive schema: Schema(fieldSchemas:[FieldSchema(name:database_name, type:string, comment:from deserializer)], properties:null)
INFO  : Completed compiling command(queryId=hive_20180618151010_397e7de5-2bd7-4bd7-90d7-bbfabcab48e8); Time taken: 0.104 seconds
INFO  : Executing command(queryId=hive_20180618151010_397e7de5-2bd7-4bd7-90d7-bbfabcab48e8): show databases
INFO  : Starting task [Stage-0:DDL] in serial mode
INFO  : Completed executing command(queryId=hive_20180618151010_397e7de5-2bd7-4bd7-90d7-bbfabcab48e8); Time taken: 0.176 seconds
INFO  : OK
+----------------+--+
| database_name  |
+----------------+--+
| db2            |
| default        |
+----------------+--+
2 rows selected (0.418 seconds)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
禁用HIve CLI 

表示hive、hue、hdfs和sentry都能访问CLI,别的用户或组成员访问不了CLI。这样创建一个用户user1,由于user1不在这个列表里面,user1自然访问不了Hive CLI。 


HDFS测试 
配置HDFS ACL与Sentry同步后,HDFS权限与Sentry监控的目录(/user/hive/warehouse)的权限同步

[root@hxmaster ~]# kinit -kt hive.keytab hive/hxmaster
[root@hxmaster ~]# hadoop fs -getfacl -R /user/hive/warehouse/
# file: /user/hive/warehouse
# owner: hive
# group: hive
user::rwx
group::---
user:hive:rwx
group:hive:rwx
mask::rwx
other::--x

# file: /user/hive/warehouse/db1.db
# owner: hive
# group: hive
user::rwx
group::---
user:hive:rwx
group:user1:rwx
group:hive:rwx
mask::rwx
other::--x

# file: /user/hive/warehouse/db1.db/table1
# owner: hive
# group: hive
user::rwx
group::---
user:hive:rwx
group:user1:rwx
group:hive:rwx
mask::rwx
other::--x

# file: /user/hive/warehouse/db1.db/table1/events.csv
# owner: hive
# group: hive
user::rwx
group::---
user:hive:rwx
group:user1:rwx
group:hive:rwx
mask::rwx
other::--x

# file: /user/hive/warehouse/db2.db
# owner: hive
# group: hive
user::rwx
group::---
user:hive:rwx
group:user2:rwx
group:hive:rwx
mask::rwx
other::--x

# file: /user/hive/warehouse/db2.db/table1
# owner: hive
# group: hive
user::rwx
group::---
user:hive:rwx
group:user2:rwx
group:hive:rwx
mask::rwx
other::--x

# file: /user/hive/warehouse/db2.db/table1/events.csv
# owner: hive
# group: hive
user::rwx
group::---
user:hive:rwx
group:user2:rwx
group:hive:rwx
mask::rwx
other::--x

# file: /user/hive/warehouse/db2.db/table2
# owner: hive
# group: hive
user::rwx
group::---
user:hive:rwx
group:user2:rwx
group:hive:rwx
mask::rwx
other::--x

# file: /user/hive/warehouse/db2.db/table2/events.csv
# owner: hive
# group: hive
user::rwx
group::---
user:hive:rwx
group:user2:rwx
group:hive:rwx
mask::rwx
other::--x

# file: /user/hive/warehouse/test_table
# owner: hive
# group: hive
user::rwx
group::---
user:hive:rwx
group:hive:rwx
mask::rwx
other::--x

# file: /user/hive/warehouse/test_table/events.csv
# owner: hive
# group: hive
user::rwx
group::---
user:hive:rwx
group:hive:rwx
mask::rwx
other::--x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
切换到user1用户,查看HDFS文件

[root@hxmaster ~]# kinit user1
Password for user1@ANDREW.COM: 
You have mail in /var/spool/mail/root
[root@hxmaster ~]# hadoop fs -ls /user/hive/warehouse/db1.db
Found 1 items
drwxrwx--x+  - hive hive          0 2018-06-10 20:08 /user/hive/warehouse/db1.db/table1
[root@hxmaster ~]# hadoop fs -cat /user/hive/warehouse/db1.db/table1/events.csv
10.1.2.3,US,android,createNote
10.200.88.99,FR,windows,updateNote
10.1.2.3,US,android,updateNote
10.200.88.77,FR,ios,createNote
10.1.4.5,US,windows,updateTag
You have mail in /var/spool/mail/root
[root@hxmaster ~]# hadoop fs -ls /user/hive/warehouse/db2.db
ls: Permission denied: user=user1, access=READ_EXECUTE, inode="/user/hive/warehouse/db2.db":hive:hive:drwxrwx--x
[root@hxmaster ~]# hadoop fs -cat /user/hive/warehouse/db2.db/table1/events.csv
cat: Permission denied: user=user1, access=READ, inode="/user/hive/warehouse/db2.db/table1/events.csv":hive:hive:-rwxrwx--x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
切换到user2用户,查看HDFS文件

[root@hxmaster ~]# kinit user2
Password for user2@ANDREW.COM: 
[root@hxmaster ~]# hadoop fs -ls /user/hive/warehouse/db1.db
ls: Permission denied: user=user2, access=READ_EXECUTE, inode="/user/hive/warehouse/db1.db":hive:hive:drwxrwx--x
[root@hxmaster ~]# hadoop fs -cat /user/hive/warehouse/db1.db/table1/events.csv
cat: Permission denied: user=user2, access=READ, inode="/user/hive/warehouse/db1.db/table1/events.csv":hive:hive:-rwxrwx--x
[root@hxmaster ~]# hadoop fs -ls /user/hive/warehouse/db2.db
Found 2 items
drwxrwx--x+  - hive hive          0 2018-06-10 20:08 /user/hive/warehouse/db2.db/table1
drwxrwx--x+  - hive hive          0 2018-06-10 20:08 /user/hive/warehouse/db2.db/table2
[root@hxmaster ~]# hadoop fs -cat /user/hive/warehouse/db2.db/table1/events.csv
10.1.2.3,US,android,createNote
10.200.88.99,FR,windows,updateNote
10.1.2.3,US,android,updateNote
10.200.88.77,FR,ios,createNote
10.1.4.5,US,windows,updateTag
[root@hxmaster ~]# hadoop fs -cat /user/hive/warehouse/db2.db/table2/events.csv
10.1.2.3,US,android,createNote
10.200.88.99,FR,windows,updateNote
10.1.2.3,US,android,updateNote
10.200.88.77,FR,ios,createNote
10.1.4.5,US,windows,updateTag
--------------------- 

1.hue集成sentry服务
首先登陆如下界面我的是http://master:7180/cmf/home

然后点击hue组件进入下面的界面,点击配置搜索Sentry将Sentry服务的Sentry勾选上

2. hive和impala启用Sentry和上面的步骤一样这里就不做介绍了
3.对hive和hue做权限控制
首先登陆到hue的界面上来我个人的登陆地址为master:8888
登陆之后默认的账号和密码都是admin
进入如下界面点击图中所示

之后点击增加用户添加一个用户将hue用户加入其中密码自己设置,然后将hue用户放入hue组之中之后以hue用户的身份登入
登陆之后再次以hue的身份创建几个用户并且分配组如下图所示先点击1在点击2,之后再在3的位置分配权限。

                       

 

注意:其中有几点要注意hue组是Sentry的管理组所以创建hue组之后放入其中的hue用户是管理用户所以拥有权限去创建其他用户,而且不仅要保证hue用户存在即如果在之前cdh集成了kerberos的话需要在kerberos中加入hue用户并且还要保证linux用户组中包含hue,以上都可以通用到其他用户身上即假如创建一个用户叫做user那么需要保证linux用户组中包含user,如果cdh集成了kerberos的话还要保证kerberos域中包含此user用户,并且你将user用户放入哪个用户组中就会拥有哪个用户组的权限。

通过以上操作你可以实现hue所创建的用户拥有什么权限的控制比如你可以实现此用户登陆hue之后能看到什么数据,能执行什么从操作从而实现对hive的控制,比如此用户只能实现对表table1实现select的处查询你甚至可以控制他只能查询此数据库中table1表的name字段即实现列级控制。

4.Hbase集成Sentry
首先登陆master:7180
然后点击hbase组件在配置里面搜索auth将以下内容勾选上
                   

在输入dfs将以下内容勾选上
                 

输入superuser加入一个超级用户之后去hbase shell里面创建一个表然后创建一个用户加入kerberos中之后执行kinit username(你自己的用户名)登陆然后进入hbase shell对此用户赋予权限
                    

赋权的代码如下

 grant "username(用户名)" ,"R(权限)","student(表名)","sex(列族名)","xingmian(列名)"
此外hbase还可以开启行级控制在配置中输入row将行级控制勾选上如果此时报错的话需要在hbase配置的高级中的hbase-site.xml 的 HBase 服务高级配置代码段(安全阀)中加入以下内容:

                  

5.HDFS 控制文件权限配置
hdfs-配置--启用 Sentry 同步--HDFS(服务范围)

启用访问控制列表---dfs.namenode.acls.enabled

启用 检查 HDFS 权限----dfs.permissions--HDFS(服务范围)

启用 HTTP Web 控制台的 Kerberos 身份验证--HDFS(服务范围),启动之后就不能访问hdfs 的namenode web ui页面了。其他服务也可进行类似的控制。

Sentry 同步路径前缀--sentry.hdfs.integration.path.prefixes---HDFS(服务范围) 

sentry.hdfs.integration.path.prefixes :/user/hive/warehouse

测试:

user2只 拥有 test.student 表的查询权限,同步文件权限之后user2只拥有/user/hive/warehouse/test.db/student 该文件的查询权限。hdfs下/user/hive/warehouse和他下面的其他路径 都不能访问。

kinit user2

[root@slave01 mySparkTest]# hdfs dfs -ls /user/hive/
Found 2 items
drwxr-xr-x   - hive hive          0 2018-07-30 17:00 /user/hive/.sparkStaging
drwxrwx--x+  - hive hive          0 2018-07-20 09:31 /user/hive/warehouse

[root@slave01 mySparkTest]# hdfs dfs -ls /user/hive/warehouse
ls: Permission denied: user=user2, access=READ_EXECUTE, inode="/user/hive/warehouse":hive:hive:drwxrwx--x
[root@slave01 mySparkTest]# hdfs dfs -ls /user/hive/warehouse/test.db/
ls: Permission denied: user=user2, access=READ_EXECUTE, inode="/user/hive/warehouse/test.db":hive:hive:drwxrwx--x
[root@slave01 mySparkTest]# hdfs dfs -ls /user/hive/warehouse/test.db/student
Found 1 items
-rwxrwx--x+  3 hive hive        113 2018-07-20 10:47 /user/hive/warehouse/test.db/student/student.txt

 
--------------------- 

Sentry在CDH平台中定位为统一的授权框架,即所有的组件都要受Sentry的管理,当然也是为了方便用户的操作,一个入口为所有数据相关进行授权。Fayson在前面的文章中介绍了大量Sentry与Hive/Impala的集成文章,其实Sentry除了可以给Hive/Impala表授权外,还可以管理HDFS ACL,Kafka,Solr,Kudu等。前两天Fayson也介绍过如何使用Sentry给Solr的collection进行赋权,参考《如何使用Sentry为Solr赋权》。本文Fayson主要介绍如何使用Sentry给Kafka的topic相关进行授权。

  • 内容概述:

1.Kafka与Sentry的集成赋权介绍

2.启用Kafka的Sentry赋权

3.Kafka的赋权测试

4.总结

  • 测试环境:

1.CM5.14.3/CDH5.14.2

2.CDK2.2.0(Apache Kafka0.10.2)

3.操作系统版本为Redhat7.3

4.采用root用户进行操作

5.集群已启用Kerberos

2.Kafka与Sentry的集成赋权介绍


从CDK2.1.x(Apache Kafka0.10.0) on CDH5.9.x开始,CDH开始支持通过Sentry给Kafka授权。我们知道Kafka可以单独作为集群部署,但是因为Sentry的安装需要HDFS,所以在部署Sentry与Kafka集成时,你必须安装HDFS服务,当Sentry安装完毕后,你可以停止HDFS服务。

2.1.可授权的资源


在Kafka集群中,可以赋权的东东我们称作资源(resources)或者实体(entities ),一旦启用Kafka的Sentry后,对这些资源或者实体进行操作,都需要对用户组进行赋权。Kafka中包含4种可以授权的资源:

1.集群(Cluster),它控制谁可以执行集群级别的操作,比如创建或者删除topic。它只有一个值,kafka-cluster,因为一个Kafka集群不能拥有多个集群资源。

2.Topic,它控制谁可以执行Topic级别的操作,比如生产和消费Topic。注意你在赋权的时候,它的值必须与Kafka的Topic的名称完全一致。从CDK3.1.0+CDH5.14.2开始,通配符(*)代表任何Topic权限。

3.消费者组(Consumergroup),它控制谁可以执行消费者组级别的操作,比如加入或者描述消费者组。它的值必须与消费者组的group.id完全匹配。从CDK3.1.0+CDH5.14.2开始,通配符(*)代表任何消费者组权限。当和Spark Streaming一起使用时,这一点比较重要,因为group.id可能是靠你的程序生成的。

4.主机(Host),它控制你可以从哪些主机执行操作。这个可以实现Kafka服务的IP过滤,通配符(*)代表允许所有主机。

2.2.可授权的操作


每个资源都可以被授权多种操作,以下是Kafka支持的授权操作,不是所有资源都支持以下所有操作。

1.ALL,代表资源的所有操作

2.read

3.write

4.create

5.delete

6.alter

7.describe

8.clusteraction

3.启用Kafka的Sentry赋权


在介绍本章之前,你需要一些预备知识才能继续往下阅读。首先CDH的Parcel默认不包含Kafka,你需要单独下载和安装,请参考Fayson之前的文章

如何在CDH中安装Kudu&Spark2&Kafka

启用Kafka的Sentry授权,集群必须安装Kerberos,Kerberos的安装请参考Fayson之前的文章

如何在CDH集群启用Kerberos

如何在Redhat7.3的CDH5.14中启用Kerberos

如何在CDH6.0.0-beta1中启用Kerberos

Kafka在启用Kerberos,以及使用过程中跟其他组件有些不一样,主要是需要引入jaas文件,请参考Fayson之前的文章

如何通过Cloudera Manager为Kafka启用Kerberos及使用

以下开始启用Kafka的Sentry授权集成

1.从Cloudera Manager修改Kafka的配置

以上三项,如果你正确启用了Kafka的Kerberos,默认已经启用

2.启用Kafka的Sentry,通过Cloudera Manager修改Kafka服务的配置

Sentry权限的cache勾选后可以提高性能。

3.如果是测试系统,建议将Sentry的cache间隔调整短一点,默认30s,可以改为1ms。

否则每次调整Kafka的相关授权以后,默认需要等待30s才能生效。

4.保存以上修改,然后重启集群服务,重启过程这里略。

4.创建测试需要使用的用户和principle


1.在所有节点创建fayson用户,并在Kerberos中创建fayson的principle。

[root@cdh01 shell]# sh ssh_do_all.sh node.list  "useradd fayson"

(可左右滑动)

[root@cdh01 shell]# kadmin.local
Authenticating as principal root/admin@FAYSON.COM with password.
kadmin.local:  addprinc fayson
WARNING: no policy specified for fayson@FAYSON.COM; defaulting to no policy
Enter password for principal "fayson@FAYSON.COM": 
Re-enter password for principal "fayson@FAYSON.COM": 
Principal "fayson@FAYSON.COM" created.
kadmin.local:

(可左右滑动)

2.为了后面操作方便,我们这里还创建一个kafka的principle,当然你也可以到/var/run/cloudera-scm-agent/process目录下去拿kafka用户的principle。

[root@cdh01 shell]# kadmin.local
Authenticating as principal root/admin@FAYSON.COM with password.
kadmin.local:  addprinc kafka/admin
WARNING: no policy specified for kafka/admin@FAYSON.COM; defaulting to no policy
Enter password for principal "kafka/admin@FAYSON.COM": 
Re-enter password for principal "kafka/admin@FAYSON.COM": 
Principal "kafka/admin@FAYSON.COM" created.
kadmin.local:

(可左右滑动)

5.Kafka的赋权测试


1.创建测试需要用到的client.properties和jaas.conf文件

[root@cdh01 kafka]# cat jaas.conf 
KafkaClient {
   com.sun.security.auth.module.Krb5LoginModule required
   useTicketCache=true;
};
[root@cdh01 kafka]# cat client.properties 
security.protocol=SASL_PLAINTEXT
sasl.kerberos.service.name=kafka
group.id=testgroup

(可左右滑动)

这里Fayson的jaas文件没有引入keytab,到时执行命令的时候需要先kinit,为什么Kafka的Kerberos需要这2个文件,可以参考Fayson之前的文章《如何通过Cloudera Manager为Kafka启用Kerberos及使用

2.首先我们使用fayson用户创建一个testTopic。

[root@cdh01 kafka]# kinit fayson
Password for fayson@FAYSON.COM: 
[root@cdh01 kafka]# kafka-topics --create --zookeeper cdh01.fayson.com:2181 --replication-factor 3 --partitions 3 --topic testTopic
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Created topic "testTopic".

(可左右滑动)

注意:这里Fayson并没有使用管理员用户kafka给fayson赋权“集群”资源的权限,但是fayson用户依旧可以创建topic,包括删除,这是CDH的中Kafka和Sentry权限集成的bug,需要在后续版本才修复,目标版本是C6。

3.使用fayson用户启用producer脚本命令。

[root@cdh01 kafka]# export KAFKA_OPTS="-Djava.security.auth.login.config=/data/disk1/_fayson/kafka/jaas.conf"
[root@cdh01 kafka]# kafka-console-producer --broker-list cdh02.fayson.com:9092,cdh03.fayson.com:9092,cdh04.fayson.com:9092 --topic testTopic --producer.config client.properties
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
18/06/13 00:39:20 WARN producer.ProducerConfig: The configuration 'group.id' was supplied but isn't a known config.
2
18/06/13 00:39:22 WARN clients.NetworkClient: Error while fetching metadata with correlation id 2 : {testTopic=UNKNOWN_TOPIC_OR_PARTITION}
18/06/13 00:39:22 WARN clients.NetworkClient: Error while fetching metadata with correlation id 6 : {testTopic=UNKNOWN_TOPIC_OR_PARTITION}
18/06/13 00:39:22 WARN clients.NetworkClient: Error while fetching metadata with correlation id 8 : {testTopic=UNKNOWN_TOPIC_OR_PARTITION}
18/06/13 00:39:22 WARN clients.NetworkClient: Error while fetching metadata with correlation id 9 : {testTopic=UNKNOWN_TOPIC_OR_PARTITION}
18/06/13 00:39:22 WARN clients.NetworkClient: Error while fetching metadata with correlation id 10 : {testTopic=UNKNOWN_TOPIC_OR_PARTITION}
18/06/13 00:39:22 WARN clients.NetworkClient: Error while fetching metadata with correlation id 11 : {testTopic=UNKNOWN_TOPIC_OR_PARTITION}
18/06/13 00:39:22 WARN clients.NetworkClient: Error while fetching metadata with correlation id 12 : {testTopic=UNKNOWN_TOPIC_OR_PARTITION}
^C18/06/13 00:39:22 WARN kerberos.KerberosLogin: [Principal=null]: TGT renewal thread has been interrupted and will exit.

(可左右滑动)

报错,无法produce到topic

4.我们给fayson用户组赋权可以写入数据到testTopic,注意需要使用管理员kafka用户登录Kerberos才能进行操作

[root@cdh01 kafka]# kinit kafka/admin
Password for kafka/admin@FAYSON.COM: 
[root@cdh01 kafka]# klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: kafka/admin@FAYSON.COM
Valid starting       Expires              Service principal
06/13/2018 00:41:45  06/14/2018 00:41:45  krbtgt/FAYSON.COM@FAYSON.COM
        renew until 06/20/2018 00:41:45

(可左右滑动)

创建角色kafka_role

[root@cdh01 kafka]# kafka-sentry -cr -r kafka_role
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
18/06/13 00:43:26 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

(可左右滑动)

列出Sentry中的角色

[root@cdh01 kafka]# kafka-sentry -lr
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
18/06/13 00:44:25 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
fayson
hive_admin
admin
kafka_role
kafka_role1

(可左右滑动)

给kafka_role角色赋权可以给testTopic写入权限

[root@cdh01 kafka]# kafka-sentry -gpr -r kafka_role -p "Topic=testTopic->action=write"
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
18/06/13 00:45:36 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

(可左右滑动)

给kafka_role角色赋权可以给testTopic的describe权限

[root@cdh01 kafka]# kafka-sentry -gpr -r kafka_role -p "Topic=testTopic->action=describe"
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
18/06/13 01:34:10 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

(可左右滑动)

把kafka_role加入到用户组fayson中

[root@cdh01 kafka]# kafka-sentry -arg -r kafka_role -g fayson
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/KAFKA-2.2.0-1.2.2.0.p0.68/lib/kafka/libs/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
18/06/13 00:47:08 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

(可左右滑动)

再次使用fayson用户登录Kerberos,启用producer程序

[root@cdh01 kafka]# export KAFKA_OPTS="-Djava.security.auth.login.config=/data/disk1/_fayson/kafka/jaas.conf"
[root@cdh01 kafka]# kafka-console-producer --broker-list cdh02.fayson.com:9092,cdh03.fayson.com:9092,cdh04.fayson.com:9092 --topic testTopic --producer.config client.properties

(可左右滑动)

执行成功,说明赋权testTopic的写入权限成功。

5.使用fayson用户启动consumer程序

export KAFKA_OPTS="-Djava.security.auth.login.config=/data/disk1/_fayson/kafka/jaas.conf"
kafka-console-consumer --topic testTopic --from-beginning --bootstrap-server cdh02.fayson.com:9092,cdh03.fayson.com:9092,cdh04.fayson.com:9092 --consumer.config client.properties

(可左右滑动)

报错没有权限

6.给kafka_role角色赋权consumer相关的权限

kafka-sentry -gpr -r kafka_role -p "CONSUMERGROUP=testgroup->action=read"
kafka-sentry -gpr -r kafka_role -p "CONSUMERGROUP=testgroup->action=describe"
kafka-sentry -gpr -r kafka_role -p "Topic=testTopic->action=read"

(可左右滑动)

7.再次使用fayson用户登录Kerberos后启动producer和consumer

export KAFKA_OPTS="-Djava.security.auth.login.config=/data/disk1/_fayson/kafka/jaas.conf"
kafka-console-producer --broker-list cdh02.fayson.com:9092,cdh03.fayson.com:9092,cdh04.fayson.com:9092 --topic testTopic --producer.config client.properties

(可左右滑动)

export KAFKA_OPTS="-Djava.security.auth.login.config=/data/disk1/_fayson/kafka/jaas.conf"
kafka-console-consumer --topic testTopic --from-beginning --bootstrap-server cdh02.fayson.com:9092,cdh03.fayson.com:9092,cdh04.fayson.com:9092 --consumer.config client.properties

(可左右滑动)

消费成功,表明赋权消费者相关权限以后,消费成功。

6.总结


1.通过Sentry可以对Kafka的topic进行权限管理,主要是往topic写入数据以及读取topic的数据。

2.启用Kafka的Sentry赋权,CDH集群必须启用Kerberos,另外对于Kafka服务也需要启用Kerberos。

3.目前Kafka的授权,对于create和delete topic还不完善,需要等待后续版本。

4.如果只是测试系统,建议将Sentry权限的cache刷新间隔调低,Fayson这次测试由默认的30s改为了1ms,如果使用默认,将需要等待30s才能让新的权限生效。

5.在给Topic赋权read或者write权限时,务必同时带上describe权限,否则权限不生效。当然你也可以将权限设置为ALL。

6.在给Topic的赋权read,即消费Topic的时候,client.properties必须带上参数group.id,然后这个group.id的值必须也同样赋权,如:

kafka-sentry -gpr -r kafka_role -p "CONSUMERGROUP=testgroup->action=ALL"

否则依旧无法消费Topic

7.一旦对Kafka启用Sentry授权以后,kafka用户就是管理员,一切管理员操作都需要使用kafka用户来操作,这个与我们在Hive/Impala中使用Sentry时,hive用户是管理员原理是一样的,Fayson之前介绍Solr的Sentry赋权时,solr用户就是默认管理员,也是一样。

8.Fayson会在后续的文章继续介绍Kafka的Host资源授权相关。

参考:

https://www.cloudera.com/documentation/kafka/latest/topics/kafka_security.html#using_kafka_with_sentry

集群说明: 
集群有wlint01、wlnamenode01、wldatanode001~wldatanode018一共20个节点, 
对应ip地址 192.168.32.9~192.168.32.28

1.生成keytab文件 
生成http.keytab文件

[wlbd@wlint01 keytabFile]$ sudo kadmin.local -q "xst -norandkey -k http.keytab HTTP/wlint01@HXDI.COM"
[wlbd@wlint01 keytabFile]$ sudo kadmin.local -q "xst -norandkey -k http.keytab HTTP/wlnamenode01@HXDI.COM"
[wlbd@wlint01 keytabFile]$ for i in {1..9}; do sudo kadmin.local -q "xst -norandkey -k http.keytab HTTP/wldatanode00$i@HXDI.COM"; done
[wlbd@wlint01 keytabFile]$ for i in {0..8}; do sudo kadmin.local -q "xst -norandkey -k http.keytab HTTP/wldatanode01$i@HXDI.COM"; done
1
2
3
4
生成impala-unmerge.keytab文件

[wlbd@wlint01 keytabFile]$ sudo kadmin.local -q "xst -norandkey -k impala-unmerge.keytab impala/wlint01@HXDI.COM"
[wlbd@wlint01 keytabFile]$ sudo kadmin.local -q "xst -norandkey -k impala-unmerge.keytab impala/wlnamenode01@HXDI.COM"
[wlbd@wlint01 keytabFile]$ for i in {1..9}; do sudo kadmin.local -q "xst -norandkey -k impala-unmerge.keytab impala/wldatanode00$i@HXDI.COM"; done
[wlbd@wlint01 keytabFile]$ for i in {0..8}; do sudo kadmin.local -q "xst -norandkey -k impala-unmerge.keytab impala/wldatanode01$i@HXDI.COM"; done
1
2
3
4
将impala-unmerge.keytab和http.keytab合并成impala.keytab

[wlbd@wlint01 keytabFile]$ ktutil 
ktutil:  rkt http.keytab 
ktutil:  rkt impala-unmerge.keytab 
ktutil:  wkt impala.keytab 
ktutil:  quit
1
2
3
4
5
测试合并的impala.keytab文件中的凭据是否有效

[wlbd@wlint01 keytabFile]$ klist -kte impala.keytab
1
将impala.keytab拷贝到每个节点的/etc/impala/conf下,并更改权限

cp impala.keytab /etc/impala/conf/
cd /etc/impala/conf/
chmod 400 impala.keytab 
chown impala:impala impala.keytab
1
2
3
4
拷贝到每个节点可以用批处理进行

for i in {10..28}; do  scp impala.keytab 192.168.32.$i:/etc/impala/conf/; ssh 192.168.32.$i; "cd /etc/impala/conf/;  chmod 400 impala.keytab; chown impala:impala impala.keytab; exit"; done
1
接着,去到Cloudera Manager管理界面去修改Impala配置:Impala -> 配置 –> (类别)高级–>Impala Daemon 命令行参数高级配置代码段(安全阀) 
添加下面内容:

IMPALA_CATALOG_ARGS="-kerberos_reinit_interval=60"
IMPALA_SERVER_ARGS="-server_name=server1 -principal=impala/_HOST@HXDI.COM"
IMPALA_STATE_STORE_ARGS ="-keytab_file=/etc/impala/conf/impala.keytab"
1
2
3

重启过期配置

测试 
在Kerberos数据库中创建一个用户,并生成该用户的keytab文件

[wlbd@wlint01 ~]$ sudo kadmin.local -q "addprinc -randkey user1@HXDI.COM"
[wlbd@wlint01 ~]$ sudo kadmin.local -q "xst -norandkey -k user1.keytab user1@HXDI.COM"
[wlbd@wlint01 ~]$ kinit -kt user1.keytab user1@HXDI.COM
1
2
3
重启Impala之后,在Impala组件页面点击”状态”,会显示进入impala-shell的命令:

impala-shell -i wldatanode004 -d default -k
1

其中参数表示为: 
-i 指定连接运行 impalad 守护进程的主机。默认端口是 21000。你可以连接到集群中运行 impalad 的任意主机。假如你连接到 impalad 实例通过 –fe_port 标志使用了其他端口,则应当同时提供端口号,格式为 hostname:port

-d 指定启动后使用的数据库,与建立连接后使用 USE 语句选择数据库作用相同,如果没有指定,那么使用 default 数据库。

-k 当连接到 impalad 时使用 Kerberos 认证。如果要连接的 impalad 实例不支持 Kerberos,将显示一个错误。 


2.Sentry服务下使用Impala 
在CDH中添加Sentry服务后,可以在Hive和Impala通过GRANT和REVOKE语句来设置权限,然后两个组件可以自动使用那些相同的权限。 
在HIve CLI中创建两个数据库和相应的表

[wlbd@wlint01 keytabFile]$ kinit -kt hive.keytab hive/wlint01
[wlbd@wlint01 keytabFile]$ hive

Logging initialized using configuration in jar:file:/opt/cloudera/parcels/CDH-5.14.2-1.cdh5.14.2.p0.3/jars/hive-common-1.1.0-cdh5.14.2.jar!/hive-log4j.properties
WARNING: Hive CLI is deprecated and migration to Beeline is recommended.
hive> create database db1;
OK
Time taken: 1.942 seconds
1
2
3
4
5
6
7
8
在db1中创建table1

create table db1.table1 (
ip STRING, country STRING, client STRING, action STRING
) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',';

load data local inpath '/app/wlbd/keytabFile/events.csv' overwrite into table db1.table1;
1
2
3
4
5
通过beeline赋予用户权限

beeline -u "jdbc:hive2://wlint01:10000/;principal=hive/wlint01@HXDI.COM"
1
给user1赋予db1的所有权限

create role user1_role;
GRANT ALL ON DATABASE db1 TO ROLE user1_role;
GRANT ROLE user1_role TO GROUP user1;
1
2
3
然后通过user1.keytab进入到impala-shell,进入后必须执行 invalidate metadata 才能看到刚刚创建的数据库和表。

[wlbd@wlint01 keytabFile]$ kinit -kt user1.keytab user1
[wlbd@wlint01 keytabFile]$ impala-shell -i wldatanode004 -d default -k
Starting Impala Shell using Kerberos authentication
Using service name 'impala'
Connected to wldatanode004:21000
Server version: impalad version 2.11.0-cdh5.14.2 RELEASE (build ed85dce709da9557aeb28be89e8044947708876c)
***********************************************************************************
Welcome to the Impala shell.
(Impala Shell v2.11.0-cdh5.14.2 (ed85dce) built on Tue Mar 27 13:39:48 PDT 2018)

You can run a single query from the command line using the '-q' option.
***********************************************************************************
Query: use `default`
[wldatanode004:21000] > show databases;
Query: show databases
+------------------+----------------------------------------------+
| name             | comment                                      |
+------------------+----------------------------------------------+
| _impala_builtins | System database for Impala builtin functions |
| default          | Default Hive database                        |
+------------------+----------------------------------------------+
Fetched 2 row(s) in 0.03s
[wldatanode004:21000] > invalidate metadata;
Query: invalidate metadata
Query submitted at: 2018-06-21 17:07:17 (Coordinator: http://wldatanode004:25000)
Query progress can be monitored at: http://wldatanode004:25000/query_plan?query_id=14491ddb95368a04:fcb124b000000000
Fetched 0 row(s) in 4.19s
[wldatanode004:21000] > show databases;
Query: show databases
+------------------+----------------------------------------------+
| name             | comment                                      |
+------------------+----------------------------------------------+
| _impala_builtins | System database for Impala builtin functions |
| db1              |                                              |
| default          | Default Hive database                        |
+------------------+----------------------------------------------+
Fetched 3 row(s) in 0.03s
[wldatanode004:21000] > show tables in db1;
Query: show tables in db1
+--------+
| name   |
+--------+
| table1 |
+--------+
Fetched 1 row(s) in 0.03s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
如果在db1新创建了table2这张表,可以通过 invalidate metadata db1.table2 进行更新;

[wldatanode004:21000] > invalidate metadata db1.table2;
Query: invalidate metadata db1.table2
Query submitted at: 2018-06-21 17:13:32 (Coordinator: http://wldatanode004:25000)
Query progress can be monitored at: http://wldatanode004:25000/query_plan?query_id=4e46f16a19e4b096:5fd05f8c00000000
Fetched 0 row(s) in 0.04s
[wldatanode004:21000] > show tables in db1;
Query: show tables in db1
+--------+
| name   |
+--------+
| table1 |
| table2 |
+--------+
Fetched 2 row(s) in 0.03s

转载于:https://my.oschina.net/hblt147/blog/2988180

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值