1. 安装mysql
准备好MySQL安装包:
执行如下命令:
sudo
rpm -e--nodeps mysql
yum list |
grep
mysql
sudo
yum
install
-y mysql-server mysqlmysql-deve
为root用户设置密码:
mysqladmin -u root password
'root'
然后可以使用root账号登录MySQL数据库,进行管理:
mysql -u root -p
输入密码登录成功。
MySQL数据库中创建数据库,名称为hive,并进行访问授权:
CREATE DATABASE hive;
GRANT ALL ON
hive
.* TO
'
hive
'
@
'
%
'
IDENTIFIEDBY
'
hive
'
;
FLUSH PRIVILEGES;
2. 下载hvie
下载地址:http://archive.cloudera.com/cdh5/cdh/5/
取得版本为:hive-0.12.0-cdh5.0.0.tar.gz
3. 创建hive用户(已有hadoop组)
执行如下命令:
useradd -ghadoop -m hive
4. 把Hive移动到/home/hive目录下并解压,重命名
执行如下命令:
tar -zxvf hive-0.12.0-cdh5.0.0.tar.gz
mv hive-0.12.0-cdh5.0.0 hive5
5. 用root用户给hive5授权
执行如下命令:
chown -R hive:hadoop hive5
6. 在hive用户下添加环境变量
执行如下命令:
su - hive
vim .profile
在.profile文件中添加如下内容:
export HADOOP_HOME=/home/hdfs/bch
export HIVE_HOME=/home/hive/hive5
export PATH=$PATH:$HIVE_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
7. 配置 Hive 配置文件
a、配置hive-env.sh
在/home/hive/hive5/conf目录下,如果没有hive-env.sh文件,则cp hive-env.sh.template hive-env.sh
如果有hive-env.sh文件,则在该文件修改如下内容:
HADOOP_HOME=/home/hdfs/bch
export HIVE_CONF_DIR=/home/hive/hive5/conf
b、配置hive-default.xml 和 hive-site.xml
在“/home/hive/hive5/conf”目录下,没有这两个文件,只有一个“hive-default.xml.template”,
所以我们要复制两个“hive-default.xml.template”,并分别命名为“hive-default.xml”和“hive-site.xml”
因为我们当前是 root 用户,所以还要把两个的文件的授权给 hadoop 用户。
执行如下命令:
cp hive-default.xml.template hive-default.xml
chown -R hive:hadoop hive-default.xml
cp hive-default.xml.template hive-site.xml
chown -R hive:hadoop hive-site.xml
备注: “hive-default.xml”用于保留默认配置,“hive-site.xml”用于个性化配置,可覆盖默认配置。
hive-site.xml内容如下(将hive-site.xml配置文件拆为如下两部分 ):
(1)、服务端配置文件
<?xml version="1.0"?>
<?xml-stylesheettype="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/hive/warehouse</value>
</property>
<property>
<name>hive.querylog.location</name>
<value>/home/hive/hive5/logs</value>
</property>
<!-- temparary sql data -->
<property>
<name>hive.exec.scratchdir</name>
<value>/home/hive/hive5/data</value>
</property>
<!--
DEPRECATED: Configuration propertyhive.metastore.local no longer has any effect.
Make sure to provide a valid value forhive.metastore.uris if you are connecting to a remote metastore.
<property>
<name>hive.metastore.local</name>
<value>true</value>
</property>
-->
<!--
<property>
<name>hive.metastore.uris</name>
<value>thrift://master1.hadoop:9083</value>
</property>
-->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://master1.hadoop:3306/hive?createDatabaseIfNotExist=true&characterEncoding=UTF-8</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
</property>
<!--
<property>
<name>hive.hwi.listen.host</name>
<value>0.0.0.0</value>
<description>This is the host address the Hive Web Interface willlisten on</description>
</property>
<property>
<name>hive.hwi.listen.port</name>
<value>9999</value>
<description>This is the port the Hive Web Interface will listenon</description>
</property>
<property>
<name>hive.hwi.war.file</name>
<value>lib/hive-hwi-0.12.0-cdh5.0.0.jar</value>
<description>This sets the path to the HWI war file, relative to${HIVE_HOME}. </description>
</property>
-->
<property>
<name>hive.metastore.client.socket.timeout</name>
<value>60</value>
<description>MetaStore Client socket timeout inseconds</description>
</property>
<!-- integrate hbase -->
<property>
<name>hive.support.concurrency</name>
<value>true</value>
<description>Whether hive supports concurrency or not. A zookeeperinstance must be up and running for the default hive lock manager to supportread-write locks.</description>
</property>
<property>
<name>hive.zookeeper.quorum</name>
<value>slave1.hadoop,slave2.hadoop,slave3.hadoop</value>
<description>The list of zookeeper servers to talk to. This isonly needed for read/write locks.</description>
</property>
</configuration>
(2)、客户端配置文件
<?xml version="1.0"?>
<?xml-stylesheettype="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/hive/warehouse</value>
</property>
<property>
<name>hive.querylog.location</name>
<value>/home/hive/hive5/logs</value>
</property>
<!-- temparary sql data -->
<property>
<name>hive.exec.scratchdir</name>
<value>/home/hive/hive5/data</value>
</property>
<!--
DEPRECATED: Configuration propertyhive.metastore.local no longer has any effect.
Make sure to provide a valid value forhive.metastore.uris if you are connecting to a remote metastore.-->
<property>
<name>hive.metastore.local</name>
<value>false</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://master1.hadoop:9083</value>
</property>
<!--
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://master1.hadoop/hive?createDatabaseIfNotExist=true&characterEncoding=UTF-8</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
</property>
-->
<!--
<property>
<name>hive.hwi.listen.host</name>
<value>0.0.0.0</value>
<description>This is the host address the Hive Web Interface willlisten on</description>
</property>
<property>
<name>hive.hwi.listen.port</name>
<value>9999</value>
<description>This is the port the Hive Web Interface will listenon</description>
</property>
<property>
<name>hive.hwi.war.file</name>
<value>lib/hive-hwi-0.12.0-cdh5.0.0.jar</value>
<description>This sets the path to the HWI war file, relative to${HIVE_HOME}. </description>
</property>
-->
<property>
<name>hive.metastore.client.socket.timeout</name>
<value>60</value>
<description>MetaStore Client socket timeout inseconds</description>
</property>
<!-- integrate hbase -->
<property>
<name>hive.support.concurrency</name>
<value>true</value>
<description>Whether hive supports concurrency or not. A zookeeperinstance must be up and running for the default hive lock manager to supportread-write locks.</description>
</property>
<property>
<name>hive.zookeeper.quorum</name>
<value>slave1.hadoop,slave2.hadoop,slave3.hadoop</value>
<description>The list of zookeeper servers to talk to. This isonly needed for read/write locks.</description>
</property>
</configuration>
8. 启动hive服务端程序
启动hive服务端程序:
执行如下命令:
hive --servicemetastore &
9. 进入Hive命令行操作界面
执行:hive