hive 安装

来源:互联网 发布:离婚率 知乎 编辑:程序博客网 时间:2024/05/22 13:01


前提,需要安装hadoop 2.7

与 Hadoop 类似,Hive 也有 3 种运行模式:

1. 内嵌模式

将元数据保存在本地内嵌的 Derby 数据库中,这是使用 Hive 最简单的方式。但是这种方式缺点也比较明显,因为一个内嵌的 Derby 数据库每次只能访问一个数据文件,这也就意味着它不支持多会话连接。

2. 本地模式

这种模式是将元数据保存在本地独立的数据库中(一般是 MySQL),这用就可以支持多会话和多用户连接了。

3. 远程模式

此模式应用于 Hive 客户端较多的情况。把 MySQL 数据库独立出来,将元数据保存在远端独立的 MySQL 服务中,避免了在每个客户端都安装 MySQL 服务从而造成冗余浪费的情况。


下载:http://mirrors.hust.edu.cn/apache/hive/hive-2.1.1/apache-hive-2.1.1-bin.tar.gz


解压:

tar -zxvf apache-hive-2.1.1-bin.tar.gz

拷贝

mv apache-hive-2.1.1-bin /usr/local/hive


设置环境变量

vim /etc/profile

  1. 设置 Hive环境变量  
  2. # Hive environment  
  3. export HIVE_HOME=/usr/local/hive
  4. export PATH=$HIVE_HOME/bin:$HIVE_HOME/conf:$PATH  

生效修改配制

source /etc/profile


修改配制文件:

  1. cd /usr/local/hive/conf
  2. cp hive-default.xml.template hive-site.xml  
  3. cp hive-env.sh.template  hive-env.sh


  • hive.metastore.warehouse.dir
    该参数指定了 Hive 的数据存储目录,默认位置在 HDFS 上面的 /user/hive/warehouse 路径下。

  • hive.exec.scratchdir
    该参数指定了 Hive 的数据临时文件目录,默认位置为 HDFS 上面的 /tmp/hive 路径下。



vim hive-env.sh
修改如下位置
HADOOP_HOME=/usr/local/hadoop

export HIVE_CONF_DIR=/usr/local/hive/conf

export HIVE_AUX_JARS_PATH=/usr/local/hive/lib


hdfs上创建必要的目录 


/bin/hdfs dfs -mkdir -p /user/hive/warehouse

/bin/hdfs dfs -mkdir -p /tmp/hive/

hdfs dfs -chmod 777 /usr/hive/warehouse

hdfs dfs -chmod 777 /tmp/hive

  1. hadoop fs -chmod 777 /user/hive/warehouse  
  2. hadoop fs -chmod 777 /tmp/hive  



修改 hive-site.xml

vim hive-site.xml

hive.exec.local.scratchdir

     ${system:java.io.tmpdir}/${ system:user.name}

改成:

    hive.exec.local.scratchdir

    /data0/hive/${ user.name}


修改元数据存储位置

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3. <configuration>  
  4.    <property>  
  5.         <name>javax.jdo.option.ConnectionURL</name>  
  6.         <value>jdbc:mysql://192.168.169.134:3306/hive?createDatabaseIfNotExist=true</value>  
  7.     </property>  
  8.     <property>  
  9.         <name>javax.jdo.option.ConnectionDriverName</name>  
  10.         <value>com.mysql.jdbc.Driver</value>  
  11.     </property>  
  12.     <property>  
  13.         <name>javax.jdo.option.ConnectionUserName</name>  
  14.         <value>root</value>  
  15.     </property>  
  16.     <property>  
  17.         <name>javax.jdo.option.ConnectionPassword</name>  
  18.         <value>123456</value>  
  19.     </property>  
  20.     <property>    
  21.    <name>hive.metastore.schema.verification</name>    
  22.    <value>false</value>    
  23.     <description>    
  24.     Enforce metastore schema version consistency.    
  25.     True: Verify that version information stored in metastore matches with one from Hive jars.  Also disable automatic    
  26.           schema migration attempt. Users are required to manully migrate schema after Hive upgrade which ensures    
  27.           proper metastore schema migration. (Default)    
  28.     False: Warn if the version information stored in metastore doesn't match with one from in Hive jars.    
  29.     </description>    
  30.  </property>   
  31. </configuration>  

下载msyql 驱动

https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.44.tar.gz

解压后,将里边的jar包,放入 /usr/local/hive/lib目录 中。

数据库初始化

bin/schematool -initSchema -dbType mysql 

运行 bin/hive

hive> show databases;
OK
default
Time taken: 1.301 seconds, Fetched: 1 row(s)



原创粉丝点击