因为我的Hadoop集群是cdh版本的,为了避免遇到不必要的麻烦,所以Hive也要用CDH版本的。
先下载一个Hive CDH包 hive-1.1.0-cdh5.7.0.tar
tar -zxvf hive-1.1.0-cdh5.7.0.tar 将其解压
我们的hive元数据是存储在mysql里面的,所以事先要安装一个mysql
然后配置环境变量
[root@hadoop002 conf]# vi + /etc/profile
export HIVE_HOME=/opt/software/hive-1.1.0-cdh5.7.0
export PATH=$PATH:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PROTOC_HOME/bin:$HIVE_HOME/bin
将mysql的驱动,移动到hive的lib目录里面
[root@hadoop002 software]# mv mysql-connector-java-5.1.32-bin.jar /opt/software/hive-1.1.0-cdh5.7.0/lib/
在hive的conf目录里面新建一个hive.site.xml的文本,写入以下相关配置
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive_remote/warehouse</value>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://hadoop001/hive_remote?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>123</value>
</property>
</configuration>
进入mysql,将hive_remote的数据库稍作修改,否则,建表会失败
mysql> alter database hive_remote character set latin1;
Query OK, 1 row affected (0.00 sec)
hive> create external table g6_access(
> cdn string,
> region string,
> level string,
> time string,
> ip string,
> domain string,
> url string,
> traffic bigint
> ) partitioned by (day string)
> ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
> LOCATION '/g6/hadoop/access/clear';
OK
Time taken: 0.854 seconds
hive>