开发者社区> sh_jepson> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

Hadoop2.7实战v1.0之Hive-2.0.0+MySQL本地模式安装

简介: 已有环境:Hadoop-2.7.2+zookeeper-3.4.6完全分布式环境搭建(HDFS、YARN HA) Active namenode:sht-sgmhadoopnn-01 Hive服务端客户端、元数据库mysql部署在 active namenode机器上 User:hive Database:hive_local_meta 1.
+关注继续查看
已有环境:Hadoop-2.7.2+zookeeper-3.4.6完全分布式环境搭建(HDFS、YARN HA)
Active namenode:sht-sgmhadoopnn-01
Hive服务端客户端、元数据库mysql部署在 active namenode机器上
User:hive
Database:hive_local_meta

1.Install MySQL5.6.23

2.Create db and user
sht-sgmhadoopnn-01:mysqladmin:/usr/local/mysql:>mysql -uroot -p
mysql> create database hive_local_meta;
Query OK, 1 row affected (0.04 sec)

mysql> create user 'hive' identified by 'hive';
Query OK, 0 rows affected (0.05 sec)

mysql> grant all privileges on hive_local_meta.* to 'hive'@'%';
Query OK, 0 rows affected (0.03 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

3.Install hive-2.0.0
[root@sht-sgmhadoopnn-01 tmp]# wget http://apache.communilink.net/hive/hive-2.0.0/apache-hive-2.0.0-bin.tar.gz

[root@sht-sgmhadoopnn-01 tmp]# tar zxvf apache-hive-2.0.0-bin.tar.gz
[root@sht-sgmhadoopnn-01 tmp]# mv apache-hive-2.0.0-bin /hadoop/hive
[root@sht-sgmhadoopnn-01 tmp]# cd /hadoop/hive 
[root@sht-sgmhadoopnn-01 hive]# ll
total 588
drwxr-xr-x 3 root root   4096 Mar 29 23:19 bin
drwxr-xr-x 2 root root   4096 Mar 29 23:19 conf
drwxr-xr-x 4 root root   4096 Mar 29 23:19 examples
drwxr-xr-x 7 root root   4096 Mar 29 23:19 hcatalog
drwxr-xr-x 4 root root  12288 Mar 29 23:19 lib
-rw-r--r-- 1 root root  26335 Jan 22 12:28 LICENSE
-rw-r--r-- 1 root root    513 Jan 22 12:28 NOTICE
-rw-r--r-- 1 root root   4348 Feb 10 09:50 README.txt
-rw-r--r-- 1 root root 527063 Feb 10 09:56 RELEASE_NOTES.txt
drwxr-xr-x 4 root root   4096 Mar 29 23:19 scripts
[root@sht-sgmhadoopnn-01 hive]#

4.Configure profile
[root@sht-sgmhadoopnn-01 ~]# vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.7.0_67-cloudera
export HADOOP_HOME=/hadoop/hadoop-2.7.2
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib"
export HBASE_HOME=/hadoop/hbase-1.2.0
export ZOOKEEPER_HOME=/hadoop/zookeeper
export HIVE_HOME=/hadoop/hive
export PATH=.:$HADOOP_HOME/bin:$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$HBASE_HOME/bin:$HIVE_HOME/bin:$PATH
[root@sht-sgmhadoopnn-01 ~]# source /etc/profile
[root@sht-sgmhadoopnn-01 ~]#

5.configure jdbc jar
[root@sht-sgmhadoopnn-01 tmp]# wget http://ftp.nchu.edu.tw/Unix/Database/MySQL/Downloads/Connector-J/mysql-connector-java-5.1.36.tar.gz
[root@sht-sgmhadoopnn-01 tmp]# tar zxvf  mysql-connector-java-5.1.36.tar.gz
[root@sht-sgmhadoopnn-01 tmp]# cd mysql-connector-java-5.1.36
[root@sht-sgmhadoopnn-01 mysql-connector-java-5.1.36]# ll
total 1428
-rw-r--r-- 1 root root  90430 Jun 20  2015 build.xml
-rw-r--r-- 1 root root 235082 Jun 20  2015 CHANGES
-rw-r--r-- 1 root root  18122 Jun 20  2015 COPYING
drwxr-xr-x 2 root root   4096 Mar 29 23:35 docs
-rw-r--r-- 1 root root 972009 Jun 20  2015 mysql-connector-java-5.1.36-bin.jar
-rw-r--r-- 1 root root  61423 Jun 20  2015 README
-rw-r--r-- 1 root root  63674 Jun 20  2015 README.txt
drwxr-xr-x 8 root root   4096 Jun 20  2015 src
[root@sht-sgmhadoopnn-01 mysql-connector-java-5.1.36]# cp mysql-connector-java-5.1.36-bin.jar $HIVE_HOME/lib/

6.Configure hive-site.xml

点击(此处)折叠或打开

  1. [root@sht-sgmhadoopnn-01 ~]# cd $HIVE_HOME/conf
  2. [root@sht-sgmhadoopnn-01 conf]# cp hive-default.xml.template hive-default.xml

  3. [root@sht-sgmhadoopnn-01 conf]# vi hive-site.xml
  4. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  5. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

  6. <configuration>
  7.      <property>
  8.      <name>hive.metastore.warehouse.dir</name>
  9.      <value>/user/hive_local/warehouse</value>
  10.       </property>

  11.       <property>
  12.      <name>hive.metastore.local</name>
  13.      <value>true</value>
  14.       </property>

  15.     <property>
  16.         <name>javax.jdo.option.ConnectionURL</name>
  17.         <value>jdbc:mysql://localhost:3306/hive_local_meta?createDatabaseIfNotExist=true</value>
  18.         <description>JDBC connect string for a JDBC metastore</description>
  19.     </property>
  20.     <property>
  21.         <name>javax.jdo.option.ConnectionDriverName</name>
  22.         <value>com.mysql.jdbc.Driver</value>
  23.         <description>Driver class name for a JDBC metastore</description>
  24.     </property>

  25.     <property>
  26.         <name>javax.jdo.option.ConnectionUserName</name>
  27.         <value>hive</value>
  28.         <description>username to use against metastore database</description>
  29.     </property>
  30.     <property>
  31.         <name>javax.jdo.option.ConnectionPassword</name>
  32.         <value>hive</value>
  33.         <description>password to use against metastore database</description>
  34.     </property>
  35. </configuration>

  36. "hive-site.xml" 26L, 1056C written
7.第一次运行  bin/hive 客户端
[root@sht-sgmhadoopnn-01 hive-2.0.0]# cd bin
[root@sht-sgmhadoopnn-01 bin]# hive
Logging initialized using configuration in jar:file:/hadoop/hive-2.0.0/lib/hive-common-2.0.0.jar!/hive-log4j2.properties
Exception in thread "main" java.lang.RuntimeException: Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql)

[root@sht-sgmhadoopnn-01 bin]# ll
total 64
-rwxr-xr-x 1 root root 1434 Feb 10 09:50 beeline
-rwxr-xr-x 1 root root 2553 Dec  1 05:54 beeline.cmd
drwxr-xr-x 3 root root 4096 Mar 29 23:19 ext
-rwxr-xr-x 1 root root 8494 Feb 10 09:56 hive
-rwxr-xr-x 1 root root 8713 Dec  1 05:54 hive.cmd
-rwxr-xr-x 1 root root 1584 Apr 23  2015 hive-config.cmd
-rwxr-xr-x 1 root root 1900 Apr 23  2015 hive-config.sh
-rwxr-xr-x 1 root root  885 Apr 23  2015 hiveserver2
-rwxr-xr-x 1 root root 1030 Jan 22 12:28 hplsql
-rwxr-xr-x 1 root root 2278 Jan 22 12:28 hplsql.cmd
-rwxr-xr-x 1 root root  832 Apr 23  2015 metatool
-rwxr-xr-x 1 root root  884 Apr 23  2015 schematool
You have mail in /var/spool/mail/root

8.初始化 db
[root@sht-sgmhadoopnn-01 bin]# schematool -initSchema -dbType mysql
Metastore connection URL:        jdbc:mysql://localhost/hive?createDatabaseIfNotExist=true
Metastore Connection Driver :    com.mysql.jdbc.Driver
Metastore connection User:       hive
Starting metastore schema initialization to 2.0.0
Initialization script hive-schema-2.0.0.mysql.sql
Initialization script completed
schemaTool completed
You have mail in /var/spool/mail/root
[root@sht-sgmhadoopnn-01 bin]#

9.查看MySQL元数据,show tables
sht-sgmhadoopnn-01.telenav.cn:mysqladmin:/usr/local/mysql:>mysql -uhive -p
mysql> use hive;
Database changed

mysql> show tables;
+---------------------------+
| Tables_in_hive            |
+---------------------------+
| aux_table                 |
| bucketing_cols            |
...............
...............

| tbls                      |
| txn_components            |
| txns                      |
| type_fields               |
| types                     |
| version                   |
+---------------------------+
55 rows in set (0.00 sec)

10.测试,创建表,插入数据
## "tab制表符"分隔
[root@sht-sgmhadoopnn-01 conf]# vi /tmp/studentInfo.txt
1       a       26      110
2       b       29      120
~

[root@sht-sgmhadoopnn-01 bin]# hive
Logging initialized using configuration in jar:file:/hadoop/hive-2.0.0/lib/hive-common-2.0.0.jar!/hive-log4j2.properties
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. tez, spark) or using Hive 1.X releases.
hive> create table studentinfo (id int,name string, age int,tel string)
   > row format delimited  fields terminated by '\t'
   > stored as textfile;
OK
Time taken: 2.347 seconds
hive> load data local inpath '/tmp/studentInfo.txt'  into table studentinfo;
Loading data to table default.studentinfo
OK
Time taken: 1.383 seconds
hive> select * from studentinfo;
OK
1       a       26      110
2       b       29      120
Time taken: 0.173 seconds, Fetched: 2 row(s)
hive> exit();

11.再次修改两个参数
# "hdfs://mycluster"是指$HADOOP_HOME/etc/hadoop/core-site.xml文件的fs.defaultFS的值(NameNode HA URI)

点击(此处)折叠或打开

  1. [root@sht-sgmhadoopnn-01 conf]# vi hive-site.xml
  2.       <property>
  3.      <name>hive.metastore.warehouse.dir</name>
  4.      <value>hdfs://mycluster/user/hive_local/warehouse</value>
  5.       </property>

  6.     <property>
  7.         <name>javax.jdo.option.ConnectionURL</name>
  8.         <value>jdbc:mysql://sht-sgmhadoopnn-01:3306/hive_local_meta?createDatabaseIfNotExist=true</value>
  9.         <description>JDBC connect string for a JDBC metastore</description>
  10.     </property>
11.再次验证修改的内容,是否成功创建classInfo
[root@sht-sgmhadoopnn-01 bin]# hive
Logging initialized using configuration in jar:file:/hadoop/hive-2.0.0/lib/hive-common-2.0.0.jar!/hive-log4j2.properties
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. tez, spark) or using Hive 1.X releases.
hive> create table classInfo(id int,classname string,stucount int) row format delimited  fields terminated by '\t'
   > stored as textfile;
OK
Time taken: 2.257 seconds
hive>

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
安装 MySql | 学习笔记
快速学习安装 MySql。
54 0
windows 10 下 mysql的安装
win10下 mysql的安装 今天在win10下装Mysql,总结一下安装详细过程: 1、下载【先进入官网: https://www.mysql.com/】(按照如下截图一步一步执行即可)           2、安装 下载出来的会是一个压缩包,解压到你打算安装的目录下边(不像图形化界面安装那样还需要点击一系列【next】),但是离完全安装成功,现在才是刚刚开始。
1565 0
mac下安装mysql
mac下安装mysql 根据我的自身经验来看,windows、liunx、mac这三个平台来看,mac上安装到正常运行是最耗我时间的。因此纪录下来,下次遇到有地方可查。 1、mysql下载安装: https://dev.mysql.com/downloads/mysql/ 这里要注意的是,最好安装和你系统匹配的版本,不然后续可能会遇到一些奇怪的错误。
4280 0
Mac上安装MySQL
版权声明:欢迎转载,请注明沉默王二原创。 https://blog.csdn.net/qing_gee/article/details/73824618 本篇文章没有技术含量,重在传播。
591 0
Windows 10下mysql 64位 安装(mysql-5.7.11-winx64安装)
Windows下mysql 64位 安装(mysql-5.7.11-winx64安装) 系统Windows10 安装包mysql-5.7.11-winx64.zip 安装过程中遇到的问题,请留意4.0常见问题汇总,常见问题都可解决。 附上最近一次完成安装记录,给大忙人看的只有两张图和完整的命令。 完成的命令 C:\Windows\syst
2563 0
Mac下安装MySQL
2015-07-13 15:10:32 Mac下用homebrew安装软件还是很方便的 brew install mysql 等待一会儿安装完毕后到安装目录:  /usr/local/Cellar/mysql/5.
760 0
MAC下homebre安装mysql
1.执行安装命令 brew install mysql 2.执行完输入mysql会有如下bug ERROR 2002 (HY000): Can not connect to local MySQL server through socket '/tmp/mysql.sock' (2) 3.bug解决方案 unset TMPDIR 4.然后 mysql_install_db --verbos
847 0
+关注
sh_jepson
遇之问题,与之斗争,穷尽方法,提高自己,重新再来。 https://github.com/Hackeruncle
178
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载