鲁春利的工作笔记,谁说程序员不能有文艺范?
1、安全模式
系统启动的时候会自动进入安全模式,如果DN节点正常那么经过30秒之后安全模式会自动关闭。
(1)、参数定义
dfs.replication:设置数据块应该被复制的份数;
dfs.replication.min:所规定的数据块副本的最小份数;
dfs.safemode.threshold.pct:指定应有多少比例的数据块满足最小副本数要求。
a. 当小于这个比例,那就将系统切换成安全模式,对数据块进行复制;
b. 当大于该比例时,就离开安全模式,说明系统有足够的数据块副本数,可以对外提供服务。
c. 小于等于0意味不进入安全模式,等于1意味一直处于安全模式。
(2)、dfs.replication.min存在的意义
副本数按dfs.replication设置,如果节点失效将导致数据块副本数降低,当低于dfs.replication.min后,系统再在其他节点处复制新的副本。如果该数据块的副本经常丢失,导致在太多的节点处进行了复制,那么当超过dfs.replication.max的副本数(默认为512),就不再复制了。
(3)、安全模式
NameNode在启动的时候首先进入安全模式,如果datanode丢失的block达到一定的比例(1-dfs.safemode.threshold.pct),则系统会一直处于安全模式状态即只读状态。
dfs.safemode.threshold.pct(缺省值0.999f)表示HDFS启动的时候,如果DataNode上报的block个数达到了元数据记录的block个数的0.999倍才可以离开安全模式,否则一直是这种只读模式。如果设为1则HDFS永远是处于SafeMode。
(4)、通过命令操作
[hadoop@nnode hadoop2.6.0]$ hdfs dfsadmin -help safemode -safemode <enter|leave|get|wait>: Safe mode maintenance command. Safe mode is a Namenode state in which it 1. does not accept changes to the name space (read-only) 2. does not replicate or delete blocks. Safe mode is entered automatically at Namenode startup, and leaves safe mode automatically when the configured minimum percentage of blocks satisfies the minimum replication condition. Safe mode can also be entered manually, but then it can only be turned off manually as well.
enter:进入安全模式;
leave:强制NN离开安全模式;
get:返回安全模式是否开启的信息;
wait:等待,一直到安全模式结束。
2、磁盘限额
hdfs dfsadmin [-setQuota <quota> <dirname>...<dirname>] [-clrQuota <dirname>...<dirname>] [-setSpaceQuota <quota> <dirname>...<dirname>] [-clrSpaceQuota <dirname>...<dirname>] hdfs dfs [-count [-q] [-h] <path> ...]
示例:
[hadoop@nnode hadoop2.6.0]$ hdfs dfs -ls /data Found 2 items -rw-r--r-- 2 hadoop hadoop 47 2015-06-09 17:59 /data/file1.txt -rw-r--r-- 2 hadoop hadoop 36 2015-06-09 17:59 /data/file2.txt [hadoop@nnode hadoop2.6.0]$ hdfs dfsadmin -setQuota 4 /data [hadoop@nnode hadoop2.6.0]$ hdfs dfs -count /data 1 2 83 /data # 47 + 36 = 83
查看count的帮助信息:
[hadoop@nnode hadoop2.6.0]$ hdfs dfs -help count -count [-q] [-h] <path> ... : Count the number of directories, files and bytes under the paths that match the specified file pattern. The output columns are: DIR_COUNT FILE_COUNT CONTENT_SIZE FILE_NAME or QUOTA REMAINING_QUOTA SPACE_QUOTA REMAINING_SPACE_QUOTA DIR_COUNT FILE_COUNT CONTENT_SIZE FILE_NAME The -h option shows file sizes in human readable format.
上传文件:
[hadoop@nnode hadoop2.6.0]$ hdfs dfs -put NOTICE.txt /data/ [hadoop@nnode hadoop2.6.0]$ hdfs dfs -put README.txt /data/ put: The NameSpace quota (directories and files) of directory /data is exceeded: quota=4 file count=5 [hadoop@nnode hadoop2.6.0]$ # data目录本身占一个限额 [hadoop@nnode hadoop2.6.0]$ hdfs dfs -ls /data Found 3 items -rw-r--r-- 2 hadoop hadoop 101 2015-11-28 21:02 /data/NOTICE.txt -rw-r--r-- 2 hadoop hadoop 47 2015-06-09 17:59 /data/file1.txt -rw-r--r-- 2 hadoop hadoop 36 2015-06-09 17:59 /data/file2.txt [hadoop@nnode hadoop2.6.0]$ hdfs dfs -count /data 1 3 184 /data [hadoop@nnode hadoop2.6.0]$ hdfs dfsadmin -clrQuota /data [hadoop@nnode hadoop2.6.0]$ hdfs dfs -rm /data/NOTICE.txt 15/11/28 21:21:24 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 0 minutes, Emptier interval = 0 minutes. Deleted /data/NOTICE.txt [hadoop@nnode hadoop2.6.0]$ [hadoop@nnode hadoop2.6.0]$ hdfs dfsadmin -setSpaceQuota 200 /data [hadoop@nnode hadoop2.6.0]$ hdfs dfs -ls /data Found 2 items -rw-r--r-- 2 hadoop hadoop 47 2015-06-09 17:59 /data/file1.txt -rw-r--r-- 2 hadoop hadoop 36 2015-06-09 17:59 /data/file2.txt [hadoop@nnode hadoop2.6.0]$ hdfs dfs -put README.txt /data 15/11/28 21:31:08 WARN hdfs.DFSClient: DataStreamer Exception org.apache.hadoop.hdfs.protocol.DSQuotaExceededException: The DiskSpace quota of /data is exceeded: quota = 200 B = 200 B but diskspace consumed = 268435622 B = 256.00 MB [hadoop@nnode hadoop2.6.0]$ hdfs dfsadmin -clrSpaceQuota /data
3、动态修改复制因子
hdfs dfs [-setrep [-R] [-w] <rep> <path> ...]
查看副本数,现在是2:
-rw-r--r-- 2 hadoop hadoop 47 2015-06-09 17:59 /data/file1.txt -rw-r--r-- 2 hadoop hadoop 36 2015-06-09 17:59 /data/file2.txt
设置文件file1.txt的副本数为1:
[hadoop@nnode hadoop2.6.0]$ hdfs dfs -setrep 1 /data/file1.txt Replication 1 set: /data/file1.txt [hadoop@nnode hadoop2.6.0]$ hdfs dfs -ls /data Found 2 items -rw-r--r-- 1 hadoop hadoop 47 2015-06-09 17:59 /data/file1.txt -rw-r--r-- 2 hadoop hadoop 36 2015-06-09 17:59 /data/file2.txt [hadoop@nnode hadoop2.6.0]$
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/193559.html