集群搭建--安装apache-hive-2.3.4
本文安装的是 apache-hive-2.3.4-bin.tar.gz 其下载地址为:
路径 https://pan.baidu.com/s/1ZPJxbGdpjW0fPpKUa7RX6Q 提取码: i58e
解压 apache-hive-2.3.4-bin.tar.gz(hadoop用户)
tar -zxvf apache-hive-2.3.4-bin.tar.gz -C /usr/local/modules/
将 apache-hive-2.3.4-bin 重命名为 hive-2.3.4
mv apache-hive-2.3.4-bin hive-2.3.4
配置hive的环境变量(root用户)
vi /etc/profile
export HIVE_HOME=/usr/local/modules/hive-2.3.4
export HIVE_CONF_DIR=/usr/local/modules/hive-2.3.4/conf
在 export PATH后面添加 $HIVE_HOME/bin:
保存
shift + :
输入 wq
执行 source /etc/profile 命令 生效
source /etc/profile
改名
将 hive-default.xml.template 为模板,重命名 hive-site.xml
mv hive-default.xml.template hive-site.xml
将 hive-env.sh.template 重名为 hive-env.sh
mv hive-env.sh.template hive-env.sh
配置hive-site.xml
配置Hive本地临时目录
cd $HIVE_HOME
mkdir tmp/
chmod -R 777 tmp/
cd /usr/local/modules/hive-2.3.4/conf/
替换 system:java.io.tmpdir
vim hive-site.xml
将 ${system:java.io.tmpdir} 替换为 /usr/local/modules/hive-2.3.4/conf/tmp
配置 hive的用户名
将 ${system:user.name} 替换为 hadoop
修改Hive数据库配置
<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.ConnectionURL</name>
<value>jdbc:mysql://192.168.32.130:3306/hive?createDatabaseIfNotExist=true</value>
<description>
JDBC connect string for a JDBC metastore.
To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.
</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>hive</value>
<description>password to use against metastore database</description>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://spark1:9083</value>
<description>Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore.</description>
</property>
将MySQL的驱动包拷贝到Hive的lib目录下:
cp mysql-connector-java.jar /usr/local/modules/hive-2.3.4/lib/
配置hive-env.sh
vim hive-env.sh
export HADOOP_HOME=/usr/local/modules/hadoop-2.7.7
export HIVE_CONF_DIR=/usr/local/modules/hive-2.3.4/conf
export HIVE_AUX_JARS_PATH=/usr/local/modules/hive-2.3.4/lib
Hive数据库初始化
cd /usr/local/modules/hive-2.3.4/bin
schematool -initSchema -dbType mysql
启动Hive
Hive metastore启动 的命令:
hive --service metastore &
Hive 启动hiveserver2 的命令:
hive --service hiveserver2 &
[[email protected] bin]$ ./hive
测试hive
创建数据库
hive> create database user_test;
创建hive表
hive> create table user_sample(
> user_num bigint,
> user_name string,
> user_gender string,
> user_age int
> ) row format delimited fields terminated by ',';
创建文件
[[email protected] ~] cd /home/hadoop
[[email protected] ~]$ vim user_sample.txt
herry,F,22
0614,Smith,M,25
0615,Tracy,F,24
0616,Lucy,F,19
0617,Sherry,F,23
加载 数据
hive> load data local inpath '/home/hadoop/user_sample.txt' into table user_sample;
查看数据
hive> select * from user_sample;
OK
NULL F 22 NULL
614 Smith M 25
615 Tracy F 24
616 Lucy F 19
617 Sherry F 23
Time taken: 4.022 seconds, Fetched: 5 row(s)
统计条数
hive> select count(*) from user_sample;