1、下载hive包wget http://labs.mop.com/apache-mirror/hive/stable/hive-0.8.1.tar.gz,并用tar -xzvf 将其解压到要安装的目录,我是放在/home/ckl/hadoop-0.20.2/hive
2、vim ~/.bashrc
export HIVE_HOME=$HADOOP_HOME/hive
export PATH=$HIVE_HOME/bin:$PATH
3、hive配置vim hive/conf/hive-env.sh.template
HADOOP_HOME=/home/ckl/hadoop-0.20.2
cd hive/conf/cp hive-env.sh.template hive-env.sh
chmod +x hive-env.sh
4、在HDFS下创建两个hive文件夹(带有/的是dfs的根目录,没有/的是当前用户所在的目录)
hadoop fs -mkdir /tmp
hadoop fs -mkdir /hive/warehouse
hadoop fs -chmod g+w /tmp
hadoop fs -chmod g+w hive/warehouse
5、将conf/hive-default.xml.template复制两份,分别命名为hive-default.xml(用于保留默认配置)和hive-site.xml(用于个性化配置,可覆盖默认配置)
6、此时关闭终端,重新运行,执行hive则可以成功
7、 测试MapReduce
CREATE TABLE pokes (foo INT, bar STRING);
将内部测试数据载入pokes表中
LOAD DATA LOCAL INPATH '/home/ckl/hadoop-0.20.2/hive/examples/files/kv1.txt' OVERWRITE INTO TABLE pokes;
select foo from pokes;
如果最终能正确显示一堆的数字,表明Hive结合MapReduce使用没问题。
8、上述配置hive默认使用的derby内嵌数据库,而这种数据库只支持一个会话连接。要使用多个会话连接可以使用独立的数据库,这里用的是mysql
apt-get install mysql-server
测试mysql:
mysql -uroot -p
create database hive;
grant all on hive.* to hive@localhost identified by '123456';//创建hive用户,密码为123456
9、将conf/hive-site.xml相应标签修改成
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost: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>hive</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>
10、下载mysql的jdbc驱动包wget http://downloads.mysql.com/archives/mysql-connector-java-5.0/mysql-connector-java-5.0.8.tar.gz
tar -xzvf mysql-connector-java-5.0.8.tar.gz
将文件夹里面的mysql-connector-java-5.0.8-bin.jar复制到hive/lib下
11、测试hive
show tables;
在Hive上建立数据表:
CREATE TABLE my(id INT,name string) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
show tables;
select name from my;
mysql -uhive -p
mysql> use hive
mysql> show tables;
mysql> select * from TBLS;//在TBLS表中可以看到my这个表