Hive 安装部署

- 日理万妓 2022-02-13 18:25 315阅读 0赞

本次用的是伪集群模式,只用了一台hadoop101。公司电脑配置有点低,伤不起。
2019-04-28-15564346078522.jpg

本次使用的hive版本1.2.1,下载地址:http://archive.apache.org/dist/hive/

安装及配置

上传并解压安装包
  1. 把 apache-hive-1.2.1-bin.tar.gz 上传到 linux 的/opt/software 目录下
  2. 解压 apache-hive-1.2.1-bin.tar.gz 到/opt/module/目录下面

    [root@hadoop101 software]# tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /opt/module/

配置

1 修改 apache-hive-1.2.1-bin.tar.gz 的名称为 hive-1.2.1

  1. [root@hadoop101 module]# mv apache-hive-1.2.1-bin hive-1.2.1

2 修改/opt/module/hive/conf 目录下的 hive-env.sh.template 名称为 hive-env.sh

  1. [root@hadoop101 hive-1.2.1]# cd conf/
  2. [root@hadoop101 conf]# ll
  3. 总用量 188
  4. -rw-rw-r--. 1 root root 1139 4 30 2015 beeline-log4j.properties.template
  5. -rw-rw-r--. 1 root root 168431 6 19 2015 hive-default.xml.template
  6. -rw-rw-r--. 1 root root 2378 4 30 2015 hive-env.sh.template
  7. -rw-rw-r--. 1 root root 2662 4 30 2015 hive-exec-log4j.properties.template
  8. -rw-rw-r--. 1 root root 3050 4 30 2015 hive-log4j.properties.template
  9. -rw-rw-r--. 1 root root 1593 4 30 2015 ivysettings.xml
  10. [root@hadoop101 conf]# mv hive-env.sh.template hive-env.sh

3 配置hive-env.sh

配置 HADOOP_HOME 路径

  1. export HADOOP_HOME=/opt/module/hadoop-2.7.2

配置 HIVE_CONF_DIR 路径

  1. export HIVE_CONF_DIR=/opt/module/hive/conf

2019-04-28-15564341029048.jpg

4 配置 /etc/profile

  1. ##HIVE_HOME
  2. export HIVE_HOME=/opt/module/hive-1.2.1
  3. export PATH=$PATH:$HIVE_HOME/bin

Hadoop 集群配置

1 必须启动 hdfs 和 yarn

  1. [root@hadoop101 hadoop-2.7.2]# sbin/start-dfs.sh
  2. [root@hadoop101 hadoop-2.7.2]# sbin/start-yarn.sh

2 在 HDFS 上创建/tmp 和/user/hive/warehouse 两个目录并修改他们的同组权限可写

  1. [root@hadoop101 ~]# hdfs dfs -mkdir /tmp
  2. [root@hadoop101 ~]# hdfs dfs -mkdir -p /user/hive/warehouse
  3. [root@hadoop101 ~]# hdfs dfs -chmod 777 /tmp
  4. [root@hadoop101 ~]# hdfs dfs -chmod 777 /user/hive/warehouse

Hive 基本操作

  1. [root@hadoop101 ~]# hive -h
  2. Unrecognized option: -h
  3. usage: hive
  4. -d,--define <key=value> Variable subsitution to apply to hive
  5. commands. e.g. -d A=B or --define A=B
  6. --database <databasename> Specify the database to use
  7. -e <quoted-query-string> SQL from command line
  8. -f <filename> SQL from files
  9. -H,--help Print help information
  10. --hiveconf <property=value> Use value for given property
  11. --hivevar <key=value> Variable subsitution to apply to hive
  12. commands. e.g. --hivevar A=B
  13. -i <filename> Initialization SQL file
  14. -S,--silent Silent mode in interactive shell
  15. -v,--verbose Verbose mode (echo executed SQL to the
  16. console)
启动hive
  1. [root@hadoop101 ~]# hive
  2. Logging initialized using configuration in jar:file:/opt/module/hive-1.2.1/lib/hive-common-1.2.1.jar!/hive-log4j.properties
  3. hive>
查看数据库
  1. hive> show databases;
  2. OK
  3. default
  4. Time taken: 0.932 seconds, Fetched: 1 row(s)
打开默认数据库
  1. hive> use default;
  2. OK
  3. Time taken: 0.031 seconds
显示default中所有的表
  1. hive> show tables;
  2. OK
  3. Time taken: 0.056 seconds

目前还没有表

创建一个表
  1. hive> create table student(id int,name string);
  2. OK
  3. Time taken: 0.584 seconds
  4. hive> show tables;
  5. OK
  6. student
  7. Time taken: 0.039 seconds, Fetched: 1 row(s)
查看表结构
  1. hive> desc student;
  2. OK
  3. id int
  4. name string
  5. Time taken: 0.137 seconds, Fetched: 2 row(s)
向表中插入数据
  1. hive> insert into student values (1,'zhangsan');
  2. Query ID = root_20190401073825_9b6c4f84-e5ee-4a7d-9f63-03702a90c80f
  3. Total jobs = 3
  4. Launching Job 1 out of 3
  5. Number of reduce tasks is set to 0 since there's no reduce operator
  6. Starting Job = job_1554074575208_0001, Tracking URL = http://hadoop101:8088/proxy/application_1554074575208_0001/
  7. Kill Command = /opt/module/hadoop-2.7.2/bin/hadoop job -kill job_1554074575208_0001
  8. Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 0
  9. 2019-04-01 07:38:44,534 Stage-1 map = 0%, reduce = 0%
  10. 2019-04-01 07:38:56,752 Stage-1 map = 100%, reduce = 0%, Cumulative CPU 2.09 sec
  11. MapReduce Total cumulative CPU time: 2 seconds 90 msec
  12. Ended Job = job_1554074575208_0001
  13. Stage-4 is selected by condition resolver.
  14. Stage-3 is filtered out by condition resolver.
  15. Stage-5 is filtered out by condition resolver.
  16. Moving data to: hdfs://hadoop101:9000/user/hive/warehouse/student/.hive-staging_hive_2019-04-01_07-38-25_714_6570492894469965354-1/-ext-10000
  17. Loading data to table default.student
  18. Table default.student stats: [numFiles=1, numRows=1, totalSize=11, rawDataSize=10]
  19. MapReduce Jobs Launched:
  20. Stage-Stage-1: Map: 1 Cumulative CPU: 2.09 sec HDFS Read: 3560 HDFS Write: 82 SUCCESS
  21. Total MapReduce CPU Time Spent: 2 seconds 90 msec
  22. OK
  23. Time taken: 33.972 seconds

2019-04-28-15564353590787.jpg

查询表中的数据
  1. hive> select * from student;
  2. OK
  3. 1 zhangsan
  4. Time taken: 0.316 seconds, Fetched: 1 row(s)
退出hive
  1. hive> quit;
  2. [root@hadoop101 ~]#

注意事项

默认情况下,Hive中metastore(元数据存储)的三种方式:

  1. 内嵌Derby方式
  2. Local方式
  3. Remote方式

参考文章 【hive】——metastore的三种模式

Hive默认的启动模式是内嵌Derby方式,一般用于单元测试,这种存储方式有一个缺点:在同一时间只能有一个进程连接使用数据库。下一篇解决这个问题。

发表评论

表情:
评论列表 (有 0 条评论,315人围观)

还没有评论,来说两句吧...

相关阅读

    相关 hive安装部署

    一、Hive 运行模式 与 Hadoop 类似,Hive 也有 3 种运行模式: > 1. 内嵌模式 > > 将元数据保存在本地内嵌的 Derby 数据库中,这是使用