和單機環境相比,叢集環境有一些不同,這裡以兩個節點為例

master:10.1.108.64

slave1:10.1.108.63

namenode:master

datanode:master,slave1

resourcenode:master

1./etc/hosts如下

[[email protected] hadoop-2.8.0]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.1.108.64 master
10.1.108.63 slave1

2.hdfs-site.xml中replication,單節點的時候是1,這裡要改成2

<property>
    <name>dfs.replication</name>
    <value>2</value>
</property>

3.修改etc/hadoop/slaves,如下:

[[email protected] hadoop-2.8.0]# cat etc/hadoop/slaves 
master
slave1

4.修改etc/hadoop/allnodes,如下:

[[email protected] hadoop-2.8.0]# cat etc/hadoop/allnodes 
master

5.將master的所有配置檔案複製到slave1,注意slave1的檔案路徑必須和master一樣

6.在slave1上,修改hdfs-site-xml,如下,並建立對應目錄,後續增加其他slave,也不能使用之前別人用的目錄,需要新增

<property>
    <name>dfs.datanode.data.dir</name>
    <value>file:/root/hadoop/hdfs/data/slave1</value>
</property>

7.設定master可以免密登陸slave1,如下

scp /root/.ssh/authorized_keys [email protected]:/root/.ssh

8.slave1上也需要執行格式化命令,效果和master一樣,如下

./bin/hdfs namenode -format

9.在master上,先停止服務,再啟動服務,命令如下:

./sbin/stop-all.sh
./sbin/start-all.sh

10.在master上檢視節點,如下:

[[email protected] hadoop-2.8.0]# jps
9506 NodeManager
9045 DataNode
9237 SecondaryNameNode
9401 ResourceManager
8939 NameNode
9871 Jps
[[email protected] hadoop-2.8.0]# 

在slave1上檢視節點,如下:

[[email protected] hdfs]# jps
2529 NodeManager
2683 Jps
2415 DataNode
[[email protected] hdfs]# 

11.在網頁端檢視節點,如下,顯示為主和備:

12.在50070下檢視datanode,如下:

.