hive搭建 -----内嵌模式和本地模式

打印 上一主题 下一主题

主题 873|帖子 873|积分 2619


一、内嵌模式(使用较少)

1、上传、解压、重命名

2、配置环境变量

export HIVE_HOME=/opt/installs/hive
export PATH=                                   H                         I                         V                                   E                            H                                  O                         M                         E                         /                         b                         i                         n                         :                              HIVE_HOME/bin:                  HIVEH​OME/binATH
3、配置conf下的hive-env.sh

  1. cd /opt/installs/hive/conf
  2. # 1.复制改名:
  3. cp hive-env.sh.template hive-env.sh
  4. # 2.并修改:
  5. export HIVE_CONF_DIR=/opt/installs/hive/conf
  6. export JAVA_HOME=/opt/installs/jdk
  7. export HADOOP_HOME=/opt/installs/hadoop
  8. export HIVE_AUX_JARS_PATH=/opt/installs/hive/lib
复制代码
4、修改conf下的hive-site.xml

  1. cd /opt/installs/hive/conf
  2. # 1.复制改名:
  3. cp hive-default.xml.template hive-site.xml
  4. # 2.并修改:
  5. 把Hive-site.xml 中所有包含${system:java.io.tmpdir}替换成/opt/installs/hive/tmp
  6. 把Hive-site.xml 中所有包含${system:user.name}替换成当前用户名root
复制代码
5、启动hadoop集群

  1. start-all.sh
复制代码
6、给hdfs创建文件夹

  1. # 1.创建:
  2. hdfs dfs -mkdir -p /user/hive/warehouse
  3. hdfs dfs -mkdir -p /tmp/hive/
  4. # 2.赋权:
  5. hdfs dfs -chmod 750 /user/hive/warehouse
  6. hdfs dfs -chmod 777 /tmp/hive
复制代码
7、修改hive-site.xml中的非法字符

在hive-site.xml中,3211行,96列的地方有一个非法字符,删除即可
8、初始化元数据

由于是内嵌模式,所以使用的数据库是derby:
  1. schematool --initSchema -dbType derby
复制代码
9、测试是否成功

输入hive 进入后,可以编写sql
10、内嵌模式的缺点

假如有一个窗口在使用你的hive,另一个窗口能进入,但是实行sql语句时会报错!
二、本地模式(最常用)

1、查抄mysql是否正常

  1. systemctl status mysqld
复制代码
2、上传、解压、重命名

3、配置环境变量

  1. # 1.编辑
  2. vim /etc/profile:
  3. export HIVE_HOME=/opt/installs/hive
  4. export PATH=$HIVE_HOME/bin:$PATH
  5. # 2.刷新:
  6. source /etc/profile
复制代码
4、修改conf下的hive-env.sh

  1. cd /opt/installs/hive/conf
  2. # 1.重命名:
  3. mv hive-env.sh.template hive-env.sh
  4. # 2.并添加:
  5. export HIVE_CONF_DIR=/opt/installs/hive/conf
  6. export JAVA_HOME=/opt/installs/jdk
  7. export HADOOP_HOME=/opt/installs/hadoop
  8. export HIVE_AUX_JARS_PATH=/opt/installs/hive/lib
复制代码
5、修改conf下的hive-site.xml

  1. cd /opt/installs/hive/conf
  2. # 1.重命名:
  3. mv hive-default.xml.template hive-site.xml
  4. # 2.修改(将hive-site.xml文件所有内容删除并添加以下配置):
  5. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  6. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--
  7.    Licensed to the Apache Software Foundation (ASF) under one or more
  8.    contributor license agreements.  See the NOTICE file distributed with
  9.    this work for additional information regarding copyright ownership.
  10.    The ASF licenses this file to You under the Apache License, Version 2.0
  11.    (the "License"); you may not use this file except in compliance with
  12.    the License.  You may obtain a copy of the License at
  13.        http://www.apache.org/licenses/LICENSE-2.0
  14.    Unless required by applicable law or agreed to in writing, software
  15.    distributed under the License is distributed on an "AS IS" BASIS,
  16.    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17.    See the License for the specific language governing permissions and
  18.    limitations under the License.
  19. --><configuration>
  20. <!--配置MySql的连接字符串-->
  21. <property>
  22.   <name>javax.jdo.option.ConnectionURL</name>
  23.   <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
  24. </property>
  25. <!--配置MySql的连接驱动-->
  26. <property>
  27.   <name>javax.jdo.option.ConnectionDriverName</name>
  28.   <value>com.mysql.cj.jdbc.Driver</value>
  29. </property>
  30. <!--配置登录MySql的用户-->
  31. <property>
  32.   <name>javax.jdo.option.ConnectionUserName</name>
  33.   <value>root</value>
  34. </property>
  35. <!--配置登录MySql的密码-->
  36. <property>
  37.   <name>javax.jdo.option.ConnectionPassword</name>
  38.   <value>123456</value>
  39. </property>
  40. <!-- 以下两个不需要修改,只需要了解即可 -->
  41. <!-- 该参数主要指定Hive的数据存储目录  -->
  42. <property>
  43.     <name>hive.metastore.warehouse.dir</name>
  44.     <value>/user/hive/warehouse</value>
  45.   </property>
  46. <!-- 该参数主要指定Hive的临时文件存储目录  -->
  47. <property>
  48.     <name>hive.exec.scratchdir</name>
  49.     <value>/tmp/hive</value>
  50.   </property>
  51. </configuration>
复制代码
6、启动hadoop集群

  1. start-all.sh
复制代码
7、给hdfs创建文件夹

  1. # 1.创建:
  2. hdfs dfs -mkdir -p /user/hive/warehouse
  3. hdfs dfs -mkdir -p /tmp/hive/
  4. # 2.赋权:
  5. hdfs dfs -chmod 750 /user/hive/warehouse
  6. hdfs dfs -chmod 777 /tmp/hive
复制代码
8、将mysql的驱动包,上传至 hive 的lib 文件夹下

mysql-connector-java-xxxx-jar
9、初始化元数据

  1. schematool --initSchema -dbType mysql
复制代码
10、测试

输入hive 进入后,可以编写sql
  1. -- 创建表的时候,string类型不需要指定字符长度
  2. create table `user` (id int,name string);
  3. -- 创建表的时候,varchar类型需要指定字符长度,否则报错!
  4. create table `user` (id int,name varchar(20));
  5. -- insert 语句 走MR任务 比较慢
  6. insert into `user` values(1,'wangcai');
  7. -- 包含*的全表查询和包含*的limit查询,不走MR任务
  8. select * from `user`;
  9. select * from `user` limit 10;
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

飞不高

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表