
# Hive对接OBS
#### 概述
Hive是一个数据仓库工具，可以对存储在分布式存储中的大规模数据进行数据提取、转化和加载，它提供了丰富的SQL查询方式来进行数据分析。
#### 前提条件
已安装Hadoop，具体请参见[Hadoop对接OBS](https://support.huaweicloud.com/bestpractice-obs/obs_05_1507.html)。
#### 对接步骤
以Hive 2.3.3为例。
1. 下载apache-hive-2.3.3-bin.tar.gz，并解压到/opt/hive-2.3.3。
2. 在/etc/profile文件中增加配置内容： 
   ```
   export HIVE_HOME=/opt/hive-2.3.3
   export PATH=$HIVE_HOME/bin:$PATH
   ```
   
   
3. 配置Hive。 
   1. 重命名/opt/hive-2.3.3/conf/hive-env.sh.template为hive-env.sh。
   
   2. 重命名/opt/hive-2.3.3/conf/hive-log4j2.properties.template为hive-log4j2.properties。
   
   3. 创建hive-site.xml文件，添加配置：
      ```
      <property>
      <name>hive.metastore.warehouse.dir</name>
      <value>obs://obs-bucket/warehouse/hive</value>
      </property>
      ```
      ![](https://support.huaweicloud.com/bestpractice-obs/public_sys-resources/note_3.0-zh-cn.png)
      可选配置，当添加了上述配置后在创建Hive表时将不用再显示指定location，创建的Hive表将自动落在OBS上。
      
   
   4. 执行以下命令，初始化元数据。 **/opt/hive-2.3.3/bin/schematool -dbType derby -initSchema**
      
   
   
   
   
4. 验证是否对接成功。 
   示例如下，示例中的location为obs://obs-bucket/warehouse/hive/student。
   ```
   hive>
   create table student(id int comment "学生id",name string comment "学生姓名",age int comment "学生年龄")
   comment "学生信息表"
   row format delimited fields terminated by ",";
   insert into table student select 6,"yangdong",29;
   ```
   
   
 
