一、环境
Centso7.2 64位 apache-hive-2.3.3-bin.tar.gz
二、安装
1、下载 apache-hive-2.3.3-bin.tar.gz
链接:http://hive.apache.org/downloads.html
2、通过Xshell工具将压缩包上传至/usr/local/src并解压缩
cd /usr/local/src
tar -xzvf apache-hive-2.3.3-bin.tar.gz
3、将解压缩的apache-hive-2.3.3-bin移动至/usr/local
mv /usr/local/src/apache-hive-2.3.3-bin /usr/local/hive
4、配置环境变量
cd /usr/local/hive/conf
cp hive-default.xml.template hive-site.xml
修改hive.metastore.schema.verification,设定为false
创建/usr/local/hive/tmp目录,替换${system:java.io.tmpdir}为该目录
替换${system:user.name}为root
5、建立数据库
5.1、hive内置数据库derby配置
schematool -initSchema -dbType derby
在当前目录下建立metastore_db的数据库;
请注意!!!下次执行hive时应该还在同一目录,默认到当前目录下寻找metastore ;
遇到问题,把metastore_db删掉,重新执行命令
实际工作环境中,经常使用mysql作为metastore的数据。
5.2、hive配置mysql数据库:
A、单用户模式:
cd /usr/local/hive/conf
vi hive-site.xml
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.199.101:3306/hive?createDatabaseIfNotExist=true&characterEncoding=UTF-8</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>root</value>
<description>password to use against metastore database</description>
</property>
</configuration>
添加两个Jar包:mysql-connector-java.jar和jline*.jar包至hadoop Jar包文件夹;
B、多用户模式:
## 服务端hive -- slave1
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.199.101:3306/multiUsersHive?createDatabaseIfNotExist=true&characterEncoding=UTF-8</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>root</value>
<description>password to use against metastore database</description>
</property>
</configuration>
## 客户端hive -- slave2
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>
<property>
<name>hive.metastore.local</name>
<value>false</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://192.168.199.102:9083</value>
<description>Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore.</description>
</property>
</configuration>
先启动服务端:hive --service metastore & ; (注意拷贝mysql Jar包);再启动客户端:hive ;
6、启动Hive:
hive
7、简单操作:
show databases;
use default;
create table emp(name string,agent string,age int,salary double);
show tables;
desc emp;
select * from emp;
drop table emp;