下载HIVE
1 | su - hadoop |
环境配置
在/etc/profile中追加:
1 | export HIVE_HOME=/home/hadoop/hive |
安装MySQL
1 | yum install gcc gcc- c ++ ncurses-devel -y |
配置HIVE
新建hive-site.xml1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://HADOOP-MASTER-153:3306/hive?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>
</configuration>
使用了mysql作为metastore ,则需要在lib目录下添加mysql的驱动
下载JDBC到hive/lib目录下1
wget http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.37/mysql-connector-java-5.1.37.jar
客户端配置
1 | scp -r apache-hive-1.2.1-bin/ hadoop@hadoop-slave:/home/hadoop |
整合HBase
1 | CREATE EXTERNAL TABLE hbaseusers(key string, value string) |
建立外部数据源指定hbase存在的数据表列族时候不能包含空格, 不然会出现’不存在的列族’(Column Family n is not defined in hbase table nginx):1
2
3
4
5
6
7
报错:
hive> CREATE EXTERNAL TABLE hbaseusers(key string, value string)
> STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
> WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:name")
> TBLPROPERTIES ("hbase.table.name" = "users");
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:For direct MetaStore DB connections, we don't support retries at the client level.)
在debug模式下开启metastore :
执行hive --service metastore -hiveconf hive.root.logger=DEBUG,console
报错:
1 | 16/01/24 17:00:07 [main]: ERROR DataNucleus.Datastore: An exception was thrown while adding/validating class(es) : Specified key was too long; max key length is 767 bytes |
差了相关文档,发现需要把mysql的字符集设置为latin1.
在/etc/my.cnf里增加1
2character-set-server = latin1
collation-server = latin1_general_ci
重启mysql
如果之前有hive的database需要drop掉重新建
1 | hive> CREATE EXTERNAL TABLE hbaseusers(key string, value string) |
OK
参考文档
http://my.oschina.net/u/204498/blog/522772
http://yanliu.org/2015/08/13/Hadoop%E9%9B%86%E7%BE%A4%E4%B9%8BHive%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/