Hive metastore三种配置方式

3 篇文章 0 订阅

Hive的meta数据支持以下三种存储方式,其中两种属于本地存储,一种为远端存储。远端存储比较适合生产环境。Hive官方wiki详细介绍了这三种方式,链接为:Hive Metastore

 

一、本地derby

这种方式是最简单的存储方式,只需要在hive-site.xml做如下配置便可

[html]  view plain copy print ?
  1. <?xml version="1.0"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3.   
  4. <configuration>  
  5.   
  6. <property>  
  7.   <name>javax.jdo.option.ConnectionURL</name>  
  8.   <value>jdbc:derby:;databaseName=metastore_db;create=true</value>  
  9. </property>  
  10.    
  11. <property>  
  12.   <name>javax.jdo.option.ConnectionDriverName</name>  
  13.   <value>org.apache.derby.jdbc.EmbeddedDriver</value>  
  14. </property>  
  15.    
  16. <property>  
  17.   <name>hive.metastore.local</name>  
  18.   <value>true</value>  
  19. </property>  
  20.    
  21. <property>  
  22.   <name>hive.metastore.warehouse.dir</name>  
  23.   <value>/user/hive/warehouse</value>  
  24. </property>  
  25.    
  26. <property>  
  27.   <name>hive.metastore.warehouse.dir</name>  
  28.   <value>/user/hive/warehouse</value>  
  29. </property>  
  30.   
  31. </configuration>  

注:使用derby存储方式时,运行hive会在当前目录生成 一个 derby 文件 一个 metastore_db 目录 。这种存储方式的 弊端 是在同一个目录下同时只能有一个hive客户端能使用数据库,否则会提示如下错误

[html]  view plain copy print ?
  1. hive> show tables;  
  2. FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Failed to start database 'metastore_db', see the next exception for details.  
  3. NestedThrowables:  
  4. java.sql.SQLException: Failed to start database 'metastore_db', see the next exception for details.  
  5. FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask  

二、本地mysql

这种存储方式需要在本地运行一个mysql服务器,并作如下配置(下面两种使用mysql的方式,需要将mysql的jar包拷贝到$HIVE_HOME/lib目录下)。

[html]  view plain copy print ?
  1. <?xml version="1.0"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3.   
  4. <configuration>  
  5. <property>  
  6.   <name>hive.metastore.warehouse.dir</name>  
  7.   <value>/user/hive_remote/warehouse</value>  
  8. </property>  
  9.    
  10. <property>  
  11.   <name>hive.metastore.local</name>  
  12.   <value>true</value>  
  13. </property>  
  14.    
  15. <property>  
  16.   <name>javax.jdo.option.ConnectionURL</name>  
  17.   <value>jdbc:mysql://localhost/hive_remote?createDatabaseIfNotExist=true</value>  
  18. </property>  
  19.    
  20. <property>  
  21.   <name>javax.jdo.option.ConnectionDriverName</name>  
  22.   <value>com.mysql.jdbc.Driver</value>  
  23. </property>  
  24.    
  25. <property>  
  26.   <name>javax.jdo.option.ConnectionUserName</name>  
  27.   <value>hive</value>  
  28. </property>  
  29.    
  30. <property>  
  31.   <name>javax.jdo.option.ConnectionPassword</name>  
  32.   <value>password</value>  
  33. </property>  
  34. </configuration>  

三、远端mysql

这种存储方式需要在远端服务器运行一个mysql服务器,并且需要在Hive服务器启动meta服务。

这里用mysql的测试服务器,ip位192.168.1.214,新建hive_remote数据库,字符集位latine1

[html]  view plain copy print ?
  1. <?xml version="1.0"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3.    
  4. <configuration>  
  5.   
  6. <property>  
  7.   <name>hive.metastore.warehouse.dir</name>  
  8.   <value>/user/hive/warehouse</value>  
  9. </property>  
  10.    
  11. <property>  
  12.   <name>javax.jdo.option.ConnectionURL</name>  
  13.   <value>jdbc:mysql://192.168.1.214:3306/hive_remote?createDatabaseIfNotExist=true</value>  
  14. </property>  
  15.    
  16. <property>  
  17.   <name>javax.jdo.option.ConnectionDriverName</name>  
  18.   <value>com.mysql.jdbc.Driver</value>  
  19. </property>  
  20.    
  21. <property>  
  22.   <name>javax.jdo.option.ConnectionUserName</name>  
  23.   <value>hive</value>  
  24. </property>  
  25.    
  26. <property>  
  27.   <name>javax.jdo.option.ConnectionPassword</name>  
  28.   <value>password</value>  
  29. </property>  
  30.   
  31. <property>  
  32.   <name>hive.metastore.local</name>  
  33.   <value>false</value>  
  34. </property>  
  35.   
  36. <property>  
  37.   <name>hive.metastore.uris</name>  
  38.   <value>thrift://192.168.1.188:9083</value>  
  39. </property>  
  40.   
  41. </configuration>  

注:这里把hive的服务端和客户端都放在同一台服务器上了。服务端和客户端可以拆开,将hive-site.xml配置文件拆为如下两部分

         1)、服务端配置文件
[html]  view plain copy print ?
  1. <?xml version="1.0"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3.    
  4. <configuration>  
  5.   
  6. <property>  
  7.   <name>hive.metastore.warehouse.dir</name>  
  8.   <value>/user/hive/warehouse</value>  
  9. </property>  
  10.    
  11. <property>  
  12.   <name>javax.jdo.option.ConnectionURL</name>  
  13.   <value>jdbc:mysql://192.168.1.214:3306/hive_remote?createDatabaseIfNotExist=true</value>  
  14. </property>  
  15.    
  16. <property>  
  17.   <name>javax.jdo.option.ConnectionDriverName</name>  
  18.   <value>com.mysql.jdbc.Driver</value>  
  19. </property>  
  20.    
  21. <property>  
  22.   <name>javax.jdo.option.ConnectionUserName</name>  
  23.   <value>root</value>  
  24. </property>  
  25.    
  26. <property>  
  27.   <name>javax.jdo.option.ConnectionPassword</name>  
  28.   <value>test1234</value>  
  29. </property>  
  30. </configuration>  

         2)、客户端配置文件
[html]  view plain copy print ?
  1. <?xml version="1.0"?>  
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  
  3.    
  4. <configuration>  
  5.   
  6. <property>  
  7.   <name>hive.metastore.warehouse.dir</name>  
  8.   <value>/user/hive/warehouse</value>  
  9. </property>  
  10.    
  11. <property>  
  12.   <name>hive.metastore.local</name>  
  13.   <value>false</value>  
  14. </property>  
  15.   
  16. <property>  
  17.   <name>hive.metastore.uris</name>  
  18.   <value>thrift://192.168.1.188:9083</value>  
  19. </property>  
  20.   
  21. </configuration>  

启动hive服务端程序

[plain]  view plain copy print ?
  1. $ hive --service metastore   

客户端直接使用hive命令即可

[plain]  view plain copy print ?
  1. root@my188:~$ hive   
  2. Hive history file=/tmp/root/hive_job_log_root_201301301416_955801255.txt  
  3. hive> show tables;  
  4. OK  
  5. test_hive  
  6. Time taken: 0.736 seconds  
  7. hive>  
转自: http://blog.csdn.net/reesun/article/details/8556078
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值