centos7下Hadoop集群的mysql5.7以及hive3.1搭建——包对的!

07-11 1196阅读

首先说一下我自己的安装环境:

centos7下Hadoop集群的mysql5.7以及hive3.1搭建——包对的!
(图片来源网络,侵删)

Hadoop: hadoop-2.7.5

Hive:apache-hive-3.1.2-bin

mysql驱动:mysql-connector-java-5.1.37

备注:我所有的压缩包放在 /opt 目录下,解压包放在 /app 目录下

用的是moba远程控制虚拟机——————最后附上了需要的压缩包哦~

一、安装mysql

下载官方mysql的rmp包

[root@Hadoop01 ~]# cd /usr/local/src
[root@Hadoop01 src]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
[root@Hadoop01 src]# ls
mysql57-community-release-el7-11.noarch.rpm

卸载原生的mariadb

[root@Hadoop01 src]# rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
[root@Hadoop01 src]# yum remove -y mariadb-libs-5.5.60-1.el7_5.x86_64

没有的话就跳过这一步

yum安装mysql-serve

[root@Hadoop01 src]# rpm -ivh mysql57-community-release-el7-11.noarch.rpm
warning: mysql57-community-release-el7-11.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql57-community-release-el7-11 ################################# [100%]
[root@Hadoop01 src]# yum -y install mysql-community-server

在这里可能会遇到以下错误:

The GPG keys listed for the “MySQL 5.7 Community Server” repository are already installed but they are not correct for this package.

Check that the correct key URLs are configured for this repository.

Failing package is: mysql-community-libs-compat-5.7.37-1.el7.x86_64

GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

原因是Mysql的GPG升级了,需要重新获取

使用以下命令即可:

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

再执行:

yum -y install mysql-community-server

验证安装是否成功

#开启mysql服务

[root@Hadoop01 src]# systemctl start mysqld.service

# 查看mysql状态

[root@Hadoop01 src]# systemctl status mysqld.service

密码设置

# 生成初始密码   hfai38(&kfnw%;

[root@Hadoop01 src]#  cat /var/log/mysqld.log|grep 'temporary password'
2024-06-25T16:19:46.809908Z 1 [Note] A temporary password is generated for root@localhost: hfai38(&kfnw%;

这里的密码一定要复制全了,虽然长得很奇怪...

# 利用刚才生成的初始密码自定义新的密码

[root@Hadoop01 src]# mysql -u root -p
Enter password: 

输入刚才的密码  hfai38(&kfnw%; 进入mysql:

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> 
#以此输入以下内容,就可以自定义的简单密码123456
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_mixed_case_count=2;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

重启mysql

# 重启mysql

[root@Hadoop01 src]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service

# 用我们刚才设置的密码123456登录

[root@Hadoop01 src]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

到这里mysql就安装结束了! 

二、Hive的搭建

Hive的安装基于Hadoop,因此需要先搭建好Hadoop环境

其次以MySQL作为Hive的元数据库,所以也要先安装好MySQL

安装配置Hive

找到对应版本的Hive安装包,我选择的是hive-3.1.2.

利用moba等工具将安装包上传到/opt下,并解压到/app下:

[root@Hadoop01 src]#  tar -zxvf /opt/apache-hive-3.1.2-bin.tar.gz -C /app

进入/app下重命名:

[root@Hadoop01 app]# mv apache-hive-3.1.2-bin/ hive3.1

在/etc/profile中添加环境变量:

[root@Hadoop01 app]# vi /etc/profile
#添加以下内容
export HIVE_HOME=/app/hive3.1/
export PATH=$PATH:HIVE_HOME/bin

生效:

[root@Hadoop01 app]# source /etc/profile

在 /app/hive3.1/conf/ 下创建hive-site.xml 文件:

[root@Hadoop01 app]# cd hive3.1/conf/
[root@Hadoop01 conf]# vim hive-site.xml

在文件中输入一下内容:

-》》注意驱动版本的问题



    
        hive.metastore.local
        true
    
    #这里的Hadoop01要改成自己的主机名
    #后面的hive是一会要在mysql创建的
    
        javax.jdo.option.ConnectionURL
         jdbc:mysql://Hadoop01:3306/hive?characterEncoding=UTF-8
    
    # 数据库的驱动类名称
    # 新版本8.0版本的驱动为com.mysql.cj.jdbc.Driver
    # 旧版本5.x版本的驱动为com.mysql.jdbc.Driver
    
        javax.jdo.option.ConnectionDriverName
        com.mysql.jdbc.Driver
    
    
        javax.jdo.option.ConnectionUserName
        root
    
    
        javax.jdo.option.ConnectionPassword
        123456
    

配置hive-log4j2.properties

复制并更名hive-log4j2.properties.template为 hive-log4j2.properties文件,并修改文件内容:

[root@Hadoop01 conf]#  cp hive-log4j2.properties.template hive-log4j2.properties
[root@Hadoop01 conf]# vi hive-log4j2.properties
# 修改内容
property.hive.log.dir =/app/hive3.1/temp/root

配置hive-env.sh文件

复制并更名hive-env.sh.template为 hive-env.sh文件,并修改文件内容:

[root@Hadoop01 conf]# cp hive-env.sh.template hive-env.sh
[root@Hadoop01 conf]# vi hive-env.sh
#添加以下内容:
export HADOOP_HOME=/app/hadoop2.7/
export HIVE_CONF_DIR=/app/hive3.1/conf/
export HIVE_AUX_JARS_PATH=/app/hive3.1/bin/

Hive启动

进入mysql,创建Hive数据库:

[root@Hadoop01 conf]# mysql -u root -p
mysql> create database hive;
Query OK, 1 row affected (0.05 sec)

进入官网下载数据库驱动:

将mysql-connector-java-5.1.37.tar.gz 放入/opt目录下,并解压到/app下:

[root@Hadoop01 conf]# tar -zxvf /opt/mysql-connector-java-5.1.37.tar.gz -C /app

然后将里面的mysql-connector-java-5.1.37-bin.jar 上传到 /app/hive3.1/lib:

[root@Hadoop01 conf]# cp /app/mysql-connector-java-5.1.37/mysql-connector-java-5.1.37-bin.jar /app/hive3.1/lib/

进入hive的bin目录,进行初始化:

[root@Hadoop01 conf]# cd ../bin
[root@Hadoop01 bin]# schematool -dbType mysql -initSchema

出现schemaTool competed就成功了!

三、一些纠错

①Failed to load driver

可能原因:

--驱动的版本不对;

--驱动没放在正确的位置(Hive/lib下);

--将驱动整个目录而不是jar包放在Hive/lib下,解压出来是一个目录,没注意的话也会报错。

②not allowed to connect to this MySQL server

服务器不允许远程连接,我们进入mysql进行以下修改:

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host = '%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

再重启mysql:

[root@Hadoop01 bin]# systemctl stop mysqld.service
[root@Hadoop01 bin]#  systemctl start mysqld.service

解决完错误之后,再重新初始化Hive:

[root@Hadoop01 bin]# schematool -dbType mysql -initSchema

祝你成功!

这里分享一下压缩包:

链接:https://pan.baidu.com/s/1AnczKF_fyugdMaJ5RZm2XA 

提取码:84is

VPS购买请点击我

文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

目录[+]