Hive的安装配置
准备
hadoop集群
mysql
1 Hive安装及配置
(1)把apache-hive-x.x.x-bin.tar.gz上传到linux的/opt/software目录下
(2)解压apache-hive-x.x.x-bin.tar.gz到/opt/module/目录下面
tar -zxvf apache-hive-x.x.x-bin.tar.gz -C /opt/module/
(3)修改apache-hive-x.x.x-bin.tar.gz的名称为hive
mv apache-hive-x.x.x-bin/ hive
(4)修改/opt/module/hive/conf目录下的hive-env.sh.template名称为hive-env.sh
mv hive-env.sh.template hive-env.sh
(5)配置hive-env.sh文件
(a)配置HADOOP_HOME路径
export HADOOP_HOME=/opt/module/hadoop-2.8.4
(b)配置HIVE_CONF_DIR路径
export HIVE_CONF_DIR=/opt/module/hive/conf
注:Hive的log默认存放在/tmp/itstar/hive.log目录下(当前用户名下)。
(1)修改hive的log存放日志到/opt/module/hive/logs
(2)修改conf/hive-log4j.properties.template文件名称为hive-log4j.properties
mv hive-log4j.properties.template hive-log4j.properties
(3)在hive-log4j.properties文件中修改log存放位置
hive.log.dir=/opt/module/hive/logs
2 Hadoop集群配置
(1)必须启动hdfs和yarn
sbin/start-dfs.sh
sbin/start-yarn.sh
(2)在HDFS上创建/tmp和/user/hive/warehouse两个目录并修改他们的同组权限可写
bin/hadoop fs -mkdir /tmp
bin/hadoop fs -mkdir /user/hive/warehouse
bin/hadoop fs -chmod g+w /tmp
bin/hadoop fs -chmod g+w /user/hive/warehouse
3 Hive基本操作
(1)启动hive
bin/hive
(2)查看数据库
hive>show databases;
(3)打开默认数据库
hive>use default;
(4)显示default数据库中的表
hive>show tables;
(5)创建一张表
hive> create table student(id int, name string);
(6)显示数据库中有几张表
hive>show tables;
(7)查看表的结构
hive>desc student;
(8)向表中插入数据
hive> insert into student values(1001,"ss1");
(9)查询表中数据
hive> select * from student;
(10)退出hive
hive> quit;
4 Hive元数据配置到MySql
4.1 驱动拷贝
1)上传mysql-connector-java-5.1.27-bin.jar到/hive/lib/
cp mysql-connector-java-5.1.27-bin.jar /opt/module/hive/lib/
4.2 配置Metastore到MySql
1)在/hive/conf目录下创建一个hive-site.xml
touch hive-site.xml
vi hive-site.xml
2)根据官方文档配置参数,拷贝数据到hive-site.xml文件中。
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!--定义原数据存储方式,存储位置(这里是mysql)-->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://bigdata111:3306/metastore?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
<!--定义原数据存储连接器(这里是mysql的)
注意:
mysql5.x连接器为 com.mysql.jdbc.Driver
mysql8.x连接器为 com.mysql.cj.jdbc.Driver 且向下兼容
-->
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<!--登录mysql用户名-->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>username to use against metastore database</description>
</property>
<!--登录mysql密码-->
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>000000</value>
<description>password to use against metastore database</description>
</property>
</configuration>
3)配置完毕后,如果启动hive异常,可以重新启动虚拟机。(重启后,别忘了启动hadoop集群)
4)在hive的bin目录下执行
bin/schematool -dbType mysql -initSchema
元数据修改成功:
4.3 Hive数据仓库位置配置
1)Default数据仓库的最原始位置是在hdfs上的:/user/hive/warehouse路径下
2)在仓库目录下,没有对默认的数据库default创建文件夹。如果某张表属于default数据库,直接在数据仓库目录下创建一个文件夹。
3)修改default数据仓库原始位置(将hive-default.xml.template如下配置信息拷贝到hive-site.xml文件中)
配置同组用户有执行权限
bin/hdfs dfs -chmod g+w /user/hive/warehouse