hadoop2.7连接mysql,hive2.1.0安装(hadoop2.7.2环境)

1. 介绍

安装hive的前提是你已经成功安装hadoop。如果不会可以查看我的文章hadoop2.7.2+spark1.6.2环境搭建教程

2. 配置部署

注意: hive只要在namenode或者备用的namenode上配置运行即可,其他datanode无需配置server。但是可以启动client

2.1 配置环境变量

修改/etc/profile

# hive settings

export HIVE_HOME=/root/Downloads/apache-hive-2.1.0-bin

export PATH=$HIVE_HOME/bin:$PATH

改完生效一下,即source /etc/profile

2.2 在HDFS上创建相关目录

$ $HADOOP_HOME/bin/hadoop fs -mkdir /tmp

$ $HADOOP_HOME/bin/hadoop fs -mkdir /hive

$ $HADOOP_HOME/bin/hadoop fs -chmod g+w /tmp

$ $HADOOP_HOME/bin/hadoop fs -chmod g+w /hive

2.3 修改hive-site.xml

在$HIVE_HOME/conf下执行以下操作:

cp hive-default.xml.template hive-site.xml

修改配置文件中如下选项:

hive.metastore.warehouse.dir

/hive

location of default database for the warehouse

javax.jdo.option.ConnectionURL

jdbc:mysql://10.45.10.31:3306/metastore_db?useSSL=false

JDBC connect string for a JDBC metastore.

To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.

For example, jdbc:postgresql://myhost/dbName?ssl=true for postgres database.

javax.jdo.option.ConnectionDriverName

com.mysql.jdbc.Driver

Driver class name for a JDBC metastore

javax.jdo.option.ConnectionUserName

hive

Username to use against metastore database

javax.jdo.option.ConnectionPassword

hive

password to use against metastore database

hive.exec.local.scratchdir

/root/Downloads/apache-hive-2.1.0-bin/hive_temps

Local scratch space for Hive jobs

hive.downloaded.resources.dir

/root/Downloads/apache-hive-2.1.0-bin/hive_temps

Temporary local directory for added resources in the remote file system.

2.4 修改 hive-log4j2.properties和hive-exec-log4j2.properties

这两个配置文件都有template,拷贝出来保持默认即可

cp hive-log4j2.properties.template hive-log4j2.properties

cp hive-exec-log4j2.properties.template hive-exec-log4j2.properties

2.5 mysql中创建相关内容

因为我们将hive元数据存放在mysql,因此在mysql先新建相关用户和数据库

create database hive_metadata;

grant all on metastore_db.* to 'hive'@'%' identified by 'hive';

grant all on metastore_db.* to 'hive'@'localhost' identified by 'hive';

ALTER DATABASE hive_metadata CHARACTER SET latin1;

flush privileges;­

2.6 使用schematool初始化

schematool 配置了元数据存放的位置,这里我们将元数据存储在mysql。

为了保证正确初始化,我们还需要把mysql的connector放到hive的lib目录下。

先到mysql官方下载java平台的mysql connector放到$HIVE_HOME/lib下面

执行如下命令:

$HIVE_HOME/bin/schematool -dbType mysql -initSchema

运行后在mysql数据库中查看:

2c156fc687909bf3dd5833a9bc7152b7.png

3. 启动hive

HiveServer2是HiveServer改进版本,它提供给新的ThriftAPI来处理JDBC或者ODBC客户端,进行Kerberos身份验证,多个客户端并发,HS2还提供了新的CLI:BeeLine,是Hive 0.11引入的新的交互式CLI,基于SQLLine,可以作为Hive JDBC Client 端访问HievServer2,启动一个beeline就是维护了一个session.

执行如下命令:

$ $HIVE_HOME/bin/hiveserver2

访问可以使用beeline这种客户端。我们这里直接运行bin/hive来进入客户端

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值