HIVE报告

    xiaoxiao2022-07-14  172

    ①下载压缩包 官网下载地址:http://mirror.bit.edu.cn/apache/hive/ 选择apache-hive-2.3.4-bin.tar.gz,在Windows里面下载。

    ②将压缩包从Windows传输到Linux当前目录下¬¬ SecureCRT 【File】→【Connect SFTP Session】开启sftp操作

    ③解压 解压安装到指定目录下/opt/module(/opt是系统自带目录,之下的/module是自己创建的) 修改解压目录名为hive。

    ④修改环境变量 修改etc/profile文件,添加HIVE_HOME安装路径。 Source命令更新etc/profile文件,使其生效。

    ⑤配置hive-env.sh 进入/opt/module/hive/conf目录,修改hive-env.sh.template的文件名为hive-env.sh。(可以使用cp或者mv命令) cp hive-env.sh.template hive-env.sh 修改Hadoop的安装路径 HADOOP_HOME=/opt/module /hadoop-2.7.3 修改Hive的conf目录的路径 export HIVE_CONF_DIR=/opt/module/hive/conf

    ⑥配置hive-site.xml 进入/opt/module/hive/conf目录,修改default.xml.template的文件名为hive-site.xml。(可以使用cp或者mv命令) cp hive- default.xml.template hive-site.xml

    启动hive ①启动Hadoop:start-all.sh ②初始化Metastore架构:schematool -dbType mysql -initSchema ③启动Hive:hive hive> 进入hive shell ④创建/删除/修改/查看 数据库、表、视图,向表中装载数据,查询数据等等。

    注: ①启动hive报错:Exception in thread “main” java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: KaTeX parse error: Expected '}', got 'EOF' at end of input: …a.io.tmpdir}/{system:user.name},原因是hive-site.xml里的临时目录没有设置好。 修改{system:Java.io.tmpdir}为自己创建的临时目录/opt/module/hive/tmp。

    ②schematool -dbType mysql -initSchema时报错:Schema initialization FAILED! Metastore state would be inconsistent !! 网上教程都是说在文件头部加上mysql的连接配置,但是hive-site.xml.templat中原本是有derby的配置,这样就会被下面的derby配置覆盖,导致初始化失败。方法就是可以将mysql配置放在最下面,或者删除derby的配置。 删除derby的配置产生的metastore_db目录。

    ③hive命令(如show databases ,show tables),会报出如下错误:Failed with exception Java.io.IOException:java.lang.IllegalArgumentException: java.NET.URISyntaxException: Relative path in absolute URI: s y s t e m : u s e r . n a m e 找 到 h i v e − s i t e . x m l 的 < n a m e > h i v e . e x e c . l o c a l . s c r a t c h d i r < / n a m e > 的 值 里 面 的 {system:user.name} 找到hive-site.xml的<name>hive.exec.local.scratchdir</name>的值里面的 system:user.namehivesite.xml<name>hive.exec.local.scratchdir</name>{system.user.name}改为${user.name}。

    Hive应用实例:wordcount ①建数据源文件并上传到hdfs的/user/input目录下 ②建数据源表t1:create table t1 (line string);

    ③装载数据:load data inpath ‘/user/input’ overwrite into table t1;

    ④编写HiveQL语句实现wordcount算法,建表wct1保存计算结果: create table wct1 as select word, count(1) as count from (select explode (split (line, ’ ')) as word from t1) w group by word order by word;

    ⑤查看wordcount计算结果:

    最新回复(0)