大数据平台运维之Hive

大数据系列之运维(自主搭建的大数据平台)

(4)Hive运维
  1. 启动 Hvie 客户端,通过 Hive 查看 hadoop 所有文件路径
[root@master apache-hive-2.1.1-bin]# bin/hive
hive> dfs -ls /;
Found 6 items
drwxr-xr-x   - root supergroup          0 2020-03-29 22:12 /1daoyun
drwxr-xr-x   - root supergroup          0 2020-03-29 21:54 /app
drwxr-xr-x   - root supergroup          0 2020-03-30 21:01 /hbase
drwxr-xr-x   - root supergroup          0 2020-03-29 22:32 /output
drwxrwxr-x   - root supergroup          0 2020-03-29 22:04 /tmp
drwxr-xr-x   - root supergroup          0 2020-03-29 22:04 /user

还有一种是

hive> dfs -ls;

区别是前一个查看的是HDFS的根目录下所有文件路径,后一个查看的是HDFS下所在用户的所有文件路径。

  1. 使用 Hive 工具来创建数据表 xd_phy_course,将 phy_course_xd.txt 导入到该表中,其中 xd_phy_course 表的数据结构如下表所示。导入完成后,通过hive 查询数据表 xd_phy_course 中数据在 HDFS 所处的文件位置列表信息。

在这里插入图片描述

hive> create table xd_phy_course (stname string,stID int,class string,opt_cour string) row format delimited fields terminated by '\t' lines terminated by '\n' stored as textfile;
OK
Time taken: 3.45 seconds
hive> load data local inpath'/root/tiku/Hive/phy_course_xd.txt' into table xd_phy_course;
Loading data to table default.xd_phy_course
OK
Time taken: 1.442 seconds
hive> dfs -ls /user/hive_remote/warehouse;
Found 1 items
drwxrwxr-x   - root supergroup          0 2020-03-30 22:41 /user/hive_remote/warehouse/xd_phy_course
  1. 使用 Hive 工具来创建数据表 xd_phy_course,并定义该表为外部表,外部存储位置为/1daoyun/data/hive,将 phy_course_xd.txt 导入到该表中,其中xd_phy_course 表的数据结构如下表所示。导入完成后,在 hive 中查询数据表 xd_phy_course 的数据结构信息。

在这里插入图片描述

hive> create external table xd_phy_course (stname string,stID int,class string,opt_cour string) row format delimited fields terminated by '\t' lines terminated by '\n' location '/1daoyun/data/hive';
OK
Time taken: 0.211 seconds
hive> load data local inpath'/root/tiku/Hive/phy_course_xd.txt' into table xd_phy_course;
Loading data to table default.xd_phy_course
OK
Time taken: 0.577 seconds
hive> describe xd_phy_course;
OK
stname            		string              	                    
stid                	int                 	                    
class               	string              	                    
opt_cour            	string              	                    
Time taken: 0.114 seconds, Fetched: 4 row(s)
  1. 使用 Hive 工具来查找出 phy_course_xd.txt 文件中某高校 Software_1403 班级报名选修 volleyball 的成员所有信息,其中 phy_course_xd.txt 文件数据结构如下表所示,选修科目字段为 opt_cour,班级字段为 class。

在这里插入图片描述

hive> create table phy_course_xd (stname string,stID int,class string,opt_cour string) row format delimited fields terminated by '\t' lines terminated by '\n';
OK
Time taken: 0.177 seconds
hive> load data local inpath'/root/tiku/Hive/phy_course_xd.txt' into table phy_course_xd;
Loading data to table default.phy_course_xd
OK
Time taken: 0.537 seconds
hive> select * from phy_course_xd where class='Software_1403' and opt_cour='volleyball';
OK
student409	10120408	Software_1403	volleyball
student411	10120410	Software_1403	volleyball
student413	10120412	Software_1403	volleyball
student419	10120418	Software_1403	volleyball
student421	10120420	Software_1403	volleyball
student422	10120421	Software_1403	volleyball
student424	10120423	Software_1403	volleyball
student432	10120431	Software_1403	volleyball
student438	10120437	Software_1403	volleyball
student447	10120446	Software_1403	volleyball
Time taken: 2.072 seconds, Fetched: 10 row(s)

  1. 使用 Hive 工具来统计 phy_course_xd.txt 文件中某高校报名选修各个体育科目的总人数,其中 phy_course_xd.txt 文件数据结构如下表所示,选修科目字段为 opt_cour,将统计的结果导入到表 phy_opt_count 中,通过 SELECT语句查询表 phy_opt_count 内容。

在这里插入图片描述

hive> create table phy_course_xd (stname string,stID int,class string,opt_cour string) row format delimited fields terminated by '\t' lines terminated by '\n';
OK
Time taken: 0.177 seconds
hive> load data local inpath'/root/tiku/Hive/phy_course_xd.txt' into table phy_course_xd;
Loading data to table default.phy_course_xd
OK
Time taken: 0.537 seconds
hive> create table phy_opt_count (opt_cour string,cour_count int) row format delimited fields terminated by '\t' lines terminated by '\n';
OK
Time taken: 0.152 seconds
hive> insert overwrite table phy_opt_count select phy_course_xd.opt_cour,count(distinct phy_course_xd.stID) from phy_course_xd group by phy_course_xd.opt_cour;
WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
Query ID = root_20200330231614_ff660b65-5065-439b-9661-6ecb9bb5f4c9
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks not specified. Estimated from input data size: 1
In order to change the average load for a reducer (in bytes):
  set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
  set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
  set mapreduce.job.reduces=<number>
Starting Job = job_1585573247854_0001, Tracking URL = http://master:18088/proxy/application_1585573247854_0001/
Kill Command = /usr/hadoop/hadoop-2.7.3/bin/hadoop job  -kill job_1585573247854_0001
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 1
2020-03-30 23:16:37,906 Stage-1 map = 0%,  reduce = 0%
2020-03-30 23:16:54,728 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 8.5 sec
2020-03-30 23:17:12,782 Stage-1 map = 100%,  reduce = 100%, Cumulative CPU 16.93 sec
MapReduce Total cumulative CPU time: 16 seconds 930 msec
Ended Job = job_1585573247854_0001
Loading data to table default.phy_opt_count
MapReduce Jobs Launched: 
Stage-Stage-1: Map: 1  Reduce: 1   Cumulative CPU: 16.93 sec   HDFS Read: 101059 HDFS Write: 216 SUCCESS
Total MapReduce CPU Time Spent: 16 seconds 930 msec
OK
Time taken: 61.419 seconds
hive> select * from phy_opt_count;
OK
badminton	234
basketball	224
football	206
gymnastics	220
opt_cour	0
swimming	234
table tennis	277
taekwondo	222
tennis	223
volleyball	209
Time taken: 0.156 seconds, Fetched: 10 row(s)

  1. 使用 Hive 工具来查找出 phy_course_score_xd.txt 文件中某高校Software_1403 班级体育选修成绩在 90 分以上的成员所有信息,其中phy_course_score_xd.txt 文件数据结构如下表所示,选修科目字段为 opt_cour,成绩字段为 score。

在这里插入图片描述

hive> create table phy_course_score_xd (stname string,stID int,class string,opt_cour string,score float) row format delimited fields terminated by '\t' lines terminated by '\n';
OK
Time taken: 3.367 seconds
hive> load data local inpath'/root/tiku/Hive/phy_course_score_xd.txt' into table phy_course_score_xd;
Loading data to table default.phy_course_score_xd
OK
Time taken: 2.704 seconds
hive> select * from phy_course_score_xd where class='Software_1403' and score>90;
OK
student403	10120402	Software_1403	swimming	94.0
student413	10120412	Software_1403	volleyball	91.8
student427	10120426	Software_1403	taekwondo	98.6
student428	10120427	Software_1403	table tennis	91.4
student449	10120448	Software_1403	badminton	97.9
Time taken: 3.008 seconds, Fetched: 5 row(s)

  1. 使用 Hive 工具来统计 phy_course_score_xd.txt 文件中某高校各个班级体育课的平均成绩,使用 round 函数保留两位小数。其中 phy_course_score_xd.txt文件数据结构如下表所示,班级字段为 class,成绩字段为 score。

在这里插入图片描述

hive> select class,round(avg(score),2) from phy_course_score_xd group by class;
WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
Query ID = root_20200331113210_24c326ce-a5d2-4394-b5d3-48e9b94de263
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks not specified. Estimated from input data size: 1
In order to change the average load for a reducer (in bytes):
  set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
  set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
  set mapreduce.job.reduces=<number>
Starting Job = job_1585624368328_0002, Tracking URL = http://master:18088/proxy/application_1585624368328_0002/
Kill Command = /usr/hadoop/hadoop-2.7.3/bin/hadoop job  -kill job_1585624368328_0002
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 1
2020-03-31 11:32:25,660 Stage-1 map = 0%,  reduce = 0%
2020-03-31 11:32:37,608 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 5.31 sec
2020-03-31 11:32:48,501 Stage-1 map = 100%,  reduce = 100%, Cumulative CPU 11.23 sec
MapReduce Total cumulative CPU time: 11 seconds 230 msec
Ended Job = job_1585624368328_0002
MapReduce Jobs Launched: 
Stage-Stage-1: Map: 1  Reduce: 1   Cumulative CPU: 11.23 sec   HDFS Read: 111370 HDFS Write: 1313 SUCCESS
Total MapReduce CPU Time Spent: 11 seconds 230 msec
OK
ClOfih_1401	80.83
ClOfih_1402	79.59
ClOfih_1403	79.75
ClOfih_1404	79.35
ClOfih_1405	79.43
ClOfih_1406	83.18
ClOfih_1407	82.25
Computer_1401	79.25
Computer_1402	82.06
Computer_1403	79.63
Computer_1404	80.84
Computer_1405	79.75
IntOfTh_1401	83.21
IntOfTh_1402	79.22
IntOfTh_1403	79.59
IntOfTh_1404	79.59
IntOfTh_1405	80.54
IntOfTh_1406	80.26
IntOfTh_1407	81.36
IntOfTh_1408	79.63
IntOfTh_1409	78.21
Mobile_1401	82.44
Mobile_1402	79.36
Mobile_1403	78.8
Mobile_1404	80.21
Mobile_1405	80.29
Mobile_1406	80.79
Network_1401	80.83
Network_1402	80.97
Network_1403	80.65
Network_1404	80.47
Network_1405	79.2
Software_1401	79.2
Software_1402	81.03
Software_1403	81.49
Software_1404	80.15
Software_1405	80.18
Software_1406	79.51
Software_1407	81.07
class	NULL
Time taken: 40.442 seconds, Fetched: 40 row(s)

  1. 使用 Hive 工具来统计 phy_course_score_xd.txt 文件中某高校各个班级体育课的最高成绩。其中 phy_course_score_xd.txt 文件数据结构如下表所示,班级字段为 class,成绩字段为 score。

在这里插入图片描述

hive> select class,max(score) from phy_course_score_xd group by class;
WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
Query ID = root_20200331113621_7d430176-398a-4d0d-be0e-17688fa4967b
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks not specified. Estimated from input data size: 1
In order to change the average load for a reducer (in bytes):
  set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
  set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
  set mapreduce.job.reduces=<number>
Starting Job = job_1585624368328_0003, Tracking URL = http://master:18088/proxy/application_1585624368328_0003/
Kill Command = /usr/hadoop/hadoop-2.7.3/bin/hadoop job  -kill job_1585624368328_0003
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 1
2020-03-31 11:36:36,187 Stage-1 map = 0%,  reduce = 0%
2020-03-31 11:36:55,042 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 9.65 sec
2020-03-31 11:37:05,837 Stage-1 map = 100%,  reduce = 100%, Cumulative CPU 14.41 sec
MapReduce Total cumulative CPU time: 14 seconds 410 msec
Ended Job = job_1585624368328_0003
MapReduce Jobs Launched: 
Stage-Stage-1: Map: 1  Reduce: 1   Cumulative CPU: 14.41 sec   HDFS Read: 110404 HDFS Write: 1278 SUCCESS
Total MapReduce CPU Time Spent: 14 seconds 410 msec
OK
ClOfih_1401	99.2
ClOfih_1402	97.0
ClOfih_1403	90.8
ClOfih_1404	98.7
ClOfih_1405	98.7
ClOfih_1406	99.4
ClOfih_1407	99.8
Computer_1401	100.0
Computer_1402	99.2
Computer_1403	98.3
Computer_1404	98.6
Computer_1405	98.1
IntOfTh_1401	98.7
IntOfTh_1402	98.6
IntOfTh_1403	94.7
IntOfTh_1404	99.3
IntOfTh_1405	97.1
IntOfTh_1406	98.3
IntOfTh_1407	99.3
IntOfTh_1408	98.6
IntOfTh_1409	96.4
Mobile_1401	99.5
Mobile_1402	99.3
Mobile_1403	97.9
Mobile_1404	99.2
Mobile_1405	99.2
Mobile_1406	99.8
Network_1401	97.2
Network_1402	99.7
Network_1403	99.8
Network_1404	99.8
Network_1405	99.9
Software_1401	99.1
Software_1402	99.5
Software_1403	98.6
Software_1404	99.8
Software_1405	99.8
Software_1406	97.7
Software_1407	99.6
class	NULL
Time taken: 45.152 seconds, Fetched: 40 row(s)

  1. 在 Hive 数据仓库将网络日志 weblog_entries.txt 中分开的 request_date 和request_time 字段进行合并,并以一个下划线“_”进行分割,如下图所示,其中 weblog_entries.txt 的数据结构如下表所示。

在这里插入图片描述

hive> create table weblog_entries (md5 STRING,url STRING,request_date STRING,request_time STRING,ip STRING) row format delimited fields terminated by '\t' lines terminated by '\n';

hive> load data local inpath'/root/tiku/Hive/weblog_entries.txt' into table weblog_entries;
hive> select concat_ws('_', request_date,request_time) from weblog_entries;
2012-05-10_21:29:01
2012-05-10_21:13:47
2012-05-10_21:12:37
2012-05-10_21:34:20
2012-05-10_21:27:00
2012-05-10_21:33:53
2012-05-10_21:10:19
2012-05-10_21:12:05
2012-05-10_21:25:58
2012-05-10_21:34:28
。。。。。。

  1. 在 Hive 数据仓库将网络日志 weblog_entries.txt 中的 IP 字段与ip_to_country 中 IP 对应的国家进行简单的内链接,输出结果如下图所示,其中 weblog_entries.txt 的数据结构如下表所示。

在这里插入图片描述

hive> create table ip_to_country (ip string,country string) row format delimited fields terminated by '\t' lines terminated by '\n';
OK
Time taken: 0.167 seconds
hive> load data local inpath'/root/tiku/Hive/ip_to_country.txt' into table ip_to_country;
Loading data to table default.ip_to_country
OK
Time taken: 0.613 seconds
hive> select wlg.*,itc.country from weblog_entries wlg join ip_to_country itc on wlg.ip=itc.ip;
22b2549649dcc284ba8bf7d4993ac62	/e.html	2012-05-10	21:12:05	105.57.100.182	Morocco
3ab7888ffe27c2f98d48eb296449d5	/khvc.html	2012-05-10	21:25:58	111.147.83.42	China
65827078a9f7ccce59632263294782db	/c.html	2012-05-10	21:34:28	137.157.65.89	Australia

  1. 使用 Hive 动态地关于网络日志 weblog_entries.txt 的查询结果创建 Hive表。通过创建一张名为 weblog_entries_url_length 的新表来定义新的网络日志数据库的三个字段,分别是 url,request_date,request_time。此外,在表中定义一个获取 url 字符串长度名为“url_length”的新字段,其中weblog_entries.txt 的数据结构如下表所示。完成后查询weblog_entries_url_length 表文件内容。
hive> create table weblog_entries_url_length as select url, request_date, request_time,length(url) as url_length from weblog_entries;
hive> select * from weblog_entries_url_length;
/hjmdhaoogwqhp.html	2012-05-10	21:34:20	19
/angjbmea.html	2012-05-10	21:27:00	14
/mmdttqsnjfifkihcvqu.html	2012-05-10	21:33:53	25
/eorxuryjadhkiwsf.html	2012-05-10	21:10:19	22
/e.html	2012-05-10	21:12:05	7
/khvc.html	2012-05-10	21:25:58	10
/c.html	2012-05-10	21:34:28	7

在此感谢先电云提供的题库。
感谢Apache开源技术服务支持
感谢抛物线、mn525520、菜鸟一枚2019三位博主的相关博客。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: Cloudera Manager是一款用于大数据平台的管理工具,它提供了一套集中化的控制台和工具,用于对大数据平台进行运维操作。 Cloudera Manager的主要功能包括集群管理、监控和警报、服务配置和升级、安全性管理等。在使用Cloudera Manager进行大数据平台运维操作时,可以按照以下步骤进行: 1. 创建集群:在Cloudera Manager控制台中,可以通过向导式界面创建新的集群。在创建过程中需要指定集群的名称、主机节点、角色和服务等。 2. 管理服务:通过Cloudera Manager可以管理各个服务的配置和状态。可以对服务进行启动、停止、重新启动等操作,并进行监控和警报设置。 3. 配置管理:Cloudera Manager提供了一套灵活的配置管理系统,可以对各个服务的配置进行修改和管理。可以根据需求对数据节点、NameNode、YARN资源管理器等进行配置优化。 4. 升级管理:Cloudera Manager支持集群的升级操作,可以通过控制台进行版本升级,同时提供了预检和回滚功能,确保升级的顺利进行。 5. 安全性管理:Cloudera Manager提供了一套完善的安全性管理系统,可以配置SSL加密和认证,管理Kerberos认证和授权,并且支持集成第三方安全工具。 6. 监控和警报:Cloudera Manager可以实时监控集群的状态和性能,并设置警报规则。可以查看CPU、内存、磁盘使用率、任务运行情况等,并及时发送警报邮件或短信。 7. 故障排除:Cloudera Manager提供了故障排除工具和日志管理。可以查看集群和服务的日志,定位和解决故障。 总而言之,Cloudera Manager是一款功能强大的大数据平台运维工具,通过它可以方便地管理和操作大数据平台的各个组件和服务。它提供了一套集中化的管理和监控系统,简化了大数据平台运维工作,提高了运维效率。 ### 回答2: Cloudera Manager是一个大数据平台运维工具,它提供了一种简化和自动化管理和监控大数据集群的方法。以下是Cloudera Manager大数据平台运维操作的指南: 1. 安装和配置:首先,需要下载并安装Cloudera Manager。安装完成后,打开Cloudera Manager Web界面,配置一些基本信息,如主机名、端口号和数据库等。 2. 集群管理:接下来,需要添加和管理集群。在Cloudera Manager中,可以通过“添加服务”来选择要安装和配置的各种组件,如Hadoop、Hive、HBase等。然后,将主机添加到集群中,分配相应的角色和服务。 3. 监控和调优:Cloudera Manager提供了强大的监控和调优功能,可以实时监控集群的健康状况和性能指标。可以设置警报,并快速诊断和解决潜在的问题。此外,Cloudera Manager还提供了性能调优建议和自动化调整资源配置的功能。 4. 管理和维护:Cloudera Manager简化了大数据平台的管理和维护工作。可以使用Cloudera Manager进行软件升级和补丁管理,以确保集群的安全和稳定性。此外,还可以执行备份和恢复操作,保护数据的安全性。 5. 安全和权限管理:Cloudera Manager提供了安全和权限管理功能,可确保集群和数据的安全性。可以配置用户、组和角色,并为不同的用户分配不同的权限。此外,还可以配置加密和防火墙等安全措施。 总之,Cloudera Manager是一个强大而全面的大数据平台运维工具,通过简化和自动化管理和监控任务,帮助管理员提高工作效率,保证集群的高可用性和性能。 ### 回答3: Cloudera Manager是一种用于大数据平台运维管理工具,通过简化操作和提供全面的监控功能,帮助管理员更轻松地管理和维护大数据集群。以下是Cloudera Manager的运维操作指南: 1. 安装和配置:首先需要安装Cloudera Manager,并按照指引配置相关参数,包括集群规模、节点配置、网络设置等。 2. 群集管理:Cloudera Manager提供了一种简便的方式来管理大数据集群。管理员可以通过Cloudera Manager界面添加、删除和管理集群中的节点,实现扩容和缩容的操作。 3. 监控和诊断:Cloudera Manager提供了丰富的监控指标和仪表盘,可以实时监控集群的各个组件和服务的状态。管理员可以通过查看日志和警报来检查并解决潜在的问题。 4. 资源管理:Cloudera Manager提供了资源管理和调度功能,可以根据集群的负载情况自动调整资源分配。管理员可以设置资源配额和优先级,确保集群资源的高效利用。 5. 配置管理:通过Cloudera Manager,管理员可以集中管理集群中的配置文件和参数。可以方便地修改和应用配置,确保集群的稳定性和一致性。 6. 升级和扩展:Cloudera Manager支持集群的升级和扩展。管理员可以使用升级向导来进行版本升级,并使用扩展向导来添加新的节点和服务。 7. 安全管理:Cloudera Manager提供了安全管理功能,可以实现对集群中数据的加密、权限控制和访问控制。管理员可以通过Cloudera Manager来配置和管理安全策略。 通过以上的运维操作指南,管理员可以更好地利用Cloudera Manager来管理和维护大数据平台,提高运维效率和系统稳定性。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

希望不是梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值