> 文档中心 > Hadoop集群中hive搭建

Hadoop集群中hive搭建

  1. 系统环境
    Oracle VM VirtualBox
    Ubuntu 16.04
    Hadoop 2.7.4
    Java 1.8.0_111

hadoop集群
master:192.168.19.128
slave1:192.168.19.129
slave2:192.168.19.130

MySQL安装在master机器上,hive服务器也安装在master上

hive版本: https://mirrors.cnnic.cn/apache/hive/hive-2.3.0/apache-hive-2.3.0-bin.tar.gz

2.mysql安装

本文使用MySQL作为远程元数据库,部署在master节点上

2.1安装mysql

安装mysql服务端
sudo apt-get install mysql-server
安装mysql客户端
sudo apt-get install mysql-client
期间会有命令窗口会有跳窗提醒输入密码,一定要记住密码,登录Mysql和后续的配置都需要密码。

2.2.查看mysql服务是否启动
sudo netstat -tap | grep mysql

2.3.设置mysql远程访问
a).编辑mysql配置文件,把其中bind-address = 127.0.0.1注释了
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

b). 使用root进入mysql命令行,执行如下2个命令,示例中mysql的root账号密码就是按照mysql时输入的密码
mysql -u root -p
命令窗口会有提示输入密码,即是安装mysql时输入的密码
c).授权root账户,并授予它远程连接的权力

添加一个用户名是root且密码是root的远程访问用户
grant all on . to root@‘%’ identified by ‘root’ with grant option;
d).运行完后紧接着输入,以更新数据库:
FLUSH PRIVILEGES;
e).执行quit退出mysql

2.4.重启mysql
/etc/init.d/mysql restart
重启成功后,在其他计算机上,便可以登录。

MySQL卸载:
1、sudo apt-get autoremove --purge mysql-server-5.0
2、sudo apt-get remove mysql-server
3、sudo apt-get autoremove mysql-server
4、sudo apt-get remove mysql-common --这个很重要
5、dpkg -l |grep ^rc|awk ‘{print $2}’ |sudo xargs dpkg -P – 清除残留数据

3.Hive安装配置

3.1.下载Hive安装包
wget https://mirrors.cnnic.cn/apache/hive/hive-2.3.0/apache-hive-2.3.0-bin.tar.gz
3.2.解压
tar -zxfv apache-hive-2.3.0-bin.tar.gz
3.3.将解压后的目录移动到自己指定的安装目录
mv apache-hive-2.3.0-bin /home/hadoop/software/
3.4.配置环境变量
sudo vim /etc/profile
export HIVE_HOME=/home/hadoop/software/apache-hive-2.3.0-bin
export PATH= H I V E H O M E / b i n : HIVE_HOME/bin: HIVEHOME/bin:PATH
3.5.使环境变量生效
source /etc/profile
3.6.修改conf/下的几个template模板并重命名
a).复制hive-env.sh.template创建为hive-env.sh
cp hive-env.sh.template hive-env.sh
给hive-env.sh增加执行权限
chmod 755 hive-env.sh
修改conf/hive-env.sh 文件
HADOOP_HOME=/home/hadoop/software/hadoop-2.7.4
b).复制hive-default.xml.template创建为hive-site.xml
cp hive-default.xml.template hive-site.xml
修改hive-site.xml文件内容

javax.jdo.option.ConnectionURL
jdbc:mysql://master:3306/hive?createDatabaseIfNotExist=true
JDBC connect string for a JDBC metastore

javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
Driver class name for a JDBC metastore

javax.jdo.option.ConnectionUserName
hive
username to use against metastore database

javax.jdo.option.ConnectionPassword
hive
password to use against metastore database

hive.exec.local.scratchdir /home/hadoop/software/apache-hive-2.3.0-bin/iotmp Local scratch space for Hive jobs hive.downloaded.resources.dir /home/hadoop/software/apache-hive-2.3.0-bin/iotmp Temporary local directory for added resources in the remote file system.

根据hive-site-xml,创建缓存目录
cd /home/hadoop/software/apache-hive-2.3.0-bin/
mkdir iotmp
3.7.修改 bin/hive-config.sh 文件
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_121
export HIVE_HOME=/home/hadoop/software/apache-hive-2.3.0-bin
export HADOOP_HOME=/home/hadoop/software/hadoop-2.7.4
3.8.下载mysql-connector-java-5.1.44-bin.jar文件,并放到/home/hadoop/software/apache-hive-2.3.0-bin/lib目录下
wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.44.tar.gz
解压mysql-connector-java-5.1.44.tar.gz后,将mysql-connector-java-5.1.44-bin.jar放置在lib目录下
4.将apache-hive-2.3.0-bin分发到slave节点
scp -r apache-hive-2.3.0-bin hadoop@slave1:/home/hadoop/software/
scp -r apache-hive-2.3.0-bin hadoop@slave2:/home/hadoop/software/

slave端配置, 修改 conf/hive-site.xml 文件

hive.metastore.uris
thrift://master:9083
Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore.

5.Hive的mysql数据库配置
5.1.使用root用户登录mysql数据库
mysql -u root -p
5.2.创建hive用户
mysql> CREATE USER ‘hive’ IDENTIFIED BY ‘hive’;
5.3.给hive用户赋权限
mysql> GRANT ALL PRIVILEGES ON . TO ‘hive’@‘%’ WITH GRANT OPTION;
5.4.更新数据库
mysql>flush privileges;
mysql> quit
5.5.Hive用户登录
hadoop@master:~$ mysql -u hive -p
5.6.创建Hive数据库
mysql>create database hive;

6.启动Hive
6.1.启动hadoop
6.2. 进入bin目录初始化表数据
hadoop@master:~/software/apache-hive-2.3.0-bin/binKaTeX parse error: Expected 'EOF', got '&' at position 82: …vice metastore &̲ 在 master 节点上运行… hive
6.5.客户端(slave)访问
hadoop@slave2:~$ hive

在这里插入代码片

开发者涨薪指南 Hadoop集群中hive搭建 48位大咖的思考法则、工作方式、逻辑体系