(7-1)hive-0.14.0安装及命令行运行



-------------------------------使用默认Derby内嵌数据库,存储metastore信息,hive解压即可使用:

解压:
tar -zxvf apache-hive-0.14.0-bin.tar.gz

改名:
mv apache-hive-0.14.0-bin hive-0.14.0


查看conf文件夹:
ll
-rw-r--r--. 1 baozi games   1139 11月  9 08:45 beeline-log4j.properties.template
-rw-r--r--. 1 baozi games 144936 11月  9 15:25 hive-default.xml.template
-rw-r--r--. 1 baozi games   2378 11月  9 08:44 hive-env.sh.template
-rw-r--r--. 1 baozi games   2662 11月  9 08:54 hive-exec-log4j.properties.template
-rw-r--r--. 1 baozi games   3050 11月  9 08:45 hive-log4j.properties.template


复制一份hive-env.sh:
cp hive-env.sh.template hive-env.sh


修改hive-env.sh:
vim hive-env.sh

export HADOOP_HOME=/usr/local/hadoop
export JAVA_HOME=/usr/local/jdk
export HIVE_HOME=/usr/local/hive-0.14.0


启动hive:
[root@i-love-you hive-0.14.0]# bin/hive

Logging initialized using configuration in jar:file:/usr/local/hive-0.14.0/lib/hive-common-0.14.0.jar!/hive-log4j.properties
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hive-0.14.0/lib/hive-jdbc-0.14.0-standalone.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
hive>


会发现多了一个metastore_db文件夹:
[root@i-love-you hive-0.14.0]# ll
总用量 420
drwxr-xr-x. 3 root  root    4096 4月  19 19:23 bin
drwxr-xr-x. 2 root  root    4096 4月  19 19:34 conf
-rw-r--r--. 1 root  root   20964 4月  19 19:40 derby.log
drwxr-xr-x. 4 root  root    4096 4月  19 19:23 examples
drwxr-xr-x. 7 root  root    4096 4月  19 19:23 hcatalog
drwxr-xr-x. 4 root  root    4096 4月  19 19:23 lib
-rw-r--r--. 1 baozi games  23828 11月  9 08:45 LICENSE
drwxr-xr-x. 5 root  root    4096 4月  19 19:40 metastore_db
-rw-r--r--. 1 baozi games    277 11月  9 10:37 NOTICE
-rw-r--r--. 1 baozi games   4048 11月  9 08:45 README.txt
-rw-r--r--. 1 baozi games 340611 11月  9 10:35 RELEASE_NOTES.txt
drwxr-xr-x. 3 root  root    4096 4月  19 19:23 scripts

查看所有数据库:
hive> show databases;
OK
default
Time taken: 1.656 seconds, Fetched: 1 row(s)
hive>



metastore是hive元数据的集中存放地。

metastore默认使用内嵌的derby数据库作为存储引擎

Derby引擎的缺点:一次只能打开一个会话

使用
Mysql作为外置存储引擎,多用户同时访问 


再开一个会话启动,会出现错误:
Caused by: ERROR XSDB6: Another instance of Derby may have already booted the database /usr/local/hive-0.14.0/metastore_db.



-------------------------------更改mysql为metastore存储引擎:
这里使用Windows上的数据库:

切记使用时候关闭windows防火墙!!


复制一份hive-site.xml:
cp hive-default.xml.template hive-site-xml



配置MySQL的metastore

修改$HIVE_HOME/conf/hive-site.xml

<property>
	
	<name>javax.jdo.option.ConnectionURL</name>
	
	<value>jdbc:mysql://192.168.1.1:3306/hive?createDatabaseIfNotExist=true</value>
</property>

<property>
	
	<name>javax.jdo.option.ConnectionDriverName</name>
	
	<value>com.mysql.jdbc.Driver</value>

</property>

<property>
	
	<name>javax.jdo.option.ConnectionUserName</name>
	
	<value>root</value>
</property>

<property>
	
	<name>javax.jdo.option.ConnectionPassword</name>
	
	<value>mysqladmin</value>

</property>


临时目录的配置
修改$HIVE_HOME/conf/hive-site.xml
<property>
    
	<name>hive.querylog.location</name>
    
	<value>/usr/local/hive-0.14.0/mydate</value>
  
</property>

  
<property>
    
	<name>hive.exec.local.scratchdir</name>
    
	<value>/usr/local/hive-0.14.0/mydate</value>
  
</property>

  
<property>
    
	<name>hive.downloaded.resources.dir</name>
    
	<value>/usr/local/hive-0.14.0/mydate</value>
  
</property>








之前别忘了启动hadoop!!!
[root@i-love-you hive-0.14.0]# jps
2473 JobHistoryServer
4021 Jps
2248 DataNode
2418 ApplicationHistoryServer
2309 ResourceManager
2192 NameNode
2363 NodeManager
3845 RunJar


第一个终端登录:
[root@i-love-you hive-0.14.0]# bin/hive

Logging initialized using configuration in jar:file:/usr/local/hive-0.14.0/lib/hive-common-0.14.0.jar!/hive-log4j.properties
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hive-0.14.0/lib/hive-jdbc-0.14.0-standalone.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
hive> show databases;
OK
default
Time taken: 1.48 seconds, Fetched: 1 row(s)
hive>



第二个终端登录:
[root@i-love-you hive-0.14.0]# bin/hive

Logging initialized using configuration in jar:file:/usr/local/hive-0.14.0/lib/hive-common-0.14.0.jar!/hive-log4j.properties
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hive-0.14.0/lib/hive-jdbc-0.14.0-standalone.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
hive> show databases;
OK
default
Time taken: 1.888 seconds, Fetched: 1 row(s)
hive>







命令行模式运行:
创建表:
hive> create table t1(name string);
OK
Time taken: 1.134 seconds
hive> show tables;
OK
t1
Time taken: 0.066 seconds, Fetched: 1 row(s)
hive>


hive> create table t2(id int);
OK
Time taken: 0.288 seconds
hive> drop table t1;
Moved: 'hdfs://192.168.1.10:9000/user/hive/warehouse/t1' to trash at: hdfs://192.168.1.10:9000/user/root/.Trash/Current
OK
Time taken: 30.15 seconds
hive>


默认在目录/user/hive/warehouse,可以在hive-default.xml.template里修改参数:hive.metastore.warehouse.dir
[root@i-love-you hive-0.14.0]# hdfs dfs -ls  /user/hive
Found 1 items
drwxr-xr-x   - root supergroup          0 2015-04-19 21:00 /user/hive/warehouse
[root@i-love-you hive-0.14.0]# hdfs dfs -ls -R  /user/hive
drwxr-xr-x   - root supergroup          0 2015-04-19 21:00 /user/hive/warehouse
drwxr-xr-x   - root supergroup          0 2015-04-19 20:59 /user/hive/warehouse/t2
[root@i-love-you hive-0.14.0]#


创建数据库:
hive> create database baozi;
OK
Time taken: 0.238 seconds
hive> 

[root@i-love-you hive-0.14.0]# hdfs dfs -ls -R  /user/hive
drwxr-xr-x   - root supergroup          0 2015-04-19 21:03 /user/hive/warehouse
drwxr-xr-x   - root supergroup          0 2015-04-19 21:03 /user/hive/warehouse/baozi.db
drwxr-xr-x   - root supergroup          0 2015-04-19 20:59 /user/hive/warehouse/t2
[root@i-love-you hive-0.14.0]#






在本地mysql里面的hive数据库的表:





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值