Hive-3.1.3远程模式安装与配置

Hive搭建前提:hadoop已安装配置成功,安装步骤可参考

Hadoop3.1.3完全分布式平台搭建_hadoop-3.1.3-CSDN博客

一、上传并解压hive

1、通过MobaXterm工具将hive3.1.3的安装包上传至master主机的/opt/software目录下,并解压至/opt/install目录下,解压命令为:

tar -zxvf apache-hive-3.1.3-bin.tar.gz -C /opt/install

2、将解压后的hive-3.1.3目录重命名为hive,命令为:

mv apache-hive-3.1.3-bin/ hive

二、配置hive的环境变量

1、打开/etc/profile文件

vi /etc/profile

2、在末尾添加hive的环境变量,命令为:

export HIVE_HOME=/opt/install/hive

export PATH=$PATH:$HIVE_HOME/bin

配置完成后按下esc键,输入:wq保存并退出文件

3、生效配置的环境

source /etc/profile

4、验证hive是否配置成功

hive --version

三、安装mysql

1、检查mysql是否已安装

rpm -qa | grep mysql

若查到内容,说明mysql已安装,此时需要先卸载掉

(卸载命令:rpm -e xxx    xxx为文件全名)

2、使用wget下载官方mysql包,命令为:

wget http://repo.mysql.com/mysql80-community-release-el7.rpm

若报错提示wgetcommand not found,需要先安装wget,命令为:

yum install –y wget

3、安装mysql包,命令为:yum install -y mysql80-community-release-el7.rpm

4、安装mysql服务,命令为:yum install –y mysql-community-server

可能的报错:xxx的公钥尚未安装

解决办法: rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

5、启动服务并查看服务状态

systemctl start mysqld

systemctl status mysqld

6、获取mysql默认密码

grep "password" /var/log/mysqld.log

7、登录mysql并修改密码

mysql –uroot -p

先修改一次密码,然后才能调整为简单的密码规则

set password for root@localhost='Root777!';

set global validate_password.policy = 0;

set global validate_password.length = 4;

将密码修改为123456

set password for root@localhost=’123456’;

退出当前账户,重新用123456这个密码登录

登录成功,说明密码修改成功

8、授权远程用户连接mysql

use mysql;

update user set host = '%' where user = 'root';

flush privileges;

授权完毕后输入exit; 退出mysql

9、将mysqljar包上传至/opt/install/hive/lib目录下

四、hive的核心文件配置

进入hiveconf目录: cd /opt/install/hive/conf

1、配置hive-env.sh

1conf目录中只有hive-env.sh.template,需要拷贝重新生成一个hive-env.sh

命令为: cp hive-env.sh.template hive-env.sh

2)打开hive-env.sh,在末尾添加如下两行内容

export HADOOP_HOME=/opt/install/hadoop

export HIVE_CONF_DIR=/opt/install/hive/conf

添加完成后,按下esc键,输入:wq保存并退出文件

2、配置hive-site.xml

1conf目录中没有hive-site.xml文件,输入 vi hive-site.xml创建并编辑文件

按下字母i,进入编辑模式,输入如下内容:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--

   Licensed to the Apache Software Foundation (ASF) under one or more

   contributor license agreements.  See the NOTICE file distributed with

   this work for additional information regarding copyright ownership.

   The ASF licenses this file to You under the Apache License, Version 2.0

   (the "License"); you may not use this file except in compliance with

   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software

   distributed under the License is distributed on an "AS IS" BASIS,

   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

   See the License for the specific language governing permissions and

   limitations under the License.

-->

<configuration>

    <!--设置Hive通过JDBC模式连接MySQL数据库metastore内容,用来保存hive元数据-->

    <property>

        <name>javax.jdo.option.ConnectionURL</name>

<value>jdbc:mysql://master:3306/hive?createDatabaseIfNotExist=true&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false&amp;serverTimezone=GMT</value>

    </property>  

    <!--设置Hive连接MySQL的驱动名称-->

    <property>

        <name>javax.jdo.option.ConnectionDriverName</name>

        <value>com.mysql.cj.jdbc.Driver</value>

    </property>

   <!--Hive连接存储metastore内容的数据库的用户名root和密码123456-->

    <property>

        <name>javax.jdo.option.ConnectionUserName</name>

        <value>root</value>

    </property>

    <property>

        <name>javax.jdo.option.ConnectionPassword</name>

        <value>123456</value>

    </property>

    <!--执行Hive数据仓库操作的数据存储目录-->

    <property>

        <name>hive.metastore.warehouse.dir</name>

        <value>hdfs://master:9820/hive/warehouse</value>

    </property>

    <property> 

        <name>hive.exec.mode.local.auto</name> 

        <value>true</value> 

    </property>

    <property>

        <name>hive.server2.thrift.port</name>

        <value>10000</value>

    </property>

    <property>

        <name>hive.server2.thrift.bind.host</name>

        <value>master</value>

    </property>

    <property>

        <name>hive.metastore.uris</name>

        <value>thrift://master:9083</value>

    </property>

    <property>

        <name>hive.metastore.event.db.notification.api.auth</name>

        <value>false</value>

    </property>

    <property>

        <name>hive.metastore.schema.verification</name>

        <value>false</value>

    </property>

    <property>

        <name>hive.server2.active.passive.ha.enable</name>

        <value>true</value>

    </property>

    <property>

        <name>hive.cli.print.header</name>

        <value>true</value>

    </property>

    <property>

        <name>hive.cli.print.current.db</name>

        <value>true</value>

    </property>

    <property>

        <name>hive.resultset.use.unique.column.names</name>

        <value>false</value>

    </property>

</configuration>

编辑完成后,按下esc键,输入:wq,保存并退出文件

五、初始化元数据库

1、mysql配置好,hadoop集群已启动的情况下,进入hive的bin目录

cd /opt/install/hive/bin

2、执行以下指令进行初始化: schematool -dbType mysql -initSchema

(1)此时会报以下错误:

2)报错原因:hadoophiveguava.jar版本不一致,两个jar位置分别位于如下目录:

       hadoop:   /opt/install/hadoop/share/hadoop/common/lib/guava-27.0-jre.jar

       hive:     /opt/install/hive/lib/guava-19.0.jar

3)解决办法:删除低版本的jar,将高版本的复制到低版本目录下。

rm -rf /opt/install/hive/lib/guava-19.0.jar

cp /opt/install/hadoop/share/hadoop/common/lib/guava-27.0-jre.jar /opt/install/hive/lib/

4)然后再次运行schematool -dbType mysql -initSchema,即可成功初始化元数据

六、启动hive

1、在hive的bin目录下启动元数据服务

hive --service metastore 

2、输入hive进入交互模式

常用HQL操作,例如:

列出所有数据库:show databases;

创建数据库:create database xxx;

删除数据库:drop database xxx;

使用某数据库:use xxx;

退出hive交互模式:输入exit; 即可

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值