在centos7中部署hadoop2.8分布式集群并安裝hbase

本文詳細(xì)記錄了centos7中安裝hadoop2.8分布式集群,之后在hadoop中部署hbase做个,并簡(jiǎn)單演示了使用萤衰。

安裝環(huán)境如下:

  • CPU:六核心
  • 內(nèi)存:8GB
  • 操作系統(tǒng)版本centos7.6
  • hadoop-2.8.5蔗牡、hbase-1.4.9
  • jdk1.8.0_171
  • 服務(wù)器名稱分別是myserver01蓝谨、myserver02、myserver03

Hadoop分布式安裝

軟件準(zhǔn)備

新建/u01/soft和/u01/app兩個(gè)目錄,下載的軟件放在/u01/soft 割捅,解壓后的文件在/u01/app中

[root@myserver01 /]#mkdir -p /u01/soft  
[root@myserver01 /]#mkdir -p /u01/app  
[root@myserver01 /]cd /u01  
[root@myserver01 u01]# ls
app    soft  
[root@myserver01 u01]#cd soft
[root@myserver01 soft]# wget https://www.apache.org/dyn/closer.cgi/hadoop/common/hadoop-2.8.5/hadoop-2.8.5.tar.gz
[root@myserver01 soft]#cd /u01/app
[root@myserver01 app]#tar -xzvf /u01/soft/hadoop-2.8.5.tar.gz
[root@myserver01 app]# ls
hadoop-2.8.5    jdk1.8.0_171 

操作系統(tǒng)配置

  1. 配置hosts
[root@myserver01 app]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.16.9.32 myserver02
192.16.9.30 myserver01
192.16.9.33 myserver03
  1. hadoop用戶配置
    三個(gè)節(jié)點(diǎn)添加hadoop用戶,這里這是的密碼是hadoop
[root@myserver01 ~]# adduser hadoop
[root@myserver01 app]# passwd hadoop
更改hadoop解壓文件的所屬者
[root@myserver01 app]# chown -R hadoop:hadoop /u01/app/hadoop-2.8.5
[root@myserver02 ~]# adduser hadoop
[root@myserver02 ~]# passwd hadoop
[root@myserver03 ~]# adduser hadoop
[root@myserver03 ~]# passwd hadoop

在myserver01上配置不需要密碼就可以訪問其他兩臺(tái)機(jī)器

[root@myserver01 app]#su - hadoop
[hadoop@myserver01 hadoop]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hadoop/.ssh/id_rsa): 
Created directory '/home/hadoop/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/hadoop/.ssh/id_rsa.
Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:FZK+l6YeAaIUzeKuhletlT38UTlThUzMdtteHHkngAs hadoop@myserver01
The key's randomart image is:
+---[RSA 2048]----+
|  .o    .....*.oo|
|  ..o   E...  Oo+|
| .... .. ... + +*|
| ... . .... =  .+|
| ..  . +S. o o ..|
|  . . + =.=     .|
|.. . o  .* .     |
|o.. .   ...      |
|..     ..        |
+----[SHA256]-----+

[hadoop@myserver01 ~]$ ssh-copy-id myserver02
[hadoop@myserver01 ~]$ ssh-copy-id myserver03
[hadoop@myserver01 ~]$ ssh-copy-id myserver01
[hadoop@myserver01 ~]$ ssh myserver01 date
Tue Feb 19 03:33:40 EST 2019
[hadoop@myserver01 ~]$ ssh myserver02 date
Tue Feb 19 03:33:43 EST 2019
[hadoop@myserver01 ~]$ ssh myserver03 date
Tue Feb 19 03:33:46 EST 2019

三個(gè)節(jié)點(diǎn)都要配置hadoop用戶JAVA_HOME

[hadoop@myserver01 hadoop]$ cat /home/hadoop/.bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
# User specific environment and startup programs
JAVA_HOME=/u01/app/jdk1.8.0_171
export JAVA_HOME
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$JAVA_HOME/bin
export PATH

配置hadoop

  1. 配置hadoop-env.sh
    主要是添加JAVA_HOME
[hadoop@myserver01 hadoop]$cd /u01/app/hadoop-2.8.5/etc/hadoop
[hadoop@myserver01 hadoop]$ pwd
/u01/app/hadoop-2.8.5/etc/hadoop
[hadoop@myserver01 hadoop]$ vi hadoop-env.sh
# The java implementation to use.
export JAVA_HOME=/u01/app/jdk1.8.0_171
  1. 修改core-site.xml
    先在每個(gè)節(jié)點(diǎn)創(chuàng)建/apps/hdptmp目錄
[root@myserver01 app]# mkdir -p /apps/hdptmp
[root@myserver01 app]# chown -R hadoop:hadoop /apps/hdptmp

然后編輯core-site.xml文件

[hadoop@myserver01 hadoop]$ vi core-site.xml 
<configuration>
<property>
        <name>hadoop.tmp.dir</name>
        <value>/apps/hdptmp</value><!-- 請(qǐng)先在 /apps 目錄下建立 hdptmp 文件夾-->
</property><!-- file system properties -->
<property>
        <name>fs.defaultFS</name>
        <value>hdfs://myserver01:9500</value>
</property>
</configuration>
  1. 修改mapred-site.xml
[hadoop@myserver01 hadoop]$ vi mapred-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
    </property>
</configuration>
  1. 配置yarn-site.xml
[hadoop@myserver01 hadoop]$ vi yarn-site.xml 
<?xml version="1.0"?>
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.resouremanager.hostname</name>
<value>myserver01</value>
</property>
   <!--mapreduce執(zhí)行shuffle(洗牌的意思)獲取數(shù)據(jù)的方式-->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
  1. 添加slaves文件
[hadoop@myserver01 hadoop]$ vi slaves
myserver01
myserver02
myserver03
  1. 將修改好的hadoop目錄拷貝到其余兩個(gè)節(jié)點(diǎn)
將hadoop拷貝到其余兩個(gè)節(jié)點(diǎn)
[root@myserver01 app]#scp -r hadoop-2.8.5 root@myserver02:/u01/app/
[root@myserver01 app]#scp -r hadoop-2.8.5 root@myserver03:/u01/app/
分別進(jìn)入myserver02和myserver03將hadoop-2.8.5所屬者改為hadoop
  1. 格式化HDFS
[hadoop@myserver01 ~]$ /u01/app/hadoop-2.8.5/bin/hadoop namenode -format
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.

19/02/19 03:42:21 INFO namenode.NameNode: STARTUP_MSG: 
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG:   user = hadoop
STARTUP_MSG:   host = myserver01/172.16.9.30
STARTUP_MSG:   args = [-format]
STARTUP_MSG:   version = 2.8.5
  1. 啟動(dòng)hadoop
    啟動(dòng)hdfs
此時(shí)如果提示要輸入某個(gè)節(jié)點(diǎn)的密碼表明節(jié)點(diǎn)信任沒配置好泽谨。
[hadoop@myserver01 ~]$ /u01/app/hadoop-2.8.5/sbin/start-dfs.sh 

此時(shí)在myserver01用jps可以看到相關(guān)進(jìn)程

jps查看進(jìn)程狀態(tài)
[hadoop@myserver01 ~]$ jps
6160 Jps
5608 DataNode
5775 SecondaryNameNode

啟動(dòng)yarn

/u01/app/hadoop-2.8.5/sbin/start-yarn.sh 
[hadoop@myserver01 ~]$ jps
6823 Jps
5608 DataNode
6316 ResourceManager
5775 SecondaryNameNode
6623 NodeManager

當(dāng)然也可以使用使用命令一次性開啟或者關(guān)閉所有進(jìn)程

[hadoop@myserver01 ~]$ /u01/app/hadoop-2.8.5/sbin/stop-all.sh 
This script is Deprecated. Instead use stop-dfs.sh and stop-yarn.sh
Stopping namenodes on [myserver01]
myserver01: stopping namenode
myserver02: stopping datanode
myserver03: stopping datanode
myserver01: stopping datanode
Stopping secondary namenodes [0.0.0.0]
0.0.0.0: stopping secondarynamenode
stopping yarn daemons
stopping resourcemanager
myserver02: no nodemanager to stop
myserver03: no nodemanager to stop
myserver01: stopping nodemanager
myserver01: nodemanager did not stop gracefully after 5 seconds: killing with kill -9
no proxyserver to stop
[hadoop@myserver01 ~]$ /u01/app/hadoop-2.8.5/sbin/start-all.sh 
This script is Deprecated. Instead use start-dfs.sh and start-yarn.sh
Starting namenodes on [myserver01]
myserver01: starting namenode, logging to /u01/app/hadoop-2.8.5/logs/hadoop-hadoop-namenode-myserver01.out
myserver03: starting datanode, logging to /u01/app/hadoop-2.8.5/logs/hadoop-hadoop-datanode-myserver03.out
myserver01: starting datanode, logging to /u01/app/hadoop-2.8.5/logs/hadoop-hadoop-datanode-myserver01.out
myserver02: starting datanode, logging to /u01/app/hadoop-2.8.5/logs/hadoop-hadoop-datanode-myserver02.out
Starting secondary namenodes [0.0.0.0]
0.0.0.0: starting secondarynamenode, logging to /u01/app/hadoop-2.8.5/logs/hadoop-hadoop-secondarynamenode-myserver01.out
starting yarn daemons
starting resourcemanager, logging to /u01/app/hadoop-2.8.5/logs/yarn-hadoop-resourcemanager-myserver01.out
myserver02: starting nodemanager, logging to /u01/app/hadoop-2.8.5/logs/yarn-hadoop-nodemanager-myserver02.out
myserver03: starting nodemanager, logging to /u01/app/hadoop-2.8.5/logs/yarn-hadoop-nodemanager-myserver03.out
myserver01: starting nodemanager, logging to /u01/app/hadoop-2.8.5/logs/yarn-hadoop-nodemanager-myserver01.out

檢查hadoop

上面已經(jīng)演示過使用jps查看hadoop進(jìn)程璧榄,hadoop啟動(dòng)后也有相應(yīng)的web頁(yè)面可以查看hadoop信息
訪問datanode
http://192.16.9.30:50070/dfshealth.html#tab-overview
截圖
訪問namenode
http://192.16.9.30:50075/
截圖

HDFS基本使用

將本地文件拷貝的hdfs

[hadoop@myserver01 ~]$ cd /u01/app/hadoop-2.8.5/
[hadoop@myserver01 hadoop-2.8.5]$ /u01/app/hadoop-2.8.5/bin/hdfs dfs -copyFromLocal LICENSE.txt /
[hadoop@myserver01 hadoop-2.8.5]$ /u01/app/hadoop-2.8.5/bin/hdfs dfs -copyFromLocal README.txt /
[hadoop@myserver01 hadoop-2.8.5]$ /u01/app/hadoop-2.8.5/bin/hdfs dfs -ls /
Found 3 items
-rw-r--r--   3 hadoop supergroup      99253 2019-02-20 04:46 /LICENSE.txt
-rw-r--r--   3 hadoop supergroup       1366 2019-02-20 04:47 /README.txt

查看hdfs文件內(nèi)容

[hadoop@myserver01 hadoop-2.8.5]$ /u01/app/hadoop-2.8.5/bin/hdfs dfs -cat /LICENSE.txt

hdfs創(chuàng)建目錄

[hadoop@myserver01 hadoop-2.8.5]$ /u01/app/hadoop-2.8.5/bin/hdfs dfs -mkdir /gjwtttt

hdfs刪除文件

[hadoop@myserver01 hadoop-2.8.5]$ /u01/app/hadoop-2.8.5/bin/hdfs dfs -rm /LICENSE.txt
Deleted /LICENSE.txt

大體來說跟在Linux中操作文件系統(tǒng)類似

安裝HBASE

準(zhǔn)備軟件

[root@myserver01 /]# cd /u01/soft
下載軟件
[root@myserver01 soft]# wget http://mirror.bit.edu.cn/apache/hbase/1.4.9/hbase-1.4.9-bin.tar.gz
解壓軟件
[root@myserver01 soft]# cd /u01/app
[root@myserver01 app]# tar -xzvf /u01/soft/hbase-1.4.9-bin.tar.gz
改變文件所屬
[root@myserver01 app]#chown -R hadoop:hadoop hbase-1.4.9
將hbase拷貝到其余兩個(gè)節(jié)點(diǎn)
[root@myserver01 app]#scp -r hbase-1.4.9 root@myserver02:/u01/app/
[root@myserver01 app]#scp -r hbase-1.4.9 root@myserver03:/u01/app/
分別進(jìn)入myserver02和myserver03將hbase-1.4.9所屬者改為hadoop

配置hbase

三個(gè)節(jié)點(diǎn)的hbase都要做配置特漩,也可以在配置完成后拷貝hbase

  1. 三個(gè)節(jié)點(diǎn)修改hbase-env.sh
[root@myserver01 app]su - hadoop
[hadoop@myserver03 ~]$ cd /u01/app/hbase-1.4.9/
[hadoop@myserver03 hbase-1.4.9]$ vi conf/hbase-env.sh
export JAVA_HOME=/u01/app/jdk1.8.0_171
  1. 三個(gè)節(jié)點(diǎn)修改hbase-site.xml
[hadoop@myserver01 conf]$ vi hbase-site.xml 
<configuration>
  <property>
    <name>hbase.rootdir</name>
    <value>hdfs://myserver01:9500/hbase</value>
  </property>
  <property>
    <name>hbase.cluster.distributed</name>
    <value>true</value>
  </property>
  <property>
    <name>hbase.zookeeper.quorum</name>
    <value>myserver01,myserver02,myserver03</value>
  </property>
</configuration>
  1. 啟動(dòng)hbase
[hadoop@myserver01 hbase-1.4.9]$ bin/start-hbase.sh 
[hadoop@myserver01 hbase-1.4.9]$ jps
11424 ResourceManager
11537 NodeManager
11250 SecondaryNameNode
12274 HQuorumPeer
12418 HRegionServer
12339 HMaster
11077 DataNode
10969 NameNode
12718 Jps
此時(shí)可以看到hbase進(jìn)程了

也可以在hdfs中查看是否有hbase目錄

[hadoop@myserver01 hadoop-2.8.5]$ ./bin/hdfs dfs  -ls /
Found 3 items
-rw-r--r--   3 hadoop supergroup       1366 2019-02-20 04:47 /README.txt
drwxr-xr-x   - hadoop supergroup          0 2019-02-20 04:49 /gjwtttt
drwxr-xr-x   - hadoop supergroup          0 2019-02-19 05:00 /hbase

hbase基本使用

這里用hbase shell簡(jiǎn)單演示下hbase如何使用
這里簡(jiǎn)單創(chuàng)建一個(gè)表演示下

[hadoop@myserver01 hbase-1.4.9]$ ./bin/hbase shell
2019-02-19 04:59:48,625 WARN  [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
Version 1.4.9, rd625b212e46d01cb17db9ac2e9e927fdb201afa1, Wed Dec  5 11:54:10 PST 2018

hbase(main):001:0> 
hbase(main):001:0> create 'test','cf'
0 row(s) in 2.1080 seconds

=> Hbase::Table - test
hbase(main):002:0> list
TABLE                                                                                                                      
test                                                                                                                       
1 row(s) in 0.0460 seconds

=> ["test"]
hbase(main):003:0> desc test
ArgumentError: wrong number of arguments (0 for 2)

hbase(main):004:0> desc 'test'
Table test is ENABLED                                                                                                      
test                                                                                                                       
COLUMN FAMILIES DESCRIPTION                                                                                                
{NAME => 'cf', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCOD
ING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', RE
PLICATION_SCOPE => '0'}                                                                                                    
1 row(s) in 0.0830 seconds

hbase(main):005:0>  put 'test','row1','cf:name','wangziqiang'
0 row(s) in 0.2470 seconds

hbase(main):006:0> scan 'test'
ROW                             COLUMN+CELL                                                                                
 row1                           column=cf:name, timestamp=1550570481753, value=wangziqiang                                 
1 row(s) in 0.1400 seconds
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市犹菱,隨后出現(xiàn)的幾起案子拾稳,更是在濱河造成了極大的恐慌,老刑警劉巖腊脱,帶你破解...
    沈念sama閱讀 206,968評(píng)論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件访得,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡陕凹,警方通過查閱死者的電腦和手機(jī)悍抑,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,601評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來杜耙,“玉大人搜骡,你說我怎么就攤上這事∮优” “怎么了记靡?”我有些...
    開封第一講書人閱讀 153,220評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)团驱。 經(jīng)常有香客問我摸吠,道長(zhǎng),這世上最難降的妖魔是什么嚎花? 我笑而不...
    開封第一講書人閱讀 55,416評(píng)論 1 279
  • 正文 為了忘掉前任寸痢,我火速辦了婚禮,結(jié)果婚禮上紊选,老公的妹妹穿的比我還像新娘啼止。我一直安慰自己,他們只是感情好兵罢,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,425評(píng)論 5 374
  • 文/花漫 我一把揭開白布献烦。 她就那樣靜靜地躺著,像睡著了一般卖词。 火紅的嫁衣襯著肌膚如雪仿荆。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,144評(píng)論 1 285
  • 那天坏平,我揣著相機(jī)與錄音,去河邊找鬼锦亦。 笑死舶替,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的杠园。 我是一名探鬼主播顾瞪,決...
    沈念sama閱讀 38,432評(píng)論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了陈醒?” 一聲冷哼從身側(cè)響起惕橙,我...
    開封第一講書人閱讀 37,088評(píng)論 0 261
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎钉跷,沒想到半個(gè)月后弥鹦,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 43,586評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡爷辙,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,028評(píng)論 2 325
  • 正文 我和宋清朗相戀三年彬坏,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片膝晾。...
    茶點(diǎn)故事閱讀 38,137評(píng)論 1 334
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡栓始,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出血当,到底是詐尸還是另有隱情幻赚,我是刑警寧澤,帶...
    沈念sama閱讀 33,783評(píng)論 4 324
  • 正文 年R本政府宣布臊旭,位于F島的核電站落恼,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏巍扛。R本人自食惡果不足惜领跛,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,343評(píng)論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望撤奸。 院中可真熱鬧吠昭,春花似錦、人聲如沸胧瓜。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,333評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)府喳。三九已至蒲肋,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間钝满,已是汗流浹背兜粘。 一陣腳步聲響...
    開封第一講書人閱讀 31,559評(píng)論 1 262
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留弯蚜,地道東北人孔轴。 一個(gè)月前我還...
    沈念sama閱讀 45,595評(píng)論 2 355
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像碎捺,于是被迫代替她去往敵國(guó)和親路鹰。 傳聞我的和親對(duì)象是個(gè)殘疾皇子贷洲,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,901評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容