hadoop2-hive的安裝和測試

来源:https://www.cnblogs.com/hongten/archive/2018/10/31/hongten_hadoop_hive.html
-Advertisement-
Play Games

在安裝和測試hive之前,我們需要把Hadoop的所有服務啟動 在安裝Hive之前,我們需要安裝mysql資料庫 ...


在安裝和測試hive之前,我們需要把Hadoop的所有服務啟動

在安裝Hive之前,我們需要安裝mysql資料庫

--mysql的安裝 - (https://segmentfault.com/a/1190000003049498)
--檢測系統是否自帶安裝mysql
yum list installed | grep mysql

--刪除系統自帶的mysql及其依賴
yum -y remove mysql-libs.x86_64


--給CentOS添加rpm源,並且選擇較新的源
wget dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
yum localinstall mysql-community-release-el6-5.noarch.rpm
yum repolist all | grep mysql
yum-config-manager --disable mysql55-community
yum-config-manager --disable mysql56-community
yum-config-manager --enable mysql57-community-dmr
yum repolist enabled | grep mysql

--安裝mysql 伺服器
yum install mysql-community-server

--啟動mysql
service mysqld start

--查看mysql是否自啟動,並且設置開啟自啟動
chkconfig --list | grep mysqld
chkconfig mysqld on

--查找初始化密碼
grep 'temporary password' /var/log/mysqld.log

--mysql安全設置
mysql_secure_installation

--啟動mysql
service mysqld start
--登錄
mysql –u root –p
--設置的密碼
!QAZ2wsx3edc

--開通遠程訪問
grant all on *.* to root@'%' identified by '!QAZ2wsx3edc';

select * from mysql.user;

--讓node1也可以訪問
grant all on *.* to root@'node1' identified by '!QAZ2wsx3edc';

--創建hive資料庫,後面要用到,hive不會 自動創建
create database hive;

 

安裝和配置Hive

--安裝Hive
cd ~
tar -zxvf apache-hive-0.13.1-bin.tar.gz

--創建軟鏈
ln -sf /root/apache-hive-0.13.1-bin /home/hive

--修改配置文件
cd /home/hive/conf/

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

--啟動Hive
cd /home/hive/bin/

./hive

--退出hive
quit;

--修改配置文件
cd /home/hive/conf/

vi hive-site.xml

--以下需要修改的地方
<property>
  <name>javax.jdo.option.ConnectionURL</name>
  <value>jdbc:mysql://node1/hive</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>root</value>
  <description>username to use against metastore database</description>
</property>

<property>
  <name>javax.jdo.option.ConnectionPassword</name>
  <value>!QAZ2wsx3edc</value>
  <description>password to use against metastore database</description>
</property>

:wq

 

添加mysql驅動

--拷貝mysql驅動到/home/hive/lib/
cp -a mysql-connector-java-5.1.23-bin.jar /home/hive/lib/

 

在這裡我寫了一個生成文件的java文件

GenerateTestFile.java

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Random;

/**
 * @author Hongwei
 * @created 31 Oct 2018
 */
public class GenerateTestFile {

    public static void main(String[] args) throws Exception{
        int num = 20000000;
        File writename = new File("/root/output1.txt");
        System.out.println("begin");
        writename.createNewFile();
        BufferedWriter out = new BufferedWriter(new FileWriter(writename));
        StringBuilder sBuilder = new StringBuilder();
        for(int i=1;i<num;i++){
            Random random = new Random();
            sBuilder.append(i).append(",").append("name").append(i).append(",")
.append(random.nextInt(50)).append(",").append("Sales").append("\n");
        }
        System.out.println("done........");
        
        out.write(sBuilder.toString());
        out.flush();
        out.close();
    }
}

 

編譯和運行文件:

cd
javac GenerateTestFile.java
java GenerateTestFile

 

最終就會生成/root/output1.txt文件,為上傳測試文件做準備。

 

啟動Hive

--啟動hive
cd /home/hive/bin/
./hive

 

創建t_tem2表

create table t_emp2(
id int,
name string,
age int,
dept_name string
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ',';

輸出結果:

hive> create table t_emp2(
    > id int,
    > name string,
    > age int,
    > dept_name string
    > )
    > ROW FORMAT DELIMITED
    > FIELDS TERMINATED BY ',';
OK
Time taken: 0.083 seconds

 

上傳文件

load data local inpath '/root/output1.txt' into table t_emp2;

輸出結果:

hive> load data local inpath '/root/output1.txt' into table t_emp2;
Copying data from file:/root/output1.txt
Copying file: file:/root/output1.txt
Loading data to table default.t_emp2
Table default.t_emp2 stats: [numFiles=1, numRows=0, totalSize=593776998, rawDataSize=0]
OK
Time taken: 148.455 seconds

 

 

測試,查看t_temp2表裡面所有記錄的總條數:

hive> select count(*) from t_emp2;
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks determined at compile time: 1
In order to change the average load for a reducer (in bytes):
  set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
  set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
  set mapreduce.job.reduces=<number>
Starting Job = job_1541003514112_0002, Tracking URL = http://node1:8088/proxy/application_1541003514112_0002/
Kill Command = /home/hadoop-2.5/bin/hadoop job  -kill job_1541003514112_0002
Hadoop job information for Stage-1: number of mappers: 3; number of reducers: 1
2018-10-31 09:41:49,863 Stage-1 map = 0%,  reduce = 0%
2018-10-31 09:42:26,846 Stage-1 map = 33%,  reduce = 0%, Cumulative CPU 33.56 sec
2018-10-31 09:42:47,028 Stage-1 map = 44%,  reduce = 0%, Cumulative CPU 53.03 sec
2018-10-31 09:42:48,287 Stage-1 map = 56%,  reduce = 0%, Cumulative CPU 53.79 sec
2018-10-31 09:42:54,173 Stage-1 map = 67%,  reduce = 0%, Cumulative CPU 56.99 sec
2018-10-31 09:42:56,867 Stage-1 map = 78%,  reduce = 0%, Cumulative CPU 57.52 sec
2018-10-31 09:42:58,201 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 58.44 sec
2018-10-31 09:43:16,966 Stage-1 map = 100%,  reduce = 100%, Cumulative CPU 60.62 sec
MapReduce Total cumulative CPU time: 1 minutes 0 seconds 620 msec
Ended Job = job_1541003514112_0002
MapReduce Jobs Launched: 
Job 0: Map: 3  Reduce: 1   Cumulative CPU: 60.62 sec   HDFS Read: 593794153 HDFS Write: 9 SUCCESS
Total MapReduce CPU Time Spent: 1 minutes 0 seconds 620 msec
OK
19999999
Time taken: 105.013 seconds, Fetched: 1 row(s)

 

查詢表中age=20的記錄總條數:

hive> select count(*) from t_emp2 where age=20;
Total jobs = 1
Launching Job 1 out of 1
Number of reduce tasks determined at compile time: 1
In order to change the average load for a reducer (in bytes):
  set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
  set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
  set mapreduce.job.reduces=<number>
Starting Job = job_1541003514112_0003, Tracking URL = http://node1:8088/proxy/application_1541003514112_0003/
Kill Command = /home/hadoop-2.5/bin/hadoop job  -kill job_1541003514112_0003
Hadoop job information for Stage-1: number of mappers: 3; number of reducers: 1
2018-10-31 09:44:28,452 Stage-1 map = 0%,  reduce = 0%
2018-10-31 09:44:45,102 Stage-1 map = 11%,  reduce = 0%, Cumulative CPU 5.54 sec
2018-10-31 09:44:49,318 Stage-1 map = 33%,  reduce = 0%, Cumulative CPU 7.63 sec
2018-10-31 09:45:14,247 Stage-1 map = 44%,  reduce = 0%, Cumulative CPU 13.97 sec
2018-10-31 09:45:15,274 Stage-1 map = 67%,  reduce = 0%, Cumulative CPU 14.99 sec
2018-10-31 09:45:41,594 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 18.7 sec
2018-10-31 09:45:50,973 Stage-1 map = 100%,  reduce = 100%, Cumulative CPU 26.08 sec
MapReduce Total cumulative CPU time: 26 seconds 80 msec
Ended Job = job_1541003514112_0003
MapReduce Jobs Launched: 
Job 0: Map: 3  Reduce: 1   Cumulative CPU: 33.19 sec   HDFS Read: 593794153 HDFS Write: 7 SUCCESS
Total MapReduce CPU Time Spent: 33 seconds 190 msec
OK
399841
Time taken: 98.693 seconds, Fetched: 1 row(s)

 

========================================================

More reading,and english is important.

I'm Hongten

 

大哥哥大姐姐,覺得有用打賞點哦!你的支持是我最大的動力。謝謝。
Hongten博客排名在100名以內。粉絲過千。
Hongten出品,必是精品。

E | [email protected]  B | http://www.cnblogs.com/hongten

======================================================== 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1. 首先去官方網站下載壓縮文件:https://dev.mysql.com/downloads/mysql/ 2. 解壓下載的文件。 3. 將解壓的所有文件放在一個文件夾里(最好是C:\Program Files\MySQL\里(Mysql文件夾是自己創建的),其他位置也可以,我安裝在D盤上,下為... ...
  • 實驗機器: Kali虛擬機一臺(192.168.163.133) Windows XP虛擬機一臺(192.168.163.130) 如何用Kali虛擬機一步一步“黑掉”這個windowsXP虛擬機呢? 用到的軟體: SLmail程式(存在緩衝區溢出漏洞) ImmunityDebugger(調試工具) ...
  • linux的資料比較零散,經常是好不容易查到了,然後幾秒鐘就忘了,然後就怎麼都找不到了。看來學這個不能偷懶,必須要隨時隨地把資料給記錄下來。這就是這篇博文的意義。Xfce 一個圖形桌面環境。debian 一個linux發行版。引導提示符,按tab編輯命令行:desktop=xfceX Window ... ...
  • 下麵是我們在使用AlwaysOn過程中遇到的一個切換案例。這個案例發生在2014年8月,雖然時間相對久遠了,但是對我們學習理解AlwaysOn的FailOver原理和過程還是很有幫助的。本次FailOver的觸發原因是系統I/O問題。大家需要理解,操作系統I/O出現了問題不一定立即觸發SQL Ser ...
  • Alluxio的基本特性:透明數據緩存機制;抽象數據訪問API;和適用應用場景分析,主要包括複雜系統設計解耦和計算存儲分離應用場景的性能加速。 ...
  • Oracle條件查詢 參考網址:http://www.oraclejsq.com/article/010100259.html Oracle條件查詢時經常使用=、IN、LIKE、BETWEEN...AND來作為條件查詢的操作符。在Oracle select 查詢中where條件經常使用到這幾個操作符 ...
  • 今天小試了一把Percona Monitoring Plugins for Zabbix模板,自己辛辛苦苦寫的那一大堆Python腳本,貌似用這個模板全都覆蓋到了。 但是,我也發現最新的版本percona monitoring plugins_1.1.8也還是存在一個問題,那就是用於Mysql Re ...
  • 一. SDS概述 Redis 沒有直接使用C語言傳統的字元串表示,而是自己構建了一種名為簡單動態字元串(simple dynamic string, SDS)的抽象類型,並將SDS用作Redis的預設字元串表示。Redis只會使用C字元串作為字面量。在Redis里,使用SDS來表示字元串值,是一個可 ...
一周排行
    -Advertisement-
    Play Games
  • 前言 本文介紹一款使用 C# 與 WPF 開發的音頻播放器,其界面簡潔大方,操作體驗流暢。該播放器支持多種音頻格式(如 MP4、WMA、OGG、FLAC 等),並具備標記、實時歌詞顯示等功能。 另外,還支持換膚及多語言(中英文)切換。核心音頻處理採用 FFmpeg 組件,獲得了廣泛認可,目前 Git ...
  • OAuth2.0授權驗證-gitee授權碼模式 本文主要介紹如何筆者自己是如何使用gitee提供的OAuth2.0協議完成授權驗證並登錄到自己的系統,完整模式如圖 1、創建應用 打開gitee個人中心->第三方應用->創建應用 創建應用後在我的應用界面,查看已創建應用的Client ID和Clien ...
  • 解決了這個問題:《winForm下,fastReport.net 從.net framework 升級到.net5遇到的錯誤“Operation is not supported on this platform.”》 本文內容轉載自:https://www.fcnsoft.com/Home/Sho ...
  • 國內文章 WPF 從裸 Win 32 的 WM_Pointer 消息獲取觸摸點繪製筆跡 https://www.cnblogs.com/lindexi/p/18390983 本文將告訴大家如何在 WPF 裡面,接收裸 Win 32 的 WM_Pointer 消息,從消息裡面獲取觸摸點信息,使用觸摸點 ...
  • 前言 給大家推薦一個專為新零售快消行業打造了一套高效的進銷存管理系統。 系統不僅具備強大的庫存管理功能,還集成了高性能的輕量級 POS 解決方案,確保頁面載入速度極快,提供良好的用戶體驗。 項目介紹 Dorisoy.POS 是一款基於 .NET 7 和 Angular 4 開發的新零售快消進銷存管理 ...
  • ABP CLI常用的代碼分享 一、確保環境配置正確 安裝.NET CLI: ABP CLI是基於.NET Core或.NET 5/6/7等更高版本構建的,因此首先需要在你的開發環境中安裝.NET CLI。這可以通過訪問Microsoft官網下載並安裝相應版本的.NET SDK來實現。 安裝ABP ...
  • 問題 問題是這樣的:第三方的webapi,需要先調用登陸介面獲取Cookie,訪問其它介面時攜帶Cookie信息。 但使用HttpClient類調用登陸介面,返回的Headers中沒有找到Cookie信息。 分析 首先,使用Postman測試該登陸介面,正常返回Cookie信息,說明是HttpCli ...
  • 國內文章 關於.NET在中國為什麼工資低的分析 https://www.cnblogs.com/thinkingmore/p/18406244 .NET在中國開發者的薪資偏低,主要因市場需求、技術棧選擇和企業文化等因素所致。歷史上,.NET曾因微軟的閉源策略發展受限,儘管後來推出了跨平臺的.NET ...
  • 在WPF開發應用中,動畫不僅可以引起用戶的註意與興趣,而且還使軟體更加便於使用。前面幾篇文章講解了畫筆(Brush),形狀(Shape),幾何圖形(Geometry),變換(Transform)等相關內容,今天繼續講解動畫相關內容和知識點,僅供學習分享使用,如有不足之處,還請指正。 ...
  • 什麼是委托? 委托可以說是把一個方法代入另一個方法執行,相當於指向函數的指針;事件就相當於保存委托的數組; 1.實例化委托的方式: 方式1:通過new創建實例: public delegate void ShowDelegate(); 或者 public delegate string ShowDe ...