Hadoop 搭建Hive环境

2021-05-30  本文已影响0人  Yohann丶blog
7741622360580_.pic_hd.jpg

环境

Mysql安装

$ 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
$ 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
$ sudo service mysql status

Mysql设置root密码

$ sudo service mysql stop
$ sudo mysqld_safe --skip-grant-tables
$ mysql -u root
mysql> use mysql;
mysql> update user set password = password('root') where user = 'root';
mysql> flush privileges;
mysql> quit;
$ sudo service mysql restart

Mysql设置hive用户

# 创建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;
$ mysql -uhive -phive -h hadoop
 # 若存在则无需再创建
mysql> create database hive;
# 查看数据库
mysql> show databases;

Hive安装

$ wget http://archive.apache.org/dist/hive/hive-0.12.0/hive-0.12.0-bin.tar.gz
$ 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 目录下

$ wget https://downloads.mysql.com/archives/get/p/3/file/mysql-connector-java-5.1.22.tar.gz
$ 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配置

$ sudo vi /etc/profile

export HIVE_HOME=/app/hive-0.12.0
export PATH=$PATH:$HIVE_HOME/bin
export CLASSPATH=$CLASSPATH:$HIVE_HOME/bin
$ source /etc/profile
$ cd /app/hive-0.12.0/conf/
$ cp hive-env.sh.template hive-env.sh
export HADOOP_HOME=/app/hadoop-1.1.2
export HIVE_CONF_DIR=/app/hive-0.12.0/conf

设置 HADOOP_HOME 和 HIVE_CONF_DIR。

$ cp hive-default.xml.template hive-site.xml
# 添加配置项
<property>
  <name>hive.metastore.local</name>
  <value>false</value>
</property>
# 修改配置项
<property>
  <name>hive.metastore.uris</name>
  <value>thrift://hadoop:9083</value>
  <description>Thrift URI for the remote metastore. ...</description>
</property>
<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://hadoop:3306/hive?=createDatabaseIfNotExist=true</value>
  <description>JDBC connect string for a JDBC metastore</description>
</property>
<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.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.schema.verification</name>
  <value>false</value>
  <desc....>
</property>

验证环境

$ sudo service mysql restart
$ hive --service metastore &
$ hive --service hiveserver &
$ jps
12662 NameNode
14370 RunJar
12918 SecondaryNameNode
14586 RunJar
13131 TaskTracker
6767 Jps
14008 DataNode
13013 JobTracker

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

$ hive
# 创建表
hive> create table test(a string, b int);
# 查看表
hive> show tables;
# 查看test表结构
hive> desc test;
# 退出
hive> quit;
$ 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)
上一篇 下一篇

猜你喜欢

热点阅读