大數據之Hive安裝配置

2020-12-14 CDA數據分析師

hive默認將元數據存儲到本地內嵌的Derby資料庫中,但是Derby不支持多會話連結,因此我們使用mysql資料庫來存儲hive的元數據。配置完成hiveSQL的元資料庫之後再開始安裝、配置hive。

1、在線安裝mysql

安裝命令為

sudo apt-get install mysql-server

當出現下面提示選擇的時候輸入y 同意繼續安裝

hduser@master:~$ sudo apt-get installmysql-server

Reading packagelists... Done

Building dependency tree

Reading state information... Done

The followingpackages were automatically installed andareno longer required:

linux-headers-4.13.0-36 linux-headers-4.13.0-36-generic

linux-headers-4.13.0-41 linux-headers-4.13.0-41-generic

linux-image-4.13.0-36-generic linux-image-4.13.0-41-generic

linux-image-extra-4.13.0-36-generic linux-image-extra-4.13.0-41-generic

Use'sudo apt autoremove' to remove them.

The followingadditional packages will be installed:

libaio1 libevent-core-2.0-5 libhtml-template-perl mysql-client-5.7

mysql-client-core-5.7 mysql-common mysql-server-5.7 mysql-server-core-5.7

Suggested packages:

libipc-sharedcache-perl mailx tinyca

The followingNEWpackages will be installed:

libaio1 libevent-core-2.0-5 libhtml-template-perl mysql-client-5.7

mysql-client-core-5.7 mysql-common mysql-servermysql-server-5.7

mysql-server-core-5.7

0 upgraded, 9 newly installed, 0 toremove and 101 not upgraded.

Need toget18.1 MB of archives.

Afterthis operation, 161 MB of additional disk space will be used.

Doyou want to continue? [Y/n] y

然後安裝繼續執行,輸出如下內容,完成安裝。中間會有讓設置root密碼提示,輸入密碼按向下的方向鍵確認,然後再輸入一次確認密碼

Get:1 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 mysql-commonall 5.7.22-0ubuntu0.16.04.1 [15.4 kB]

Get:2 http://mirrors.aliyun.com/ubuntu xenial/main amd64 libaio1 amd64 0.3.110-2 [6,356 B]

Get:3 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 mysql-client-core-5.7 amd64 5.7.22-0ubuntu0.16.04.1[6,425 kB]

Get:4 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 mysql-client-5.7 amd64 5.7.22-0ubuntu0.16.04.1[1,673 kB]

Get:5 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 mysql-server-core-5.7 amd64 5.7.22-0ubuntu0.16.04.1[7,268 kB]

Get:6 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 libevent-core-2.0-5 amd64 2.0.21-stable-2ubuntu0.16.04.1[70.6 kB]

Get:7 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 mysql-server-5.7 amd64 5.7.22-0ubuntu0.16.04.1[2,583 kB]

Get:8 http://mirrors.aliyun.com/ubuntu xenial/main amd64 libhtml-template-perl all 2.95-2 [60.4 kB]

Get:9 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 mysql-server all 5.7.22-0ubuntu0.16.04.1[10.8 kB]

Fetched 18.1 MB in1min 56s (155 kB/s)

Preconfiguring packages ...

Selecting previously unselected package mysql-common.

(Reading database ... 285825 files anddirectories currently installed.)

Preparing to unpack .../mysql-common_5.7.22-0ubuntu0.16.04.1_all.deb ...

Unpacking mysql-common(5.7.22-0ubuntu0.16.04.1) ...

Selecting previously unselected package libaio1:amd64.

Preparing to unpack .../libaio1_0.3.110-2_amd64.deb ...

Unpacking libaio1:amd64 (0.3.110-2) ...

Selecting previously unselected package mysql-client-core-5.7.

Preparing to unpack .../mysql-client-core-5.7_5.7.22-0ubuntu0.16.04.1_amd64.deb ...

Unpacking mysql-client-core-5.7 (5.7.22-0ubuntu0.16.04.1) ...

Selecting previously unselected package mysql-client-5.7.

Preparing to unpack .../mysql-client-5.7_5.7.22-0ubuntu0.16.04.1_amd64.deb ...

Unpacking mysql-client-5.7 (5.7.22-0ubuntu0.16.04.1) ...

Selecting previously unselected package mysql-server-core-5.7.

Preparing to unpack .../mysql-server-core-5.7_5.7.22-0ubuntu0.16.04.1_amd64.deb ...

Unpacking mysql-server-core-5.7 (5.7.22-0ubuntu0.16.04.1) ...

Selecting previously unselected package libevent-core-2.0-5:amd64.

Preparing to unpack .../libevent-core-2.0-5_2.0.21-stable-2ubuntu0.16.04.1_amd64.deb ...

Unpacking libevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...

Processing triggers for libc-bin (2.23-0ubuntu10) ...

Processing triggers for man-db (2.7.5-1) ...

Setting upmysql-common (5.7.22-0ubuntu0.16.04.1) ...

update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) inauto mode

Selecting previously unselected package mysql-server-5.7.

(Reading database ... 285993 files anddirectories currently installed.)

Preparing to unpack .../mysql-server-5.7_5.7.22-0ubuntu0.16.04.1_amd64.deb ...

Unpacking mysql-server-5.7 (5.7.22-0ubuntu0.16.04.1) ...

Selecting previously unselected package libhtml-template-perl.

Preparing to unpack .../libhtml-template-perl_2.95-2_all.deb ...

Unpacking libhtml-template-perl (2.95-2) ...

Selecting previously unselected package mysql-server.

Preparing to unpack .../mysql-server_5.7.22-0ubuntu0.16.04.1_all.deb ...

Unpacking mysql-server (5.7.22-0ubuntu0.16.04.1) ...

Processing triggers for man-db (2.7.5-1) ...

Processing triggers for ureadahead (0.100.0-19) ...

Processing triggers for systemd (229-4ubuntu21.1) ...

Setting uplibaio1:amd64 (0.3.110-2) ...

Setting upmysql-client-core-5.7 (5.7.22-0ubuntu0.16.04.1) ...

Setting upmysql-client-5.7 (5.7.22-0ubuntu0.16.04.1) ...

Setting upmysql-server-core-5.7 (5.7.22-0ubuntu0.16.04.1) ...

Setting uplibevent-core-2.0-5:amd64 (2.0.21-stable-2ubuntu0.16.04.1) ...

Setting upmysql-server-5.7 (5.7.22-0ubuntu0.16.04.1) ...

update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) inauto mode

Renaming removed key_buffer andmyisam-recover options (if present)

Setting uplibhtml-template-perl (2.95-2) ...

Setting upmysql-server (5.7.22-0ubuntu0.16.04.1) ...

Processing triggers for libc-bin (2.23-0ubuntu10) ...

Processing triggers for systemd (229-4ubuntu21.1) ...

Processing triggers for ureadahead (0.100.0-19) ...

使用如下命令登錄MySQL伺服器。在提示輸入密碼的地方輸入剛才設置的root密碼

hduser@master:/etc/network$ mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.22-0ubuntu0.16.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 |

| mysql |

| performance_schema |

| sys |

+--------------------+

4 rows in set (0.00 sec)

mysql>

2、在Mysql中創建hive元數據資料庫

創建hive資料庫

mysql> createdatabasehive;

將hive資料庫的所有權限賦給hive用戶

mysql>create user 'hive'@'%' identified by 'hive';

mysql>grant all privileges on *.* to 'hive'@'%' with grant option;

mysql>flush privileges;

mysql>use hive;

mysql>select user,host,password from mysql.user;

註:在ubuntu中,默認情況下MySQL只允許登陸,所以需要修改配置文件將地址綁定注釋掉

sudo vim /etc/mysql/my.cnf

#bind-address = 127.0.0.1 #注釋掉

3、安裝hive

下載最新穩定版hive

https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.3/apache-hive-2.3.3-bin.tar.gz

上傳到master節點的/home/hduser/Downloads目錄下

解壓

tar -zxvf Downloads/apache-hive-2.3.3-bin.tar.gz

更改安裝文件名稱

hduser@master:~$ mv apache-hive-2.3.3-bin/ ./hive

hduser@master:~$

配置用戶環境變量

vim ~/.bashrc

在文件末尾添加如下內容

#HIVE

export HIVE_HOME=/home/hduser/hive

export PATH=$PATH:$HIVE_HOME/bin

最後重新導入環境變量

source ~/.bashrc

註:通過source方法只是臨時重置了系統環境變量,若想系統環境變量永久生效重啟是不錯的方法

4、配置hive參數

配置hive-site.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<configuration>

<!--指定元資料庫連接信息-->

<property>

<name>javax.jdo.option.ConnectionURL</name>

<value>jdbc:mysql://master: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>

</configuration>

我們也可指定某個文件夾來存放元數據

<property>

<name>hive.metastore.warehouse.dir</name>

<value>/home/hduser/hive/warehouse</value>

<description>location of default database for the warehouse</description>

</property>

下載mysql-connector-java-5.1.46.tar.gz,下載連結為

https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-5.1.46.tar.gz

將其解壓後在文件夾中選擇mysql-connector-java-5.1.46-bin.jar上傳到master節點的/home/hduser/Downloads目錄下。最後將JDBC文件放到hive的lib文件夾內即可。

5、啟動hive

Hive數據存儲到HDFS上,因此要先啟動hadoop

start-all.sh

格式化hive

schematool -dbType mysql -initSchema

啟動hive命令行

hive

HiveSQL的優點是學習成本低,可以通過類似SQL語句實現快速MapReduce統計,使MapReduce變得更加簡單,而不必開發專門的MapReduce應用程式。hive是十分適合數據倉庫的統計分析和Windows註冊表文件。

相關焦點

  • Hadoop大數據實戰系列文章之Hive
    2) Metastore 組件:元數據服務組件存儲hive 的元數據,hive的元數據存儲在關係資料庫裡,hive 支持的關係資料庫有 derby、mysql。Hive 還支持把 metastore服務安裝到遠程的伺服器集群裡,從而解耦 hive 服務和metastore 服務。
  • 大數據分析師工程師入門6-HIVE進階
    針對mapreduce的過程來說主要表現是:任務進度長時間維持在 99%或者 100%的附近,查看任務監控頁面,發現只有少量 reduce 子任務未完成,因為其處理的數據量和其他的 reduce 差異過大。單一 reduce 處理的記錄數和平均記錄數相差太大,通常達到好幾倍之多,最長時間遠大於平均時長。
  • 尚矽谷大數據視頻_Hive視頻教程
    Hive同時也是進入網際網路行業的大數據開發工程師必備技術之一。在本課程中,你將學習到,Hive架構原理、安裝配置、hiveserver2、數據類型、數據定義、數據操作、查詢、自定義UDF函數、窗口函數、壓縮和存儲、企業級調優、以及結合穀粒影音項目需求,把整個Hive的核心知識點貫穿起來。
  • 訪問Hive數據的幾種騷姿勢
    會啟動一個hive服務端默認埠為:10000,可以通過beeline,jdbc,odbc的方式連結到hive。hiveserver2啟動的時候會先檢查有沒有配置hive.metastore.uris,如果沒有會先啟動一個metastore服務,然後在啟動hiveserver2。如果有配置hive.metastore.uris。會連接到遠程的metastore服務。
  • Hive數據倉庫實戰
    Hive作為大數據平臺Hadoop之上的主流應用,公司一般都是用它作為公司的數據倉庫,分布式機器學習的訓練數據和數據處理也經常用它來處理,下面介紹下它的常用功能。Hive原理和功能介紹Hive是建立在 Hadoop 上的數據倉庫基礎構架。
  • Hadoop數據分析之Hive
    對於Hive來說默認就是mapreduce任務Hive:數據類型基本數據類型類型名稱描述舉例booleantrue/falsetruetinyint1位元組的有符號整數1smallint2位元組的有符號整數1int4位元組的有符號整數1bigint8位元組的有符號整數1float4位元組單精度浮點數1.0
  • 大數據中Hadoop Hive發生數據傾斜的處理方案 絕對是乾貨
    發生數據傾斜的原因有key分布不均勻。map端數據傾斜,輸入文件太多且大小不一 。reduce端數據傾斜,分區器問題。業務數據本身的特徵。hive中的解決方案:1.調節hive配置參數設置hive.map.aggr = true map端部分聚合,相當於Combiner設置hive.groupby.skewindata = true 有數據傾斜時,查詢計劃生成兩個mr job,
  • Hive 如何快速拉取大批量數據
    用hive來做數倉類操作,或者大數據的運算,是沒有疑問的,至少在你沒有更多選擇之前。當我們要hive來做類似於大批量數據的select時,也許問題就會發生了變化。 1.
  • 大數據面試題(Hive優化措施)
    大家好,我是驀然,這一系列大數據面試題是我秋招時自己總結準備的,後續我會總結出PDF版,希望對大家有幫助!
  • 深入淺出Hive數據傾斜
    (0,"hive spark hive hbase") (21,"hadoop hive spark hive") (39,"sqoop flume scala scala")1.2 Map任務將1.1產生的 <k,v>值轉換為新的<k,v>值,並將這個結果存入環形緩衝內存中(溢出的部分存入磁碟),具體數據如下:
  • Hive On LLAP搭建&常見問題
    首先進入腳本目錄,分別在node01、node02、node03中編輯frames.txt配置文件,添加zookeeper的安裝信息。這裡也可以安裝其它版本,自行更改配置即可。在node01、node02、node03上調用腳本進行一鍵安裝。
  • Hive高級-調優
    Hive調優策略Hive作為大數據領域常用的數據倉庫組件,在設計和開發階段需要注意效率。影響Hive效率的不僅僅是數據量過大;數據傾斜、數據冗餘、job(小文件多)或I/O過多、MapReduce分配不合理等因素都對Hive的效率有影響。
  • 小白篇(十八):恢復Hive誤刪的表數據
    Hive數據恢復步驟1、通過Hue界面,找到被刪除表在Hdfs中垃圾回收站的位置(HDFS默認回收站保留時間為3天,可通過配置調整保留期限)。如果界面用得不習慣,可直接hdfs dfs指令去查找被刪除表所在位置。
  • 手把手教你在 Windows 平臺搭建本地 Hive 訪問環境
    spark-sql訪問已經被hive創建的表出現的問題簡介學習大數據最痛苦和費時間的就是入門時的環境搭建,對於大數據工程師而言,這個過程必不可少,但對於一些簡單的測試,每次都要打開自己搭建好的虛擬機,未免有些麻煩。對於數據分析師而言,一般只需要使用hive和spark就好,搭建集群實在是一件費力沒有效果的事。
  • Hive SQL基本使用詳解
    Hive 並非為聯機事務處理而設計,Hive 並不提供實時的查詢和基於行級的數據更新操作。Hive 的最佳使用場合是大數據集的批處理作業。Hive SQL 與 SQL的區別:HQL不支持行級別的增(insert into table values)、改、刪,所有數據在加載時就已經確定,不可更改。
  • 代碼 | Spark讀取mongoDB數據寫入Hive普通表和分區表
    Hive ordinary table");            Long t1 = System.currentTimeMillis();            spark.sql("insert into mgtohive_2 " + querysql + " " + "where b.id not in (select id from mgtohive_2)");
  • 好程式設計師大數據培訓分享大數據技術Hbase和Hive詳解
    好程式設計師大數據培訓分享大數據技術Hbase和Hive詳解,今天給大家介紹一下關於零基礎學習大數據視之HBASE和HIVE是多麼重要的技術,那麼兩者有什麼區別呢?下面我們一起來看一下吧。
  • 大數據學習環境搭建系列(一)大數據集群平臺介紹
    作者 | CDA數據分析師掌握搭建大數據集群的方法是學習大數據技術的人需要具備的基礎技能,因此我會通過接下來的三十餘篇文章介紹大數據平臺的搭建方法。在本文中我將向小夥伴們介紹一下搭建大數據集群需要哪些知識以及我們接下來搭建的大數據集群平臺架構,讓大家對平臺有個總體的認識並普及一些概念。
  • 大數據快速入門(09):永久弄清楚 Hive 分區表和分桶表的區別
    set hive.exec.dynamic.partition.mode=nonstrict  //分區模式,默認nostrictset hive.exec.dynamic.partition=true      //開啟動態分區,默認trueset hive.exec.max.dynamic.partitions=1000
  • 「大數據進擊之路」——Apache Hive的架構及其特性總結
    非易失性:數倉式數據分析的平臺,不是數據創造的平臺,分析數據的規律而不是修改創造數據的規律。數倉的數據都是已經生產的歷史數據,已經是客觀事實!時變性:數倉的數據會隨著時間成周期性變化,分析的頻率相關,一年一分析?一季度?一月?一天?一小時?