Hadoop 搭建Hive环境

7741622360580_.pic_hd.jpg

环境

  • CentOS 6.8 64位 1核 2GB

  • JDK 1.7.0_75 64 位

  • Hadoop 1.1.2

  • Mysql 5.6.21

  • Hive 0.12.0

Mysql安装

  • 下载 mysql 安装包
1
2
3
$ wget https://downloads.mysql.com/archives/get/p/23/file/MySQL-server-5.6.21-1.el6.x86_64.rpm
$ wget https://downloads.mysql.com/archives/get/p/23/file/MySQL-client-5.6.21-1.el6.x86_64.rpm
$ wget https://downloads.mysql.com/archives/get/p/23/file/MySQL-devel-5.6.21-1.el6.x86_64.rpm
  • 安装 mysql
1
2
3
$ sudo rpm -ivh MySQL-server-5.6.21-1.el6.x86_64.rpm
$ sudo rpm -ivh MySQL-client-5.6.21-1.el6.x86_64.rpm
$ sudo rpm -ivh MySQL-devel-5.6.21-1.el6.x86_64.rpm
  • 查看 mysql 状态
1
$ sudo service mysql status

Mysql设置root密码

  • 停止 mysql 服务
1
$ sudo service mysql stop
  • 跳过验证启动 mysql
1
$ sudo mysqld_safe --skip-grant-tables
  • 登录 mysql 设置密码
1
2
3
4
5
$ mysql -u root
mysql> use mysql;
mysql> update user set password = password('root') where user = 'root';
mysql> flush privileges;
mysql> quit;
  • 重启 mysql
1
$ sudo service mysql restart

Mysql设置hive用户

  • 设置 hive 用户
1
2
3
4
5
6
7
8
#  创建hive用户
mysql> create user 'hive' identified by 'hive';
# 赋予权限
mysql> grant all on *.* TO 'hive'@'%' identified by 'hive' with grant option;
mysql> grant all on *.* TO 'hive'@'localhost' identified by 'hive' with grant option;
# 刷新生效
mysql> flush privileges;
mysql> quit;
  • 使用 hive 用户登录 mysql
1
2
3
4
5
$ mysql -uhive -phive -h hadoop
# 若存在则无需再创建
mysql> create database hive;
# 查看数据库
mysql> show databases;

Hive安装

  • 下载 hive 安装包
1
$ wget http://archive.apache.org/dist/hive/hive-0.12.0/hive-0.12.0-bin.tar.gz
  • 解压 hive 安装包
1
2
$ tar -xzf hive-0.12.0-bin.tar.gz
$ mv hive-0.12.0-bin /app/hive-0.12.0

解压后,将 hive-0.12.0-bin 移动到 /app 目录下

  • 下载 mysql 驱动包
1
$ wget https://downloads.mysql.com/archives/get/p/3/file/mysql-connector-java-5.1.22.tar.gz
  • 解压 mysql 驱动包
1
2
$ tar -xzf mysql-connector-java-5.1.22.tar.gz
$ cp mysql-connector-java-5.1.22/mysql-connector-java-5.1.22-bin.jar /app/hive-0.12.0/lib

解压后,将 mysql-connector-java-5.1.22-bin.jar 复制到 /app/hive-0.12.0/lib 目录下

Hive配置

  • 修改 /etc/profile 文件
1
$ sudo vi /etc/profile
  • 添加 hive 环境变量
1
2
3
4
5
6
export HIVE_HOME=/app/hive-0.12.0
export PATH=$PATH:$HIVE_HOME/bin
export CLASSPATH=$CLASSPATH:$HIVE_HOME/bin
```

- 保存生效

$ source /etc/profile

1
2

- 进入 /app/hive-0.12.0/conf/ 目录

$ cd /app/hive-0.12.0/conf/

1
2

- 复制 hive-env.sh.template 配置文件,命名为 hive-env.sh

$ cp hive-env.sh.template hive-env.sh

1
2

- 修改 hive-env.sh 文件

export HADOOP_HOME=/app/hadoop-1.1.2
export HIVE_CONF_DIR=/app/hive-0.12.0/conf

1
2
3
4

> 设置 HADOOP_HOME 和 HIVE_CONF_DIR。

- 复制 hive-default.xml.template 配置文件,命名为 hive-site.xml

$ cp hive-default.xml.template hive-site.xml

1
2

- 修改 hive-site.xml 文件

添加配置项

hive.metastore.local false # 修改配置项 hive.metastore.uris thrift://hadoop:9083 Thrift URI for the remote metastore. ... javax.jdo.option.ConnectionURL jdbc:mysql://hadoop: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.metastore.schema.verification false
1
2
3
4

# 验证环境

- 重启 mysql
$ sudo service mysql restart
1
2

- 启动 metastore 和 hiveserver 服务
$ hive --service metastore & $ hive --service hiveserver &
1
2

- 查看 metastore 和 hiveserver 服务运行状态
$ jps 12662 NameNode 14370 RunJar 12918 SecondaryNameNode 14586 RunJar 13131 TaskTracker 6767 Jps 14008 DataNode 13013 JobTracker
1
2
3
4

> 可以看到,两个进程 RunJar 运行在后台,分别对应 metastore 和 hiveserver 服务。

- 操作 hive
$ hive # 创建表 hive> create table test(a string, b int); # 查看表 hive> show tables; # 查看test表结构 hive> desc test; # 退出 hive> quit;
1
2

- 操作 mysql
$ mysql -uhive -phive # 选择hive数据库 mysql> use hive; # 在TBLS表中查看刚刚新增的test表 mysql> select TBL_ID, CREATE_TIME, DB_ID, OWNER, TBL_NAME,TBL_TYPE from TBLS; +--------+-------------+-------+--------+----------+---------------+ | TBL_ID | CREATE_TIME | DB_ID | OWNER | TBL_NAME | TBL_TYPE | +--------+-------------+-------+--------+----------+---------------+ | 1 | 1621827317 | 1 | yohann | test | MANAGED_TABLE | +--------+-------------+-------+--------+----------+---------------+ 1 row in set (0.00 sec) ```
-------------本文结束感谢您的阅读-------------
0%