hive 1.2 mysql_hive安装 (hive1.2.1+hadoop2.7+mysql)

本文档详细介绍了在CentOS系统上安装和配置Hive的步骤,包括下载Hive,配置环境变量,设置Hive-site.xml,配置MySQL metastore,修改Hadoop配置,开启Hive服务,并提供了通过JDBC和Beeline访问Hive的示例。
摘要由CSDN通过智能技术生成

1. 下载解压

cd /mk/soft

tar -xvzf apache-hive-1.2.1-bin.tar.gz -C /appl/

cd /appl

mv apache-hive-1.2.1-bin hive-1.2.1

2. 配置环境变量

vi /etc/profile

export HIVE_HOME=/appl/hive-1.2.1

export PATH=$PATH:$HIVE_HOME/bin

export CLASSPATH=.:$HIVE_HOME/lib

wq

source /etc/profile

3. 配置Hive

cd /appl/hive-1.2.1/conf

cp hive-default.xml.template hive-default.xml (不改变)

cp hive-default.xml.template hive-site.xml (覆盖hive-default.xml配置项)

cp hive-env.sh.template hive-env.sh

cp hive-log4j.properties.template hive-log4j.properties

vi hive-env.sh

export HADOOP_HOME=${HADOOP_HOME}

export HIVE_CONF_DIR=${HIVE_HOME}/conf

vi hive-log4j.properties

#log4j.appender.EventCounter=org.apache.hadoop.hive.shims.HiveEventCounter

#log4j.appender.EventCounter=org.apache.hadoop.metrics.jvm.EventCounter

log4j.appender.EventCounter=org.apache.hadoop.log.metrics.EventCounter

vi hive-site.xml

--------

javax.jdo.option.ConnectionURL

jdbc:mysql://centos1:3306/metastore_hive?

createDatabaseIfNotExist=true

JDBC connect string for a JDBC metastore

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.metastore.warehouse.dir

/hive/warehouse

location of default database for the warehouse (hdfs

path)

hive.metastore.uris

thrift://centos1:9083

hive.server2.authentication

NONE

--------

hadoop fs -mkdir /hive

hadoop fs -mkdir /hive/warehouse

hadoop fs -chmod g+w /hive/warehouse

hadoop fs -mkdir /hive/tmp

hadoop fs -chmod g+w /hive/tmp

mysql

mysql -uroot -proot

create database metastore_hive;

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

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

grant all on metastore_hive.* to hive@centos1 identified by 'hive';

ALTER DATABASE metastore_hive CHARACTER SET latin1;

show databases;

exit

mysql -hcentos1 -P3306 -uhive -phive

use metastore_hive

exit

传mysql-connector-java-5.1.30-bin.jar到/appl/hive-2.1.0/lib/

hadoop 配置(这一步很多参考文章缺少了)

/appl/hadoop-2.7.0/etc/hadoop/hdfs-site.xml

dfs.permissions

false

/appl/hadoop-2.7.0/etc/hadoop/hadoop-env.sh

export HADOOP_CLASSPATH=$CLASSPATH:$HADOOP_CLASSPATH

# 开通端口(centos)

/sbin/iptables -I INPUT -p tcp --dport 9083 -j ACCEPT

/sbin/iptables -I INPUT -p tcp --dport 10000 -j ACCEPT

/etc/init.d/iptables save

service iptables restart

5. 启动服务

1、启动metastore服务

hive --service metastore & (默认端口:9083,可-p 9083控制;测试:hive --service metastore)

2、启动hiveserver服务

hive --service hiveserver2 &  (测试:hive --service hiveserver2)

3、访问hiveserver的两种方式

(1) JDBC

Class.forName("org.apache.hive.jdbc.HiveDriver");

DriverManager.getConnection("jdbc:hive2://IP:10000/default","","");

(2) beeline

beeline -u jdbc:hive2://localhost:10000/ -n hive -p hive

beeline

!connect jdbc:hive2://localhost:10000

show tables;

create table test1 (id int, name string) row format delimited fields terminated by ',' stored as textfile;

load data local inpath '/mk/test/test1.txt' into table test1;

select * from test1;

!quit 查看hive文件 hadoop fs -ls /hive/warehouse/test1 停止:因为不是通过服务启动,只能ps -ef|grep hive,再kill 参考 http://blog.csdn.net/an342647823/article/details/46048403 http://blog.fens.me/hadoop-hive-intro/ http://blog.csdn.net/jiangkai_nju/article/details/7292313 http://blog.csdn.net/reesun/article/details/8556078 http://www.micmiu.com/bigdata/hive/hive-metastore-config/ http://blog.csdn.net/stark_summer/article/details/45844403

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值