Hadoop的相关资料
1 HDFS
1.1 概念
Hadoop分布式文件系统(HDFS)被设计成适合运行在通用硬件(commodity hardware)上的分布式文件系统
1.2 特点
- 高度容错性
- 硬件要求低
- 能提供高吞吐量的数据访问
1.3 文件系统命令行
1.3.1 获取帮助
|
1
|
hadoop fs -help
|
1.3.2 ls命令
|
1
2
|
hadoop fs -
ls
/
hadoop fs -
ls
-R
/user
|
1.3.3 getconf命令
|
1
2
|
hdfs getconf -help
hdfs getconf -namenodes
|
1.3.4 版本信息
|
1
|
hdfs version
|
注:由于与linux系统指令用法接近,详细请参阅文后的官方链接。
2 MapReduce
2.1 MapReduce的简介
MapReduce是一种编程模型,用于大规模数据集(大于1TB)的并行运算。
2.2 工作原理
假若一个盘子中有黑豆、黄豆、绿豆、红豆,你现在想挑出其中的红豆。
MapReduce方法则是:
step1 找一个团队来处理(相当于一群服务器组成的集群)
step2 把豆子平均分配给团队里的每成员(相当于给群集中的服务器分配数据)
step3 让团队的成员开始挑选出其中的红豆(相当于群集的计算机并行地处理数据)
step4 把团队成员挑出来的豆子汇聚(相当于群集汇总并输出结果)
3 Hive
3.1 Hive的简介
3.1.1 概念
Hive是一个基于Hadoop的数据仓库平台。
3.1.2 Hive的作用
通过hive,我们可以方便地进行ETL的工作
hive定义了一个类似于SQL的查询语言
HQL能够将用户编写的QL转化为相应的Mapreduce程序基于Hadoop执行
3.1.3 Hive项目的历史
Hive是Facebook 2008年8月刚开源的一个数据仓库框架,其系统目标与Pig有相似之处,但它有一些Pig目前还不支持的机制。
比如:更丰富的类型系统、更类似SQL的查询语言、Table/Partition元数据的持久化等。
4 impala
4.1 Impala的简介
Impala 是 Cloudera 在受到 Google 的 Dremel 启发下开发的实时交互 SQL 大数据查询工具,Impala 没有再使用缓慢的 Hive+MapReduce 批处理,而是通过使用与商用并行关系数据库中类似的分布式查询引擎(由 Query Planner、Query Coordinator 和 Query Exec Engine 三部分组成),可以直接从 HDFS 或 HBase 中用 SELECT、JOIN 和统计函数查询数据,从而大大降低了延迟。
4.2 Impala的shell
4.2.1 启动shell
|
1
|
impala-shell
|
4.2.2 版本查询
|
1
|
select
version();
|
4.3 库的操作
4.3.1 查询数据库
|
1
|
show databases;
|
4.3.2 创建数据库
|
1
2
|
create database testdb;
create database testdb2;
|
数据库存储路径:
|
1
|
hdfs dfs -
ls
/user/hive/warehouse/
|
4.3.3 使用数据库
|
1
|
use testdb;
|
4.3.4 显示当前数据库
|
1
|
select
current_database();
|
4.3.5 删除数据库
|
1
|
drop database testdb;
|
4.4 表操作
4.4.1 创建表
|
1
2
3
|
create table t1 (x int);
create table t3 (
id
int, word string);
create table city (
id
int,name string,countrycode string,district string,population int);
|
4.4.2 显示数据库中的表
|
1
2
3
|
show tables;
show tables
in
testdb;
show tables
in
testdb like
't*'
;
|
4.4.3 表结构描述
|
1
|
describe city;
|
4.4.4 修改表名称
|
1
|
alter table t3 rename to t2;
|
4.4.5 插入数据
|
1
2
|
insert into t1 values (1),(3),(2),(4);
insert into t2 values (1,
"one"
), (3,
"three"
), (5,
'five'
);
|
4.4.6 数据查询
|
1
2
|
select
min(x), max(x),
sum
(x), avg(x) from t1;
select
word from t1
join
t2 on (t1.x = t2.
id
);
|
5 sentry
5.1 开启权限
5.1.1 开启权限
Hive/Impala > Configuration > Service-Wide > Sentry Service > 选择“sentry”
5.1.2 指定认证服务器
Hive > Configuration > Service-Wide > Advanced > Server Name for Sentry Authorization(hive.sentry.server) > 填写sentry服务器名称或IP地址
5.1.3 设置特权用户
Hive > Configuration > Service-Wide > Security > Bypass Sentry Authorization Users(sentry.metastore.service.users) > 填写绕过的linux用户名(hive,impala,hue,hdfs等)
5.1.4 配置Hive的代理用户
HDFS > Configuration > Service-Wide > Proxy > Hive Proxy User Groups(hadoop.proxyuser.hive.groups) > 填写代理的linux用户名(hive,impala,hue,hdfs等)
5.1.5 重启服务
重启Hive/Impala的服务
5.2 授权
5.2.1 创建数据库用户和组
|
1
2
3
|
groupadd gp1
useradd
user1 -G gp1
useradd
user2 -G gp1
|
5.2.2 切换执行用户
|
1
|
su
- impala
|
5.2.3 创建数据库
切换到hive shell
|
1
|
hive
|
新建库
|
1
|
create database testdb;
|
退出hive shell
|
1
|
quit;
|
5.2.4 创建角色
切换到impala shell
|
1
|
impala-shell
|
创建角色
|
1
|
create role ro1;
|
5.2.5 确认创建的角色
|
1
|
show roles;
|
5.2.6 用户组和角色的关联
|
1
|
grant role ro1 to group gp1;
|
5.2.7 角色授权
|
1
|
grant all on database testdb to role ro1;
|