这篇文章将为大家详细讲解有关Hdfs中怎么配置磁盘存储策略,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
一、Hdfs磁盘存储策略
1、 指定本地目录存储策略
data目录为Hot策略对应DISK;
data1目录为Cold策略对应ARCHIVE;
<property>
<name>dfs.datanode.data.dir</name>
<value>[DISK]/opt/beh/data/namenode/dfs/data,[ARCHIVE]/opt/beh/data/namenode/dfs/data1</value>
</property>
$ stop-dfs.sh
$ start-dfs.sh
2、指定hdfs目录的存储策略
$ hdfs storagepolicies -listPolicies
Block Storage Policies:
BlockStoragePolicy{COLD:2, storageTypes=[ARCHIVE], creationFallbacks=[], replicationFallbacks=[]}
BlockStoragePolicy{WARM:5, storageTypes=[DISK, ARCHIVE], creationFallbacks=[DISK, ARCHIVE], replicationFallbacks=[DISK, ARCHIVE]}
BlockStoragePolicy{HOT:7, storageTypes=[DISK], creationFallbacks=[], replicationFallbacks=[ARCHIVE]}
BlockStoragePolicy{ONE_SSD:10, storageTypes=[SSD, DISK], creationFallbacks=[SSD, DISK], replicationFallbacks=[SSD, DISK]}
BlockStoragePolicy{ALL_SSD:12, storageTypes=[SSD], creationFallbacks=[DISK], replicationFallbacks=[DISK]}
BlockStoragePolicy{LAZY_PERSIST:15, storageTypes=[RAM_DISK, DISK], creationFallbacks=[DISK], replicationFallbacks=[DISK]}
$ hadoop fs -mkdir /Cold_data
$ hadoop fs -mkdir /Hot_data
$ hdfs storagepolicies -setStoragePolicy -path hdfs://breath:9000/Cold_data -policy COLD
Set storage policy COLD on hdfs://breath:9000/Cold_data
$ hdfs storagepolicies -setStoragePolicy -path hdfs://breath:9000/Hot_data -policy HOT
Set storage policy HOT on hdfs://breath:9000/Hot_data
$ hdfs storagepolicies -getStoragePolicy -path /Cold_data
The storage policy of /Cold_data:
BlockStoragePolicy{COLD:2, storageTypes=[ARCHIVE], creationFallbacks=[], replicationFallbacks=[]}
$ hdfs storagepolicies -getStoragePolicy -path /Hot_data
The storage policy of /Hot_data:
BlockStoragePolicy{HOT:7, storageTypes=[DISK], creationFallbacks=[], replicationFallbacks=[ARCHIVE]}
3、存储测试
$ cd /opt/beh/data/namenode/dfs
$ du -sh *
38M data
16K data1
30M name
14M namesecondary
$ dd if=/dev/zero of=test.txt bs=1000M count=1
记录了1+0 的读入
记录了1+0 的写出
1048576000字节(1.0 GB)已复制,3.11214 秒,337 MB/秒
$ hadoop fs -put test.txt /Cold_data
$ du -sh *
38M data
1008M data1
30M name
14M namesecondary
4、测试结果说明
上传的文件全部存储在了data1目录下
因为hdfs上的/Cold_data指定的是COLD 策略,与hdfs-site.xml里面ARCHIVE策略的data1目录相对应,所以文件存储达到了测试目的
二、Hdfs预留空间配置
1、参数修改
<property>
<name>dfs.datanode.du.reserved</name>
<value>32212254720</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>[ARCHIVE]/opt/beh/data/namenode/dfs/data</value>
</property>
设置dfs.datanode.du.reserved参数,32212254720表示指定预留空间为30G;
修改dfs.datanode.data.dir,只保留一个本地存储目录;
-重启hdfs
$ stop-dfs.sh
$ start-dfs.sh
2、上传文件
$ df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 46G 14G 32G 31% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.5M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/vda1 497M 125M 373M 25% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
tmpfs 1.6G 0 1.6G 0% /run/user/1000
$ hadoop fs -put test1.txt /Cold_data/test1.txt
$ hadoop fs -put test1.txt /Cold_data/test2.txt
。
。
。
$ hadoop fs -put test1.txt /Cold_data/test7.txt
$ hadoop fs -put test1.txt /Cold_data/test8.txt
16/11/12 16:30:54 INFO hdfs.DFSClient: Exception in createBlockOutputStream
java.io.EOFException: Premature EOF: no length prefix available
at org.apache.hadoop.hdfs.protocolPB.PBHelper.vintPrefixed(PBHelper.java:2239)
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.createBlockOutputStream(DFSOutputStream.java:1451)
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(DFSOutputStream.java:1373)
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:600)
16/11/12 16:30:54 INFO hdfs.DFSClient: Abandoning BP-456596110-192.168.134.129-1450512233024:blk_1073744076_3254
16/11/12 16:30:54 INFO hdfs.DFSClient: Excluding datanode DatanodeInfoWithStorage[10.10.1.31:50010,DS-01c3c362-44f4-46eb-a8d8-57d2c2d5f196,ARCHIVE]
16/11/12 16:30:54 WARN hdfs.DFSClient: DataStreamer Exception
org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /Cold_data/test8.txt._COPYING_ could only be replicated to 0 nodes instead of minReplication (=1). There are 1 datanode(s) running and 1 node(s) are excluded in this operation.
at org.apache.hadoop.hdfs.server.blockmanagement.BlockManager.chooseTarget4NewBlock(BlockManager.java:1541)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getAdditionalBlock(FSNamesystem.java:3289)
at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.addBlock(NameNodeRpcServer.java:668)
at org.apache.hadoop.hdfs.server.namenode.AuthorizationProviderProxyClientProtocol.addBlock(AuthorizationProviderProxyClientProtocol.java:212)
at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.addBlock(ClientNamenodeProtocolServerSideTranslatorPB.java:483)
at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:619)
at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:1060)
at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2044)
at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2040)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1671)
at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2038)
at org.apache.hadoop.ipc.Client.call(Client.java:1468)
at org.apache.hadoop.ipc.Client.call(Client.java:1399)
at org.apache.hadoop.ipc.ProtobufRpcEngine$Invoker.invoke(ProtobufRpcEngine.java:232)
at com.sun.proxy.$Proxy9.addBlock(Unknown Source)
at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB.addBlock(ClientNamenodeProtocolTranslatorPB.java:399)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:187)
at org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)
at com.sun.proxy.$Proxy10.addBlock(Unknown Source)
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.locateFollowingBlock(DFSOutputStream.java:1544)
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(DFSOutputStream.java:1361)
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:600)
put: File /Cold_data/test8.txt._COPYING_ could only be replicated to 0 nodes instead of minReplication (=1). There are 1 datanode(s) running and 1 node(s) are excluded in this operation.
此时数据目录/opt/beh/data/namenode/dfs的空间大小如下
$ cd /opt/beh/data/namenode/dfs
$ du -sh *
15G data
12K data1
34M name
19M namesecondary
$ df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 46G 27G 19G 59% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.5M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/vda1 497M 125M 373M 25% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
tmpfs 1.6G 0 1.6G 0% /run/user/1000
3、总结
出现报错说明磁盘预留空间配置生效,但是查看磁盘空间可以看到,本地目录剩余可用空间并不是Hdfs设置的预留空间;
Hdfs对一个数据目录的可用存储认定是当前目录所在磁盘的总空间(此处为/目录46G),并不是当前目录的可用空间。
当前目录(磁盘)的总空间46G - Hdfs已使用的总空间15G=31G
而此时预留空间为30G,因此hdfs剩余的可用空间为1G,所以当再次上传一个大小为2G的文件时,出现以上的报错。
因为此处测试直接使用了/目录的存储,其它非Hdfs占用了部分空间,当hdfs的数据目录对单块磁盘一一对应,每块磁盘的剩余可用空间大小与预留空间配置的值相当时,就不会再往该磁盘写入数据。
关于Hdfs中怎么配置磁盘存储策略就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。