Hive安装基于mysql元数据

2017-05-13  本文已影响375人  大龄程序员在帝都

1、下载hive

wget http://ftp.meisei-u.ac.jp/mirror/apache/dist/hive/hive-1.2.2/apache-hive-1.2.2-bin.tar.gz

2、解压

tar -xzvf apache-hive-1.2.2-bin.tar.gz

3、配置环境变量

export HIVE_HOME=/home/apache-hive-1.2.2-bin
export PATH=$PATH:$HIVE_HOME/bin

4、测试安装成功
在任意位置输入hive,会出现以下两个文件,因为默认hive 元数据的存储是基于derby数据库的,所以在对应的目录会生成这样两个文件,这种方式是基于session的,当新建一个文件夹以后,再次访问hive,上次创建的表就会没有了,为了保证所有元数据共享访问,所以采用mysql存储元数据信息

image.png

5、mysql存储Hive元数据信息
在mysql中创建数据库hive
在hive-site.xml中修改连接配置,连接到mysql
首先修改以下配置文件

<property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://106.75.xx.162:3306/hive?createDatabaseIfNotExist=true</value>
    <description>JDBC connect string for a JDBC metastore</description>
  </property>
<property>  
 <name>javax.jdo.option.ConnectionDriverName</name>  
  <value>com.mysql.jdbc.Driver</value>  
  <description>Driver class name for aJDBC metastore</description>  
</property>  
<property>  
 <name>javax.jdo.option.ConnectionUserName</name>  
  <value>root</value>  
  <description>username to use againstmetastore database</description>  
</property>  
<property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>xxxxxx</value>
    <description>password to use against metastore database</description>
  </property>

以上是可以连接到mysql存储Hive元数据的配置

修改hive产生的其他文件的放置位置

<property>
    <name>hive.exec.scratchdir</name>
    <value>/tmp/hive</value>
    <description>HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: ${hive.exec.scratchdir}/<username> is created, with ${hive.scratch.dir.permission}.</description>
  </property>
  <property>
    <name>hive.exec.local.scratchdir</name>
    <value>/tmp/hive</value>
    <description>Local scratch space for Hive jobs</description>
  </property>
  <property>
    <name>hive.downloaded.resources.dir</name>
    <value>/tmp/hive/${hive.session.id}_resources</value>
    <description>Temporary local directory for added resources in the remote file system.</description>
  </property>
  <property>
    <name>hive.scratch.dir.permission</name>
    <value>733</value>
    <description>The permission for the user specific scratch directories that get created.</description>
  </property>

5、启动hive看mysql是否生成对应的表
启动之前首先在mysql上执行可以访问的设置,授权用户可以访问hive数据库,这属于mysql的权限控制

grant all privileges on hive.* to root identified by ‘password’ 

启动之前需要把mysql的连接jar包拷贝到hive的lib目录下,这样hive才能连接操作mysql

image.png
hive

对应mysql生成表信息

image.png

执行部分hive命令操作,证明安装hive成功

image.png
上一篇 下一篇

猜你喜欢

热点阅读