[root@ip-172-31-8-141 1874-hive-HIVESERVER2]# kinit -kt hive.keytab hive/[email protected]
[root@ip-172-31-8-141 1874-hive-HIVESERVER2]# klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: hive/[email protected]
Valid starting Expires Service principal
09/01/17 11:10:54 09/02/17 11:10:54 krbtgt/[email protected]
renew until 09/06/17 11:10:54
[root@ip-172-31-8-141 1874-hive-HIVESERVER2]#
[root@ip-172-31-8-141 ec2-user]# hadoop fs -mkdir /extwarehouse
[root@ip-172-31-8-141 ec2-user]# hadoop fs -ls /
drwxr-xr-x - hive supergroup 0 2017-09-01 11:27 /extwarehouse
drwxrwxrwx - user_r supergroup 0 2017-08-23 03:23 /fayson
drwx------ - hbase hbase 0 2017-09-01 02:59 /hbase
drwxrwxrwt - hdfs supergroup 0 2017-08-31 06:18 /tmp
drwxrwxrwx - hdfs supergroup 0 2017-08-30 03:48 /user
[root@ip-172-31-8-141 ec2-user]# hadoop fs -chown hive:hive /extwarehouse
[root@ip-172-31-8-141 ec2-user]# hadoop fs -chmod 771 /extwarehouse
[root@ip-172-31-8-141 ec2-user]# hadoop fs -ls /
drwxrwx--x - hive hive 0 2017-09-01 11:27 /extwarehouse
drwxrwxrwx - user_r supergroup 0 2017-08-23 03:23 /fayson
drwx------ - hbase hbase 0 2017-09-01 02:59 /hbase
drwxrwxrwt - hdfs supergroup 0 2017-08-31 06:18 /tmp
drwxrwxrwx - hdfs supergroup 0 2017-08-30 03:48 /user
[root@ip-172-31-8-141 ec2-user]#
create external table if not exists student(
name string,
age int,
addr string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
LOCATION '/extwarehouse/student';
[root@ip-172-31-8-141 1874-hive-HIVESERVER2]# beeline
Beeline version 1.1.0-cdh5.11.1 by Apache Hive
beeline> !connect jdbc:hive2://localhost:10000/;principal=hive/[email protected]
...
0: jdbc:hive2://localhost:10000/> create external table if not exists student(
. . . . . . . . . . . . . . . . > name string,
. . . . . . . . . . . . . . . . > age int,
. . . . . . . . . . . . . . . . > addr string
. . . . . . . . . . . . . . . . > )
. . . . . . . . . . . . . . . . > ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
. . . . . . . . . . . . . . . . > LOCATION '/extwarehouse/student';
...
INFO : OK
No rows affected (0.236 seconds)
0: jdbc:hive2://localhost:10000/>
[root@ip-172-31-8-141 student]# pwd
/home/ec2-user/student
[root@ip-172-31-8-141 student]# ll
total 4
-rw-r--r-- 1 root root 39 Sep 1 11:37 student.txt
[root@ip-172-31-8-141 student]# cat student.txt
zhangsan,18,guangzhou
lisi,20,shenzhen
[root@ip-172-31-8-141 student]#
[root@ip-172-31-8-141 student]# hadoop fs -mkdir /tmp/student
[root@ip-172-31-8-141 student]# ll
total 4
-rw-r--r-- 1 hive hive 39 Sep 1 11:37 student.txt
[root@ip-172-31-8-141 student]# hadoop fs -put student.txt /tmp/student
[root@ip-172-31-8-141 student]# hadoop fs -ls /tmp/student
Found 1 items
-rw-r--r-- 3 hive supergroup 39 2017-09-01 11:57 /tmp/stu
dent/student.txt
[root@ip-172-31-8-141 student]#
0: jdbc:hive2://localhost:10000/> load data inpath '/tmp/student' into table student;
...
INFO : Table default.student stats: [numFiles=1, totalSize=39]
INFO : Completed executing command(queryId=hive_20170901115858_5a76aa76-1b24-40ce-8254-42991856c05b); Time taken: 0.263 seconds
INFO : OK
No rows affected (0.41 seconds)
0: jdbc:hive2://localhost:10000/>
0: jdbc:hive2://localhost:10000/> select * from student;
...
INFO : OK
+---------------+--------------+---------------+--+
| student.name | student.age | student.addr |
+---------------+--------------+---------------+--+
| zhangsan | 18 | guangzhou |
| lisi | 20 | shenzhen |
+---------------+--------------+---------------+--+
2 rows selected (0.288 seconds)
0: jdbc:hive2://localhost:10000/>
[ec2-user@ip-172-31-8-141 cdh-shell-master]$ kinit fayson
Password for [email protected]:
[ec2-user@ip-172-31-8-141 cdh-shell-master]$ klist
Ticket cache: FILE:/tmp/krb5cc_500
Default principal: [email protected]
Valid starting Expires Service principal
09/01/17 12:27:39 09/02/17 12:27:39 krbtgt/[email protected]
renew until 09/08/17 12:27:39
[ec2-user@ip-172-31-8-141 cdh-shell-master]$
[ec2-user@ip-172-31-8-141 ~]$ hadoop fs -ls /extwarehouse/student
ls: Permission denied: user=fayson, access=READ_EXECUTE, inode="/extwarehouse/student":hive:hive:drwxrwx--x
[ec2-user@ip-172-31-8-141 ~]$
[ec2-user@ip-172-31-8-141 ~]$ beeline
Beeline version 1.1.0-cdh5.11.1 by Apache Hive
beeline> !connect jdbc:hive2://localhost:10000/;principal=hive/[email protected]
...
INFO : OK
+-----------+--+
| tab_name |
+-----------+--+
+-----------+--+
No rows selected (0.295 seconds)
0: jdbc:hive2://localhost:10000/> select * from student;
Error: Error while compiling statement: FAILED: SemanticException No valid privileges
User fayson does not have privileges for QUERY
The required privileges: Server=server1->Db=default->Table=student->Column=addr->action=select; (state=42000,code=40000)
0: jdbc:hive2://localhost:10000/>
[ec2-user@ip-172-31-8-141 cdh-shell-master]$ impala-shell
...
[Not connected] > connect ip-172-31-10-156.ap-southeast-1.compute.internal:21000;
Connected to ip-172-31-10-156.ap-southeast-1.compute.internal:21000
Server version: impalad version 2.8.0-cdh5.11.1 RELEASE (build 3382c1c488dff12d5ca8d049d2b59babee605b4e)
[ip-172-31-10-156.ap-southeast-1.compute.internal:21000] > show tables;
Query: show tables
ERROR: AuthorizationException: User '[email protected]' does not have privileges to access: default.*
[ip-172-31-10-156.ap-southeast-1.compute.internal:21000] > select * from student;
Query: select * from student
Query submitted at: 2017-09-01 12:33:06 (Coordinator: http://ip-172-31-10-156.ap-southeast-1.compute.internal:25000)
ERROR: AuthorizationException: User '[email protected]' does not have privileges to execute 'SELECT' on: default.student
[ip-172-31-10-156.ap-southeast-1.compute.internal:21000] >
0: jdbc:hive2://localhost:10000/> create role student_read;
...
INFO : Executing command(queryId=hive_20170901124848_927878ba-0217-4a32-a508-bf29fed67be8): create role student_read
...
INFO : OK
No rows affected (0.104 seconds)
0: jdbc:hive2://localhost:10000/>
0: jdbc:hive2://localhost:10000/> grant select on table student to role student_read;
...
INFO : Executing command(queryId=hive_20170901125252_8702d99d-d8eb-424e-929d-5df352828e2c): grant select on table student to role student_read
...
INFO : OK
No rows affected (0.111 seconds)
0: jdbc:hive2://localhost:10000/>
0: jdbc:hive2://localhost:10000/> grant role student_read to group fayson;
...
INFO : Executing command(queryId=hive_20170901125454_5f27a87e-2f63-46d9-9cce-6f346a0c415c): grant role student_read to group fayson
...
INFO : OK
No rows affected (0.122 seconds)
0: jdbc:hive2://localhost:10000/>
[ec2-user@ip-172-31-8-141 ~]$ hadoop fs -ls /extwarehouse/student
Found 1 items
-rwxrwx--x+ 3 hive hive 39 2017-09-01 14:42 /extwarehouse/student/student.txt
[ec2-user@ip-172-31-8-141 ~]$
[ec2-user@ip-172-31-8-141 ~]$ klist
Ticket cache: FILE:/tmp/krb5cc_500
Default principal: [email protected]
Valid starting Expires Service principal
09/01/17 12:58:59 09/02/17 12:58:59 krbtgt/[email protected]
renew until 09/08/17 12:58:59
[ec2-user@ip-172-31-8-141 ~]$
[ec2-user@ip-172-31-8-141 ~]$ beeline
Beeline version 1.1.0-cdh5.11.1 by Apache Hive
beeline> !connect jdbc:hive2://localhost:10000/;principal=hive/[email protected]
...
INFO : OK
+-----------+--+
| tab_name |
+-----------+--+
| student |
+-----------+--+
1 row selected (0.294 seconds)
0: jdbc:hive2://localhost:10000/> select * from student;
...
INFO : OK
+---------------+--------------+---------------+--+
| student.name | student.age | student.addr |
+---------------+--------------+---------------+--+
| zhangsan | 18 | guangzhou |
| lisi | 20 | shenzhen |
+---------------+--------------+---------------+--+
2 rows selected (0.241 seconds)
0: jdbc:hive2://localhost:10000/>
[ec2-user@ip-172-31-8-141 cdh-shell-master]$ klist
Ticket cache: FILE:/tmp/krb5cc_500
Default principal: [email protected]
Valid starting Expires Service principal
09/01/17 12:58:59 09/02/17 12:58:59 krbtgt/[email protected]
renew until 09/08/17 12:58:59
[ec2-user@ip-172-31-8-141 cdh-shell-master]$ impala-shell
...
[Not connected] > connect ip-172-31-10-156.ap-southeast-1.compute.internal:21000;
Connected to ip-172-31-10-156.ap-southeast-1.compute.internal:21000
Server version: impalad version 2.8.0-cdh5.11.1 RELEASE (build 3382c1c488dff12d5ca8d049d2b59babee605b4e)
[ip-172-31-10-156.ap-southeast-1.compute.internal:21000] > show tables;
Query: show tables
+---------+
| name |
+---------+
| student |
+---------+
Fetched 1 row(s) in 0.02s
[ip-172-31-10-156.ap-southeast-1.compute.internal:21000] > select * from student;
...
+----------+-----+-----------+
| name | age | addr |
+----------+-----+-----------+
| zhangsan | 18 | guangzhou |
| lisi | 20 | shenzhen |
+----------+-----+-----------+
Fetched 2 row(s) in 0.13s
[ip-172-31-10-156.ap-southeast-1.compute.internal:21000] >
大数据视频推荐:
CSDN
大数据语音推荐:
企业级大数据技术应用
大数据机器学习案例之推荐系统
自然语言处理
大数据基础
人工智能:深度学习入门到精通