a.通过查看hdfs-site.xml 文件
点击(此处)折叠或打开
-
[root@sht-sgmhadoopnn-01 ~]# cd /hadoop/hadoop-2.7.2/etc/hadoop
-
[root@sht-sgmhadoopnn-01 hadoop]# more hdfs-site.xml
-
<property>
-
<name>dfs.replication</name>
-
<value>3</value>
- </property>
点击(此处)折叠或打开
-
[root@sht-sgmhadoopnn-01 hadoop]# hdfs dfs -ls /testdir
-
Found 7 items
-
-rw-r--r-- 3 root supergroup 37322672 2016-03-05 17:59 /testdir/012_HDFS.avi
-
-rw-r--r-- 3 root supergroup 224001146 2016-03-05 18:01 /testdir/016_Hadoop.avi
-
-rw-r--r-- 3 root supergroup 176633760 2016-03-05 19:11 /testdir/022.avi
-
-rw-r--r-- 3 root supergroup 30 2016-02-28 22:42 /testdir/1.log
-
-rw-r--r-- 3 root supergroup 196 2016-02-28 22:23 /testdir/full_backup.log
-
-rw-r--r-- 3 root supergroup 142039186 2016-03-05 17:55 /testdir/oracle-j2sdk1.7-1.7.0+update67-1.x86_64.rpm
-
-rw-r--r-- 3 root supergroup 44 2016-02-28 19:40 /testdir/test.log
- [root@sht-sgmhadoopnn-01 hadoop]#
- ### 紧跟-rw-r--r--权限后面的3,表示该文件在hdfs有多少份备份
而Default replication factor则需要重启整个Hadoop集群才能修改(就是hdfs-site.xml 文件中改为4,然后集群重启才生效,不过这种情况不适用生产集群),
但实际影响系统的还是Average block replication的值,因此并非一定要修改默认值Default replication factor。
点击(此处)折叠或打开
-
[root@sht-sgmhadoopnn-01 hadoop]# hdfs fsck /
-
16/03/06 17:15:27 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
-
Connecting to namenode via http://sht-sgmhadoopnn-01:50070/fsck?ugi=root&path=%2F
-
FSCK started by root (auth:SIMPLE) from /172.16.101.55 for path / at Sun Mar 06 17:15:29 CST 2016
-
............Status: HEALTHY
-
Total size: 580151839 B
-
Total dirs: 15
-
Total files: 12
-
Total symlinks: 0
-
Total blocks (validated): 11 (avg. block size 52741076 B)
-
Minimally replicated blocks: 11 (100.0 %)
-
Over-replicated blocks: 0 (0.0 %)
-
Under-replicated blocks: 0 (0.0 %)
-
Mis-replicated blocks: 0 (0.0 %)
-
Default replication factor: 3
-
Average block replication: 3.0
-
Corrupt blocks: 0
-
Missing replicas: 0 (0.0 %)
-
Number of data-nodes: 4
-
Number of racks: 1
-
FSCK ended at Sun Mar 06 17:15:29 CST 2016 in 9 milliseconds
-
The filesystem under path '/' is HEALTHY
- You have mail in /var/spool/mail/root
点击(此处)折叠或打开
-
[root@sht-sgmhadoopnn-01 hadoop]# hdfs dfs -help
-
-setrep [-R] [-w] ... :
-
Set the replication level of a file. If is a directory then the command
-
recursively changes the replication factor of all files under the directory tree
-
rooted at .
-
-
-w It requests that the command waits for the replication to complete. This
-
can potentially take a very long time.
-
-R It is accepted for backwards compatibility. It has no effect.
-
-
-
[root@sht-sgmhadoopnn-01 hadoop]# hdfs dfs -setrep -w 4 -R /
-
setrep: `-R': No such file or directory
-
Replication 4 set: /out1/_SUCCESS
-
Replication 4 set: /out1/part-r-00000
-
Replication 4 set: /testdir/012_HDFS.avi
-
Replication 4 set: /testdir/016_Hadoop.avi
-
Replication 4 set: /testdir/022.avi
-
Replication 4 set: /testdir/1.log
-
Replication 4 set: /testdir/full_backup.log
-
Replication 4 set: /testdir/oracle-j2sdk1.7-1.7.0+update67-1.x86_64.rpm
-
Replication 4 set: /testdir/test.log
-
Replication 4 set: /tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1456590271264_0002-1456659654297-root-word+count-1456659679606-1-1-SUCCEEDED-root.root-1456659662730.jhist
-
Replication 4 set: /tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1456590271264_0002.summary
-
Replication 4 set: /tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1456590271264_0002_conf.xml
-
Waiting for /out1/_SUCCESS ... done
-
Waiting for /out1/part-r-00000 .... done
-
Waiting for /testdir/012_HDFS.avi ... done
-
Waiting for /testdir/016_Hadoop.avi ... done
-
Waiting for /testdir/022.avi ... done
-
Waiting for /testdir/1.log ... done
-
Waiting for /testdir/full_backup.log ... done
-
Waiting for /testdir/oracle-j2sdk1.7-1.7.0+update67-1.x86_64.rpm ... done
-
Waiting for /testdir/test.log ... done
-
Waiting for /tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1456590271264_0002-1456659654297-root-word+count-1456659679606-1-1-SUCCEEDED-root.root-1456659662730.jhist ... done
-
Waiting for /tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1456590271264_0002.summary ... done
-
Waiting for /tmp/hadoop-yarn/staging/history/done_intermediate/root/job_1456590271264_0002_conf.xml ... done
-
[root@sht-sgmhadoopnn-01 hadoop]#
-
-
##再次检查备份系统的情况, Average block replication为4
-
[root@sht-sgmhadoopnn-01 hadoop]# hdfs fsck /
-
16/03/06 17:25:49 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
-
Connecting to namenode via http://sht-sgmhadoopnn-01:50070/fsck?ugi=root&path=%2F
-
FSCK started by root (auth:SIMPLE) from /172.16.101.55 for path / at Sun Mar 06 17:25:51 CST 2016
-
............Status: HEALTHY
-
Total size: 580151839 B
-
Total dirs: 15
-
Total files: 12
-
Total symlinks: 0
-
Total blocks (validated): 11 (avg. block size 52741076 B)
-
Minimally replicated blocks: 11 (100.0 %)
-
Over-replicated blocks: 0 (0.0 %)
-
Under-replicated blocks: 0 (0.0 %)
-
Mis-replicated blocks: 0 (0.0 %)
-
Default replication factor: 3
-
Average block replication: 4.0
-
Corrupt blocks: 0
-
Missing replicas: 0 (0.0 %)
-
Number of data-nodes: 4
-
Number of racks: 1
-
FSCK ended at Sun Mar 06 17:25:51 CST 2016 in 6 milliseconds
- The filesystem under path '/
点击(此处)折叠或打开
-
[root@sht-sgmhadoopnn-01 hadoop]# vi /tmp/wjp.log
-
hello,i am
-
hadoop
-
hdfs
-
mapreduce
-
yarn
-
hive
-
zookeeper
-
-
[root@sht-sgmhadoopnn-01 hadoop]# hdfs dfs -put /tmp/wjp.log /testdir
-
-
[root@sht-sgmhadoopnn-01 hadoop]# hdfs dfs -ls /testdir
-
Found 8 items
-
-rw-r--r-- 4 root supergroup 37322672 2016-03-05 17:59 /testdir/012_HDFS.avi
-
-rw-r--r-- 4 root supergroup 224001146 2016-03-05 18:01 /testdir/016_Hadoop.avi
-
-rw-r--r-- 4 root supergroup 176633760 2016-03-05 19:11 /testdir/022.avi
-
-rw-r--r-- 4 root supergroup 30 2016-02-28 22:42 /testdir/1.log
-
-rw-r--r-- 4 root supergroup 196 2016-02-28 22:23 /testdir/full_backup.log
-
-rw-r--r-- 4 root supergroup 142039186 2016-03-05 17:55 /testdir/oracle-j2sdk1.7-1.7.0+update67-1.x86_64.rpm
-
-rw-r--r-- 4 root supergroup 44 2016-02-28 19:40 /testdir/test.log
-
-rw-r--r-- 3 root supergroup 62 2016-03-06 17:30 /testdir/wjp.log
-
[root@sht-sgmhadoopnn-01 hadoop]# hdfs dfs -rm /testdir/wjp.log
-
16/03/06 17:31:47 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 1440 minutes, Emptier interval = 0 minutes.
-
Moved: 'hdfs://mycluster/testdir/wjp.log' to trash at: hdfs://mycluster/user/root/.Trash/Current
-
[root@sht-sgmhadoopnn-01 hadoop]#
- ### put的测试文件wjp.log的备份数还是3,于是我先把测试文件删除掉,去修改namenode节点的hdfs-site.xml的参数
点击(此处)折叠或打开
-
[root@sht-sgmhadoopnn-01 hadoop]# vi hdfs-site.xml
-
<property>
-
<name>dfs.replication</name>
-
<value>4</value>
-
</property>
- [root@sht-sgmhadoopnn-01 hadoop]# scp hdfs-site.xml root@sht-sgmhadoopnn-02:/hadoop/hadoop-2.7.2/etc/hadoop
- ###假如集群中,配置了namenode HA,那么应该需要对另外一个standbyNamenode节点的文件要同步一直,无需也同步到datanode节点
##先不重启试试看
点击(此处)折叠或打开
-
[root@sht-sgmhadoopnn-01 hadoop]# hdfs dfs -put /tmp/wjp.log /testdir
-
16/03/06 17:36:34 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
-
You have mail in /var/spool/mail/root
-
[root@sht-sgmhadoopnn-01 hadoop]# hdfs dfs -ls /testdir
-
16/03/06 17:36:46 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
-
Found 8 items
-
-rw-r--r-- 4 root supergroup 37322672 2016-03-05 17:59 /testdir/012_HDFS.avi
-
-rw-r--r-- 4 root supergroup 224001146 2016-03-05 18:01 /testdir/016_Hadoop.avi
-
-rw-r--r-- 4 root supergroup 176633760 2016-03-05 19:11 /testdir/022.avi
-
-rw-r--r-- 4 root supergroup 30 2016-02-28 22:42 /testdir/1.log
-
-rw-r--r-- 4 root supergroup 196 2016-02-28 22:23 /testdir/full_backup.log
-
-rw-r--r-- 4 root supergroup 142039186 2016-03-05 17:55 /testdir/oracle-j2sdk1.7-1.7.0+update67-1.x86_64.rpm
-
-rw-r--r-- 4 root supergroup 44 2016-02-28 19:40 /testdir/test.log
-
-rw-r--r-- 4 root supergroup 62 2016-03-06 17:36 /testdir/wjp.log
-
-
[root@sht-sgmhadoopnn-01 hadoop]# hdfs fsck /
-
16/03/06 21:49:10 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
-
Connecting to namenode via http://sht-sgmhadoopnn-01:50070/fsck?ugi=root&path=%2F
-
FSCK started by root (auth:SIMPLE) from /172.16.101.55 for path / at Sun Mar 06 21:49:12 CST 2016
-
...............Status: HEALTHY
-
Total size: 580152025 B
-
Total dirs: 17
-
Total files: 15
-
Total symlinks: 0
-
Total blocks (validated): 14 (avg. block size 41439430 B)
-
Minimally replicated blocks: 14 (100.0 %)
-
Over-replicated blocks: 0 (0.0 %)
-
Under-replicated blocks: 0 (0.0 %)
-
Mis-replicated blocks: 0 (0.0 %)
-
Default replication factor: 3
-
Average block replication: 4.0
-
Corrupt blocks: 0
-
Missing replicas: 0 (0.0 %)
-
Number of data-nodes: 4
-
Number of racks: 1
- FSCK ended at Sun Mar 06 21:49:12 CST 2016 in 8 milliseconds
而不是从配置文件hdfs-site.xml文件中读取配置的,从而验证了上面这句话:
实际影响系统的还是Average block replication的值,因此并非一定要修改默认值Default replication factor。
总结命令:
hdfs fsck /
hdfs dfs -setrep -w 4 -R /