第三篇: Hive安装步骤 |《自己动手做大数据系统》读书笔记

1 安装MySQL


以安装在master为例:

hadoop@master:~$ sudo apt-get install mysql-server mysql-client

设置root用户密码为123456

登陆MySQL创建Hive元数据库,并授权hive用户。

创建语句如下:

create database hivemeta;

alter database hivemeta character set latin1;

grant all privileges on *.* to hive@"master" identified by "123456" with grant option;

flush privileges;

MySQL安装在其他主机,创建语句如下:

create database hivemeta;

alter database hivemeta character set latin1;

grant all privileges on *.* to hive@"%" identified by "123456" with grant option;

flush privileges;

查看数据库及授权用户信息:

hadoop@master:~$ mysql -uroot -p123456
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.5.62-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2018, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| hivemeta           |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.03 sec)

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> select host, user, password from user;
+-----------+------------------+-------------------------------------------+
| host      | user             | password                                  |
+-----------+------------------+-------------------------------------------+
| localhost | root             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| master    | root             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 127.0.0.1 | root             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ::1       | root             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost | debian-sys-maint | *54F95D9F05A61F97757EF9468057B658D8C5AB23 |
| %         | hive             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| master    | hive             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| 127.0.0.1 | hive             | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+------------------+-------------------------------------------+
8 rows in set (0.00 sec)

mysql> 

如果后面步骤中Hive不能启动,则设置my.cnf

hadoop@master:~$ vi /etc/mysql/my.cnf 
bind-address        = 192.168.1.245   # 不能使用默认参数,修改为master的ip

2 安装Hive


下载hive:

hadoop@master:~$ wget https://archive.apache.org/dist/hive/hive-1.2.1/apache-hive-1.2.1-bin.tar.gz

安装hive:

hadoop@master:~$ tar zxvf apache-hive-1.2.1-bin.tar.gz -C bigdata/
hadoop@master:~$ cd bigdata/
hadoop@master:~/bigdata$ mv apache-hive-1.2.1-bin hive

环境变量:

hadoop@master:~/bigdata$ vi /home/hadoop/.bashrc
export HIVE_HOME=/home/hadoop/bigdata/hive
export PATH=$HIVE_HOME/bin:$PATH

使环境变量设置生效:

hadoop@master:~$ source /home/hadoop/.bashrc

验证:

hadoop@master:~$ env | grep HIVE
HIVE_HOME=/home/hadoop/bigdata/hive

修改配置参数文件:

hadoop@master:~$ cd /home/hadoop/bigdata/hive/conf/
hadoop@master:~/bigdata/hive/conf$ cp hive-default.xml.template hive-site.xml
hadoop@master:~/bigdata/hive/conf$ cp hive-env.sh.template hive-env.sh
hadoop@master:~/bigdata/hive/conf$ cp hive-log4j.properties.template hive-log4j.properties

hive-env.sh

hadoop@master:~/bigdata/hive/conf$ diff hive-env.sh.template hive-env.sh
54a55,57
> 
> export HADOOP_HOME=/home/hadoop/bigdata/hadoop
> export HIVE_CONF_DIR=/home/hadoop/bigdata/hive/conf

hive-log4j.properties

hadoop@master:~/bigdata/hive/conf$ diff hive-log4j.properties.template hive-log4j.properties
20c20,21
< hive.log.dir=${java.io.tmpdir}/${user.name}
---
> # hive.log.dir=${java.io.tmpdir}/${user.name}
> hive.log.dir=/home/hadoop/bigdata/hive/log

hive-site.xml

hadoop@master:~/bigdata/hive/conf$ diff hive-default.xml.template hive-site.xml 47,48c47
<     <value>/tmp/hive</value>
<     <description>HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: ${hive.exec.scratchdir}/&lt;username&gt; is created, with ${hive.scratch.dir.permission}.</description>
---
>     <value>hdfs://master:9000/hive/scratchdir</value>
52,53c51
<     <value>${system:java.io.tmpdir}/${system:user.name}</value>
<     <description>Local scratch space for Hive jobs</description>
---
>     <value>/home/hadoop/bigdata/hive/iotmp</value>
57,58c55
<     <value>${system:java.io.tmpdir}/${hive.session.id}_resources</value>
<     <description>Temporary local directory for added resources in the remote file system.</description>
---
>     <value>/home/hadoop/bigdata/hive/iotmp</value>
335,336c332
<     <value>/user/hive/warehouse</value>
<     <description>location of default database for the warehouse</description>
---
>     <value>hdfs://master:9000/hive/warehouse</value>
340,341c336
<     <value/>
<     <description>Thrift URI for the remote metastore. Used by metastore client to connect to remote metastore.</description>
---
>     <value>thrift://master:9083</value>
381,382c376
<     <value>mine</value>
<     <description>password to use against metastore database</description>
---
>     <value>123456</value>
396,397c390
<     <value>jdbc:derby:;databaseName=metastore_db;create=true</value>
<     <description>JDBC connect string for a JDBC metastore</description>
---
>     <value>jdbc:mysql://master:3306/hivemeta?createDatabaseIfNotExist=true</value>
790,791c783
<     <value>org.apache.derby.jdbc.EmbeddedDriver</value>
<     <description>Driver class name for a JDBC metastore</description>
---
>     <value>com.mysql.jdbc.Driver</value>
815,816c807
<     <value>APP</value>
<     <description>Username to use against metastore database</description>
---
>     <value>hive</value>
1320,1321c1311
<     <value>${system:java.io.tmpdir}/${system:user.name}</value>
<     <description>Location of Hive run time structured log file</description>
---
>     <value>/home/hadoop/bigdata/hive/iotmp</value>

官网下载mysql jdbc驱动,放在lib目录下。

hadoop@master:~$ ls -l /home/hadoop/bigdata/hive/lib/ | grep mysql
-rw-r--r--  1 hadoop hadoop  1007505  4月 22 23:45 mysql-connector-java-5.1.47-bin.jar

3 启动


master启动 metastore 服务:

hadoop@master:~$ nohup hive --service metastore &

slave01启动hiveserver2服务:

hadoop@slave01:~$ nohup hive --service hiveserver2 &

4 验证


hadoop@master:~$ hive
hive> create table test01(id int, name string);
OK
Time taken: 3.734 seconds
hive> show tables;
OK
test01
Time taken: 0.471 seconds, Fetched: 1 row(s)
hive> show databases;
OK
default
test
Time taken: 0.014 seconds, Fetched: 2 row(s) 

5 总结


安装包 百度网盘链接: https://pan.baidu.com/s/1Nxd82L800_JAWqTlZrDSOA 提取码: xwbu

配置参考代码 github: https://github.com/zhixingkad/bigdata

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 224,014评论 6 522
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 95,832评论 3 402
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 171,062评论 0 366
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 60,620评论 1 300
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 69,636评论 6 399
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 53,148评论 1 314
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 41,522评论 3 427
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 40,501评论 0 278
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 47,032评论 1 324
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 39,069评论 3 344
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 41,211评论 1 354
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,848评论 5 350
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 42,541评论 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 33,013评论 0 25
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 34,136评论 1 275
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 49,712评论 3 380
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 46,240评论 2 363

推荐阅读更多精彩内容