虛擬機器搭建hadoop2.7.4
阿新 • • 發佈:2018-12-30
CentOS7.0安裝配置hadoop2.7.4
資源準備
資源下載:
注意事項:
- 注意hadoop,jdk,centos都應該是64位或者32位的,以免出現無法預料的錯誤建議使用64位的
linux 虛擬機器配置
系統配置:
- 虛擬機器:一個master(Master.Hadoop),兩個slave(Slave1.Hadoop, Slave2.Hadoop)
- 網路設定:我NAT的方式
- 記憶體:每個虛擬機器配置1024M記憶體
- 分割槽:自動
- 軟體選擇:最小安裝,注意選擇開發工具
- 進行以下步驟前,確保3臺虛擬機器與主機之間可以相互ping通
yum search ifconfg
yum install net-tools.x86_64
- 1
- 2
- 1
- 2
完成其它兩個虛擬機器的安裝:
- 兩個slave的hostname可以改成Slave1.Hadoop, Slave2.Hadoop,方便區分
安裝完後各個虛擬機器的ip配置(參考用)
主機 | ip地址 |
---|---|
master.hadoop | 192.168.202.128 |
slave1.hadoop | 192.168.202.129 |
slave2.hadoop | 192.168.202.130 |
配置本地hosts
、、需把下圖紅框內容刪除,否則啟動有問題。
- 輸入指令
vi /etc/hosts
// 將以下資料複製進入各個主機中
192.168.202.128 master.hadoop
192.168.202.129 slave1.hadoop
192.168.202.130 slave2.hadoop
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 使用以下指令對master主機中進行測試,可使用類似指令在slave主機測試
ping slave1.hadoop
ping slave2.hadoop
- 1
- 2
- 3
- 1
- 2
- 3
配置Master無密碼登入所有Salve
以下在Master主機上配置
- 輸入以下指令生成ssh,過程中遇到需要輸入密碼,只需執行回車Enter即可
ssh-keygen
// 會生成兩個檔案,放到預設的/root/.ssh/資料夾中
- 1
- 2
- 3
- 1
- 2
- 3
- 把id_rsa.pub追加到授權的key裡面去
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
- 1
- 1
- 修改檔案”authorized_keys”許可權
chmod 600 ~/.ssh/authorized_keys
- 1
- 1
- 設定SSH配置
vi /etc/ssh/sshd_config
// 以下三項修改成以下配置
RSAAuthentication yes # 啟用 RSA 認證
PubkeyAuthentication yes # 啟用公鑰私鑰配對認證方式
AuthorizedKeysFile .ssh/authorized_keys # 公鑰檔案路徑(和上面生成的檔案同)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 重啟ssh服務
service sshd restart
- 1
- 1
- 把公鑰複製所有的Slave機器上
// scp ~/.ssh/id_rsa.pub 遠端使用者名稱@遠端伺服器IP:~/
scp ~/.ssh/id_rsa.pub root@192.168.202.129:~/
scp ~/.ssh/id_rsa.pub root@192.168.202.130:~/
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
以下在Slave主機上配置
- 在slave主機上建立.ssh資料夾
mkdir ~/.ssh
// 修改許可權
chmod 700 ~/.ssh
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
- 追加到授權檔案”authorized_keys”
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
// 修改許可權
chmod 600 ~/.ssh/authorized_keys
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
- 刪除無用.pub檔案
rm –r ~/id_rsa.pub
- 1
- 1
在master主機下進行測試
ssh 192.168.202.129
ssh 192.168.202.130
// 如果能夠分別無密碼登陸slave1, slave2主機,則成功配置
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
進行jdk, hadoop軟體安裝
jdk安裝:
- 在/usr下建立java資料夾
- 使用第三方軟體將jdk壓縮包檔案傳到3臺虛擬主機中
- 使用以下指令進行加壓
tar zxvf jdk-8u45-linux-x64.tar.gz
// 解壓後可以刪除掉gz檔案
rm jdk-8u45-linux-x64.tar.gz
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
- 配置jdk環境變數
vi /etc/profile
- 1
- 2
- 1
- 2
- 新增Java環境變數
// 將以下資料複製到檔案底部
export JAVA_HOME=/usr/java/jdk1.8.0_45
export JRE_HOME=/usr/java/jdk1.8.0_45/jre
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 使配置生效
source /etc/profile
- 1
- 1
- 驗證安裝成功
java -version
// 如果出現以下資訊,則配置成功
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
- 把下載的hadoop壓縮檔案傳到/usr目錄下
- 解壓hadoop-2.7.4.tar.gz檔案,並重命名
cd /usr
tar zxvf hadoop-2.7.4.tar.gz
mv hadoop-2.7.4 hadoop
// 刪除hadoop-2.7.4.tar.gz檔案
rm –rf hadoop-2.7.4.tar.gz
- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
- 在”/usr/hadoop”下面建立tmp資料夾
cd /usr/hadoop
mkdir tmp
- 1
- 2
- 1
- 2
- 把Hadoop的安裝路徑新增到”/etc/profile”中
vi /etc/profile
// 將以下資料加入到檔案末尾
export HADOOP_INSTALL=/usr/hadoop
export PATH=${HADOOP_INSTALL}/bin:${HADOOP_INSTALL}/sbin:${PATH}
export HADOOP_MAPRED_HOME=${HADOOP_INSTALL}
export HADOOP_COMMON_HOME=${HADOOP_INSTALL}
export HADOOP_HDFS_HOME=${HADOOP_INSTALL}
export YARN_HOME=${HADOOP_INSTALLL}
export HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_INSTALL}/lib/natvie
export HADOOP_OPTS="-Djava.library.path=${HADOOP_INSTALL}/lib:${HADOOP_INSTALL}/lib/native"
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 重啟”/etc/profile”
source /etc/profile
- 1
- 1
配置hadoop(先只在Master主機配置,配置完後傳入兩個Slave主機)
- 設定hadoop-env.sh和yarn-env.sh中的java環境變數
cd /usr/hadoop/etc/hadoop/
vi hadoop-env.sh
// 修改JAVA_HOME
export JAVA_HOME=/usr/java/jdk1.8.0_45
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
- 配置core-site.xml檔案
vi core-site.xml
// 修改檔案內容為以下
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/hadoop/tmp</value>
<description>A base for other temporary directories.</description>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://master.hadoop:9000</value>
</property>
</configuration>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 配置hdfs-site.xml檔案
vi hdfs-site.xml
// 修改檔案內容為以下
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:///usr/hadoop/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:///usr/hadoop/dfs/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.nameservices</name>
<value>hadoop-cluster1</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>master.hadoop:50090</value>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
</configuration>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 配置mapred-site.xml檔案,如沒有此檔案需要手動建立,檔案頭尾加上configuration標籤,把下面內容複製到中間即可
vi mapred-site.xml
// 修改檔案為以下
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
<final>true</final>
</property>
<property>
<name>mapreduce.jobtracker.http.address</name>
<value>master.hadoop:50030</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>master.hadoop:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>master.hadoop:19888</value>
</property>
<property>
<name>mapred.job.tracker</name>
<value>http://master.hadoop:9001</value>
</property>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 配置yarn-site.xml檔案
vi yarn-site.xml
// 修改檔案內容為以下
<property>
<name>yarn.resourcemanager.hostname</name>
<value>master.hadoop</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>master.hadoop:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>master.hadoop:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>master.hadoop:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>master.hadoop:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>master.hadoop:8088</value>
</property>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
配置Hadoop的叢集
- 將Master中配置好的hadoop傳入兩個Slave中
scp -r /usr/hadoop root@192.168.202.129:/usr/
scp -r /usr/hadoop root@192.168.202.130:/usr/
- 1
- 2
- 1
- 2
- 修改Master主機上的slaves檔案
cd /usr/hadoop/etc/hadoop
vi slaves
// 將檔案內容修改為
slave1.hadoop
slave2.hadoop
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 格式化HDFS檔案系統
- 注意:只需初始化一次便可。若執行多次,可能會導致namenode與datanode的clusterID不一致,從而導致無法啟動
// 在Master主機上輸入以下指令
hadoop namenode -format
- 1
- 2
- 1
- 2
- 啟動hadoop
// 關閉機器防火牆 根據自己的版本不同,命令有所不同
CentOS 7
關閉firewall:
systemctl stop/start firewalld.service 停止/啟動firewall
systemctl disable firewalld.service 禁止firewall開機啟動
firewall-cmd --state 檢視預設防火牆狀態
cd /usr/hadoop/sbin
./start-all.sh
// 更推薦的執行方式:
cd /usr/hadoop/sbin
./start-dfs.sh
./start-yarn.sh
應該輸出以下資訊:
Starting namenodes on [Master.Hadoop]
Master.Hadoop: starting namenode, logging to /usr/hadoop/logs/hadoop-root-namenode-localhost.localdomain.out
Slave2.Hadoop: starting datanode, logging to /usr/hadoop/logs/hadoop-root-datanode-Slave2.Hadoop.out
Slave1.Hadoop: starting datanode, logging to /usr/hadoop/logs/hadoop-root-datanode-Slave1.Hadoop.out
starting yarn daemons
starting resourcemanager, logging to /usr/hadoop/logs/yarn-root-resourcemanager-localhost.localdomain.out
Slave1.Hadoop: starting nodemanager, logging to /usr/hadoop/logs/yarn-root-nodemanager-Slave1.Hadoop.out
Slave2.Hadoop: starting nodemanager, logging to /usr/hadoop/logs/yarn-root-nodemanager-Slave2.Hadoop.out
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 驗證hadoop
// 1. 直接在Master或Slave輸入指令:
jps
// 應該輸出以下資訊(埠號僅供參考)
Master:
3930 ResourceManager
4506 Jps
3693 NameNode
Slave:
2792 NodeManager
2920 Jps
2701 DataNode
// 2. 輸入以下指令
hadoop dfsadmin -report
// 應該輸出以下資訊:
Configured Capacity: 14382268416 (13.39 GB)
Present Capacity: 10538565632 (9.81 GB)
DFS Remaining: 10538557440 (9.81 GB)
DFS Used: 8192 (8 KB)
DFS Used%: 0.00%
Under replicated blocks: 0
Blocks with corrupt replicas: 0
Missing blocks: 0
Missing blocks (with replication factor 1): 0
-------------------------------------------------
Live datanodes (2):
Name: 192.168.1.124:50010 (Slave2.Hadoop)
Hostname: Slave2.Hadoop
Decommission Status : Normal
Configured Capacity: 7191134208 (6.70 GB)
DFS Used: 4096 (4 KB)
Non DFS Used: 1921933312 (1.79 GB)
DFS Remaining: 5269196800 (4.91 GB)
DFS Used%: 0.00%
DFS Remaining%: 73.27%
Configured Cache Capacity: 0 (0 B)
Cache Used: 0 (0 B)
Cache Remaining: 0 (0 B)
Cache Used%: 100.00%
Cache Remaining%: 0.00%
Xceivers: 1
Last contact: Thu Jul 02 10:45:04 CST 2015
Name: 192.168.1.125:50010 (Slave1.Hadoop)
Hostname: Slave1.Hadoop
Decommission Status : Normal
Configured Capacity: 7191134208 (6.70 GB)
DFS Used: 4096 (4 KB)
Non DFS Used: 1921769472 (1.79 GB)
DFS Remaining: 5269360640 (4.91 GB)
DFS Used%: 0.00%
DFS Remaining%: 73.28%
Configured Cache Capacity: 0 (0 B)
Cache Used: 0 (0 B)
Cache Remaining: 0 (0 B)
Cache Used%: 100.00%
Cache Remaining%: 0.00%
Xceivers: 1
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 訪問網頁
// CentOS7中iptables這個服務的配置檔案沒有了,採用了新的firewalld
// 輸入以下指令後,可以在真機瀏覽器上訪問hadoop網頁
systemctl stop firewalld
// 輸入以下網頁,進入hadoop管理首頁(IP地址為master 主機IP)
http://192.168.202.128:50070/dfshealth.html#tab-overview
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 1
- 2
- 3
- 4
- 5
- 6
- 7