【Hive一】Hive安装及配置

Hive安装及配置

下载hive安装包

此处以hive-0.13.1-cdh5.3.6版本的为例,包名为:hive-0.13.1-cdh5.3.6.tar.gz

解压Hive到安装目录

$ tar -xvf hive-0.13.1-cdh5.3.6.tar.gz

重命名配置文件

mv hive-default.xml.template hive-site.xml

mv hive-env.sh.template hive-env.sh

mv hive-log4j.properties.template hive-log4j.properties

hive-env.sh文件

JAVA_HOME=/usr/local/src/jdk1.8.0_121

HADOOP_HOME=/usr/local/src/hadoop-2.5.0-cdh5.3.6

export HIVE_CONF_DIR=/usr/local/src/hive-0.13.1-cdh5.3.6/conf

hive-site.xml文件

<property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://master:3306/metastore?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 a JDBC metastore</description>
</property>

<property>
    <name>javax.jdo.option.ConnectionUserName</name>
    <value>root</value>
    <description>username to use against metastore database</description>
</property>

<property>
    <name>javax.jdo.option.ConnectionPassword</name>
    <value>123456</value>
    <description>password to use against metastore database</description>
</property>

<!--显示数据库名称以及字段名称-->
<!-- 是否在当前客户端中显示查询出来的数据的字段名称 -->
<property>
  <name>hive.cli.print.header</name>
  <value>true</value>
  <description>Whether to print the names of the columns in query output.</description>
</property>

<!-- 是否在当前客户端中显示当前所在数据库名称 -->
<property>
  <name>hive.cli.print.current.db</name>
  <value>true</value>
  <description>Whether to include the current database in the Hive prompt.</description>
</property>

<!--简单HiveSql绕过MR配置-->
<property>
    <name>hive.fetch.task.conversion</name>
    <value>more</value>
    <description>
    Some select queries can be converted to single FETCH task minimizing latency.
    Currently the query should be single sourced not having any subquery and should not have
    any aggregations or distincts (which incurs RS), lateral views and joins.
    1. minimal : SELECT STAR, FILTER on partition columns, LIMIT only
    2. more    : SELECT, FILTER, LIMIT only (TABLESAMPLE, virtual columns)
    </description>
</property>

注意:该版本中hive-site.xml文件在2787h行附近缺少了<property>标签

hive-log4j.properties

hive.log.dir=/usr/local/src/hive-0.13.1-cdh5.3.6/logs

安装Mysql

su - root

yum -y install mysql mysql-server mysql-devel

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

rpm -ivh mysql-community-release-el7-5.noarch.rpm

yum -y install mysql-community-server

配置Mysql

  • 开启Mysql服务

    systemctl start mysqld.service

  • 设置root用户密码

    mysqladmin -uroot password '123456'

  • 为用户以及其他机器节点授权

    mysql grant all on . to root@'master' identified by '123456';

    grant:授权

    all:所有权限

    .:数据库名称.表名称

    root:操作mysql的用户

    @'':主机名

    密码:123456

    完成之后刷新:flush privileges;

  • 拷贝数据库驱动包到Hive根目录下的lib文件夹

    cp -a mysql-connector-java-5.1.27-bin.jar /usr/local/src/hive-0.13.1-cdh5.3.6/lib/

启动Hive

bin/hive

修改HDFS系统中关于Hive的一些目录权限

/usr/local/src/hadoop-2.7.2/bin/hadoop fs -chmod 777 /tmp/

/usr/local/src/hadoop-2.7.2/bin/hadoop fs -chmod 777 /user/hive/warehouse

创建数据库

create database school;

创建表操作

create table t1(eid int, name string, sex string) row format delimited fields terminated by '\t';

导入数据到hive表

  • 从本地导入:

    load data local inpath '文件路径' into table 库名.表名;(此步骤已经将文件上传到HDFS了)

  • 从HDFS系统导入

Hive历史命令存放地

cat ~/.hivehistory

主要用于排查逻辑错误或者查看常用命令

Hive临时生效设置

固定语法:set 属性名=属性值

例如:set hive.cli.print.header=false;

posted @ 2018-05-06 18:07  Lil-K  阅读(624)  评论(0编辑  收藏  举报