Hadoop学习之路(十)HDFS API的使用
HDFS API的高级编程
HDFS的API就两个:FileSystem 和Configuration
1、文件的上传和下载
- package com.ghgj.hdfs.api;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.FileSystem;
- import org.apache.hadoop.fs.Path;
- public class HDFS_GET_AND_PUT {
- public static void main(String[] args) throws Exception {
- Configuration conf = new Configuration();
- conf.set("fs.defaultFS", "hdfs://hadoop1:9000");
- conf.set("dfs.replication", "2");
- FileSystem fs = FileSystem.get(conf);
- /**
- * 更改操作用户有两种方式:
- *
- * 1、直接设置运行换种的用户名为hadoop
- *
- * VM arguments ; -DHADOOP_USER_NAME=hadoop
- *
- * 2、在代码中进行声明
- *
- * System.setProperty("HADOOP_USER_NAME", "hadoop");
- */
- System.setProperty("HADOOP_USER_NAME", "hadoop");
- // 上传
- fs.copyFromLocalFile(new Path("c:/sss.txt"), new Path("/a/ggg.txt"));
- /**
- * .crc : 校验文件
- *
- * 每个块的元数据信息都只会记录合法数据的起始偏移量: qqq.txt blk_41838 : 0 - 1100byte
- *
- * 如果进行非法的数据追加。最终是能够下载合法数据。
- * 由于你在数据的中间, 也就是说在 0 -1100 之间的范围进行了数据信息的更改。 造成了采用CRC算法计算出来校验值,和最初存入进HDFS的校验值
- * 不一致。HDFS就认为当前这个文件被损坏了。
- */
- // 下载
- fs.copyToLocalFile(new Path("/a/qqq.txt"), new Path("c:/qqq3.txt"));
- /**
- * 上传和下载的API的底层封装其实就是 : FileUtil.copy(....)
- */
- fs.close();
- }
- }
2、配置文件conf
- package com.exam.hdfs;
- import java.io.IOException;
- import java.util.Iterator;
- import java.util.Map.Entry;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.FileSystem;
- public class TestConf1 {
- public static void main(String[] args) throws Exception {
- /**
- * 底层会加载一堆的配置文件:
- *
- * core-default.xml
- * hdfs-default.xml
- * mapred-default.xml
- * yarn-default.xml
- */
- Configuration conf = new Configuration();
- // conf.addResource("hdfs-default.xml");
- /**
- * 当前这个hdfs-site.xml文件就放置在这个项目中的src下。也就是classpath路径下。
- * 所以 FS在初始化的时候,会把hdfs-site.xml这个文件中的name-value对解析到conf中
- *
- *
- * 但是:
- *
- * 1、如果hdfs-site.xml 不在src下, 看是否能加载??? 不能
- *
- * 2、如果文件名不叫做 hdfs-default.xml 或者 hdsf-site.xml 看是否能自动加载??? 不能
- *
- * 得出的结论:
- *
- * 如果需要项目代码自动加载配置文件中的信息,那么就必须把配置文件改成-default.xml或者-site.xml的名称
- * 而且必须放置在src下
- *
- * 那如果不叫这个名,或者不在src下,也需要加载这些配置文件中的参数:
- *
- * 必须使用conf对象提供的一些方法去手动加载
- */
- // conf.addResource("hdfs-site.xml");
- conf.set("dfs.replication", "1");
- conf.addResource("myconfig/hdfs-site.xml");
- /**
- * 依次加载的参数信息的顺序是:
- *
- * 1、加载 core/hdfs/mapred/yarn-default.xml
- *
- * 2、加载通过conf.addResources()加载的配置文件
- *
- * 3、加载conf.set(name, value)
- */
- FileSystem fs = FileSystem.get(conf);
- System.out.println(conf.get("dfs.replication"));
- Iterator<Entry<String, String>> iterator = conf.iterator();
- while(iterator.hasNext()){
- Entry<String, String> e = iterator.next();
- System.out.println(e.getKey() + "\t" + e.getValue());
- }
- }
- }
输出结果
- log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
- log4j:WARN Please initialize the log4j system properly.
- log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
- 1
- hadoop.security.groups.cache.secs 300
- dfs.datanode.cache.revocation.timeout.ms 900000
- dfs.namenode.resource.check.interval 5000
- s3.client-write-packet-size 65536
- dfs.client.https.need-auth false
- dfs.replication 1
- hadoop.security.group.mapping.ldap.directory.search.timeout 10000
- dfs.datanode.available-space-volume-choosing-policy.balanced-space-threshold 10737418240
- hadoop.work.around.non.threadsafe.getpwuid false
- dfs.namenode.write-lock-reporting-threshold-ms 5000
- fs.ftp.host.port 21
- dfs.namenode.avoid.read.stale.datanode false
- dfs.journalnode.rpc-address 0.0.0.0:8485
- hadoop.security.kms.client.encrypted.key.cache.expiry 43200000
- ipc.client.connection.maxidletime 10000
- hadoop.registry.zk.session.timeout.ms 60000
- tfile.io.chunk.size 1048576
- fs.automatic.close true
- ha.health-monitor.sleep-after-disconnect.ms 1000
- io.map.index.interval 128
- dfs.namenode.https-address 0.0.0.0:50470
- dfs.mover.max-no-move-interval 60000
- io.seqfile.sorter.recordlimit 1000000
- fs.s3n.multipart.uploads.enabled false
- hadoop.util.hash.type murmur
- dfs.namenode.replication.min 1
- dfs.datanode.directoryscan.threads 1
- dfs.namenode.fs-limits.min-block-size 1048576
- dfs.datanode.directoryscan.interval 21600
- fs.AbstractFileSystem.file.impl org.apache.hadoop.fs.local.LocalFs
- dfs.namenode.acls.enabled false
- dfs.client.short.circuit.replica.stale.threshold.ms 1800000
- net.topology.script.number.args 100
- hadoop.http.authentication.token.validity 36000
- fs.s3.block.size 67108864
- dfs.namenode.resource.du.reserved 104857600
- ha.failover-controller.graceful-fence.rpc-timeout.ms 5000
- s3native.bytes-per-checksum 512
- dfs.namenode.datanode.registration.ip-hostname-check true
- dfs.namenode.path.based.cache.block.map.allocation.percent 0.25
- dfs.namenode.backup.http-address 0.0.0.0:50105
- hadoop.security.group.mapping org.apache.hadoop.security.JniBasedUnixGroupsMappingWithFallback
- dfs.namenode.edits.noeditlogchannelflush false
- dfs.datanode.cache.revocation.polling.ms 500
- dfs.namenode.audit.loggers default
- hadoop.security.groups.cache.warn.after.ms 5000
- io.serializations org.apache.hadoop.io.serializer.WritableSerialization,org.apache.hadoop.io.serializer.avro.AvroSpecificSerialization,org.apache.hadoop.io.serializer.avro.AvroReflectSerialization
- dfs.namenode.lazypersist.file.scrub.interval.sec 300
- fs.s3a.threads.core 15
- hadoop.security.crypto.buffer.size 8192
- hadoop.http.cross-origin.allowed-methods GET,POST,HEAD
- hadoop.registry.zk.retry.interval.ms 1000
- dfs.http.policy HTTP_ONLY
- hadoop.registry.secure false
- dfs.namenode.replication.interval 3
- dfs.namenode.safemode.min.datanodes 0
- dfs.client.file-block-storage-locations.num-threads 10
- nfs.dump.dir /tmp/.hdfs-nfs
- dfs.namenode.secondary.https-address 0.0.0.0:50091
- hadoop.kerberos.kinit.command kinit
- dfs.block.access.token.lifetime 600
- dfs.webhdfs.enabled true
- dfs.client.use.datanode.hostname false
- dfs.namenode.delegation.token.max-lifetime 604800000
- fs.trash.interval 0
- dfs.datanode.drop.cache.behind.writes false
- dfs.namenode.avoid.write.stale.datanode false
- dfs.namenode.num.extra.edits.retained 1000000
- s3.blocksize 67108864
- ipc.client.connect.max.retries.on.timeouts 45
- dfs.datanode.data.dir /home/hadoop/data/hadoopdata/data
- fs.s3.buffer.dir ${hadoop.tmp.dir}/s3
- fs.s3n.block.size 67108864
- nfs.exports.allowed.hosts * rw
- ha.health-monitor.connect-retry-interval.ms 1000
- hadoop.security.instrumentation.requires.admin false
- hadoop.registry.zk.retry.ceiling.ms 60000
- nfs.rtmax 1048576
- dfs.client.mmap.cache.size 256
- dfs.datanode.data.dir.perm 700
- io.file.buffer.size 4096
- dfs.namenode.backup.address 0.0.0.0:50100
- dfs.client.datanode-restart.timeout 30
- dfs.datanode.readahead.bytes 4194304
- dfs.namenode.xattrs.enabled true
- io.mapfile.bloom.size 1048576
- ipc.client.connect.retry.interval 1000
- dfs.client-write-packet-size 65536
- dfs.namenode.checkpoint.txns 1000000
- dfs.datanode.bp-ready.timeout 20
- dfs.datanode.transfer.socket.send.buffer.size 131072
- hadoop.security.kms.client.authentication.retry-count 1
- dfs.client.block.write.retries 3
- fs.swift.impl org.apache.hadoop.fs.swift.snative.SwiftNativeFileSystem
- ha.failover-controller.graceful-fence.connection.retries 1
- hadoop.registry.zk.connection.timeout.ms 15000
- dfs.namenode.safemode.threshold-pct 0.999f
- dfs.cachereport.intervalMsec 10000
- hadoop.security.java.secure.random.algorithm SHA1PRNG
- ftp.blocksize 67108864
- dfs.namenode.list.cache.directives.num.responses 100
- dfs.namenode.kerberos.principal.pattern *
- file.stream-buffer-size 4096
- dfs.datanode.dns.nameserver default
- fs.s3a.max.total.tasks 1000
- dfs.namenode.replication.considerLoad true
- nfs.allow.insecure.ports true
- dfs.namenode.edits.journal-plugin.qjournal org.apache.hadoop.hdfs.qjournal.client.QuorumJournalManager
- dfs.client.write.exclude.nodes.cache.expiry.interval.millis 600000
- dfs.client.mmap.cache.timeout.ms 3600000
- ipc.client.idlethreshold 4000
- io.skip.checksum.errors false
- ftp.stream-buffer-size 4096
- fs.s3a.fast.upload false
- dfs.client.failover.connection.retries.on.timeouts 0
- file.blocksize 67108864
- ftp.replication 3
- dfs.namenode.replication.work.multiplier.per.iteration 2
- hadoop.security.authorization false
- hadoop.http.authentication.simple.anonymous.allowed true
- s3native.client-write-packet-size 65536
- hadoop.rpc.socket.factory.class.default org.apache.hadoop.net.StandardSocketFactory
- file.bytes-per-checksum 512
- dfs.datanode.slow.io.warning.threshold.ms 300
- fs.har.impl.disable.cache true
- rpc.engine.org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolPB org.apache.hadoop.ipc.ProtobufRpcEngine
- io.seqfile.lazydecompress true
- dfs.namenode.reject-unresolved-dn-topology-mapping false
- hadoop.common.configuration.version 0.23.0
- hadoop.security.authentication simple
- dfs.datanode.drop.cache.behind.reads false
- dfs.image.compression.codec org.apache.hadoop.io.compress.DefaultCodec
- dfs.client.read.shortcircuit.streams.cache.size 256
- file.replication 1
- dfs.namenode.top.num.users 10
- dfs.namenode.accesstime.precision 3600000
- dfs.namenode.fs-limits.max-xattrs-per-inode 32
- dfs.image.transfer.timeout 60000
- io.mapfile.bloom.error.rate 0.005
- nfs.wtmax 1048576
- hadoop.security.kms.client.encrypted.key.cache.size 500
- dfs.namenode.edit.log.autoroll.check.interval.ms 300000
- fs.s3a.multipart.purge false
- dfs.namenode.support.allow.format true
- hadoop.hdfs.configuration.version 1
- fs.s3a.connection.establish.timeout 5000
- hadoop.security.group.mapping.ldap.search.attr.member member
- dfs.secondary.namenode.kerberos.internal.spnego.principal ${dfs.web.authentication.kerberos.principal}
- dfs.stream-buffer-size 4096
- hadoop.ssl.client.conf ssl-client.xml
- dfs.namenode.invalidate.work.pct.per.iteration 0.32f
- fs.s3a.multipart.purge.age 86400
- dfs.journalnode.https-address 0.0.0.0:8481
- dfs.namenode.top.enabled true
- hadoop.security.kms.client.encrypted.key.cache.low-watermark 0.3f
- dfs.namenode.max.objects 0
- hadoop.user.group.static.mapping.overrides dr.who=;
- fs.s3a.fast.buffer.size 1048576
- dfs.bytes-per-checksum 512
- dfs.datanode.max.transfer.threads 4096
- dfs.block.access.key.update.interval 600
- ipc.maximum.data.length 67108864
- tfile.fs.input.buffer.size 262144
- ha.failover-controller.new-active.rpc-timeout.ms 60000
- dfs.client.cached.conn.retry 3
- dfs.client.read.shortcircuit false
- hadoop.ssl.hostname.verifier DEFAULT
- dfs.datanode.hdfs-blocks-metadata.enabled false
- dfs.datanode.directoryscan.throttle.limit.ms.per.sec 0
- dfs.image.transfer.chunksize 65536
- hadoop.http.authentication.type simple
- dfs.namenode.list.encryption.zones.num.responses 100
- dfs.client.https.keystore.resource ssl-client.xml
- s3native.blocksize 67108864
- net.topology.impl org.apache.hadoop.net.NetworkTopology
- dfs.client.failover.sleep.base.millis 500
- io.seqfile.compress.blocksize 1000000
- dfs.namenode.path.based.cache.refresh.interval.ms 30000
- dfs.namenode.decommission.interval 30
- dfs.permissions.superusergroup supergroup
- dfs.namenode.fs-limits.max-directory-items 1048576
- hadoop.registry.zk.retry.times 5
- dfs.ha.log-roll.period 120
- fs.AbstractFileSystem.ftp.impl org.apache.hadoop.fs.ftp.FtpFs
- ftp.bytes-per-checksum 512
- dfs.user.home.dir.prefix /user
- dfs.namenode.checkpoint.edits.dir ${dfs.namenode.checkpoint.dir}
- dfs.client.socket.send.buffer.size 131072
- ipc.client.fallback-to-simple-auth-allowed false
- dfs.blockreport.initialDelay 0
- dfs.namenode.inotify.max.events.per.rpc 1000
- dfs.namenode.heartbeat.recheck-interval 300000
- dfs.namenode.safemode.extension 30000
- dfs.client.failover.sleep.max.millis 15000
- dfs.namenode.delegation.key.update-interval 86400000
- dfs.datanode.transfer.socket.recv.buffer.size 131072
- hadoop.rpc.protection authentication
- fs.permissions.umask-mode 022
- fs.s3.sleepTimeSeconds 10
- dfs.namenode.fs-limits.max-xattr-size 16384
- ha.health-monitor.rpc-timeout.ms 45000
- hadoop.http.staticuser.user dr.who
- dfs.datanode.http.address 0.0.0.0:50075
- fs.s3a.connection.maximum 15
- fs.s3a.paging.maximum 5000
- fs.AbstractFileSystem.viewfs.impl org.apache.hadoop.fs.viewfs.ViewFs
- dfs.namenode.blocks.per.postponedblocks.rescan 10000
- fs.ftp.host 0.0.0.0
- dfs.lock.suppress.warning.interval 10s
- hadoop.http.authentication.kerberos.keytab ${user.home}/hadoop.keytab
- fs.s3a.impl org.apache.hadoop.fs.s3a.S3AFileSystem
- hadoop.registry.zk.root /registry
- hadoop.jetty.logs.serve.aliases true
- dfs.namenode.fs-limits.max-blocks-per-file 1048576
- dfs.balancer.keytab.enabled false
- dfs.client.block.write.replace-datanode-on-failure.enable true
- hadoop.http.cross-origin.max-age 1800
- io.compression.codec.bzip2.library system-native
- dfs.namenode.checkpoint.dir file://${hadoop.tmp.dir}/dfs/namesecondary
- dfs.client.use.legacy.blockreader.local false
- dfs.namenode.top.windows.minutes 1,5,25
- ipc.ping.interval 60000
- net.topology.node.switch.mapping.impl org.apache.hadoop.net.ScriptBasedMapping
- nfs.mountd.port 4242
- dfs.storage.policy.enabled true
- dfs.namenode.list.cache.pools.num.responses 100
- fs.df.interval 60000
- nfs.server.port 2049
- ha.zookeeper.parent-znode /hadoop-ha
- hadoop.http.cross-origin.allowed-headers X-Requested-With,Content-Type,Accept,Origin
- dfs.datanode.block-pinning.enabled false
- dfs.namenode.num.checkpoints.retained 2
- fs.s3a.attempts.maximum 10
- s3native.stream-buffer-size 4096
- io.seqfile.local.dir ${hadoop.tmp.dir}/io/local
- fs.s3n.multipart.copy.block.size 5368709120
- dfs.encrypt.data.transfer.cipher.key.bitlength 128
- dfs.client.mmap.retry.timeout.ms 300000
- dfs.datanode.sync.behind.writes false
- dfs.namenode.fslock.fair true
- hadoop.ssl.keystores.factory.class org.apache.hadoop.security.ssl.FileBasedKeyStoresFactory
- dfs.permissions.enabled true
- fs.AbstractFileSystem.hdfs.impl org.apache.hadoop.fs.Hdfs
- dfs.blockreport.split.threshold 1000000
- dfs.datanode.balance.bandwidthPerSec 1048576
- dfs.block.scanner.volume.bytes.per.second 1048576
- hadoop.security.random.device.file.path /dev/urandom
- fs.s3.maxRetries 4
- hadoop.http.filter.initializers org.apache.hadoop.http.lib.StaticUserWebFilter
- dfs.namenode.stale.datanode.interval 30000
- ipc.client.rpc-timeout.ms 0
- fs.client.resolve.remote.symlinks true
- dfs.default.chunk.view.size 32768
- hadoop.ssl.enabled.protocols TLSv1
- dfs.namenode.decommission.blocks.per.interval 500000
- dfs.namenode.handler.count 10
- dfs.image.transfer.bandwidthPerSec 0
- rpc.metrics.quantile.enable false
- hadoop.ssl.enabled false
- dfs.replication.max 512
- dfs.namenode.name.dir /home/hadoop/data/hadoopdata/name
- dfs.namenode.read-lock-reporting-threshold-ms 5000
- dfs.datanode.https.address 0.0.0.0:50475
- dfs.datanode.failed.volumes.tolerated 0
- ipc.client.kill.max 10
- fs.s3a.threads.max 256
- ipc.server.listen.queue.size 128
- dfs.client.domain.socket.data.traffic false
- dfs.block.access.token.enable false
- dfs.blocksize 134217728
- fs.s3a.connection.timeout 50000
- fs.s3a.threads.keepalivetime 60
- file.client-write-packet-size 65536
- dfs.datanode.address 0.0.0.0:50010
- ha.failover-controller.cli-check.rpc-timeout.ms 20000
- ha.zookeeper.acl world:anyone:rwcda
- ipc.client.connect.max.retries 10
- dfs.encrypt.data.transfer false
- dfs.namenode.write.stale.datanode.ratio 0.5f
- ipc.client.ping true
- dfs.datanode.shared.file.descriptor.paths /dev/shm,/tmp
- dfs.short.circuit.shared.memory.watcher.interrupt.check.ms 60000
- hadoop.tmp.dir /home/hadoop/data/hadoopdata
- dfs.datanode.handler.count 10
- dfs.client.failover.max.attempts 15
- dfs.balancer.max-no-move-interval 60000
- dfs.client.read.shortcircuit.streams.cache.expiry.ms 300000
- dfs.namenode.block-placement-policy.default.prefer-local-node true
- hadoop.ssl.require.client.cert false
- hadoop.security.uid.cache.secs 14400
- dfs.client.read.shortcircuit.skip.checksum false
- dfs.namenode.resource.checked.volumes.minimum 1
- hadoop.registry.rm.enabled false
- dfs.namenode.quota.init-threads 4
- dfs.namenode.max.extra.edits.segments.retained 10000
- dfs.webhdfs.user.provider.user.pattern ^[A-Za-z_][A-Za-z0-9._-]*[$]?$
- dfs.client.mmap.enabled true
- dfs.client.file-block-storage-locations.timeout.millis 1000
- dfs.datanode.block.id.layout.upgrade.threads 12
- dfs.datanode.use.datanode.hostname false
- hadoop.fuse.timer.period 5
- dfs.client.context default
- fs.trash.checkpoint.interval 0
- dfs.journalnode.http-address 0.0.0.0:8480
- dfs.balancer.address 0.0.0.0:0
- dfs.namenode.lock.detailed-metrics.enabled false
- dfs.namenode.delegation.token.renew-interval 86400000
- ha.health-monitor.check-interval.ms 1000
- dfs.namenode.retrycache.heap.percent 0.03f
- ipc.client.connect.timeout 20000
- dfs.reformat.disabled false
- dfs.blockreport.intervalMsec 21600000
- fs.s3a.multipart.threshold 2147483647
- dfs.https.server.keystore.resource ssl-server.xml
- hadoop.http.cross-origin.enabled false
- io.map.index.skip 0
- dfs.balancer.block-move.timeout 0
- io.native.lib.available true
- s3.replication 3
- dfs.namenode.kerberos.internal.spnego.principal ${dfs.web.authentication.kerberos.principal}
- fs.AbstractFileSystem.har.impl org.apache.hadoop.fs.HarFs
- hadoop.security.kms.client.encrypted.key.cache.num.refill.threads 2
- fs.s3n.multipart.uploads.block.size 67108864
- dfs.image.compress false
- dfs.datanode.dns.interface default
- dfs.datanode.available-space-volume-choosing-policy.balanced-space-preference-fraction 0.75f
- tfile.fs.output.buffer.size 262144
- fs.du.interval 600000
- dfs.client.failover.connection.retries 0
- dfs.namenode.edit.log.autoroll.multiplier.threshold 2.0
- hadoop.security.group.mapping.ldap.ssl false
- dfs.namenode.top.window.num.buckets 10
- fs.s3a.buffer.dir ${hadoop.tmp.dir}/s3a
- dfs.namenode.checkpoint.check.period 60
- fs.defaultFS hdfs://hadoop1:9000
- fs.s3a.multipart.size 104857600
- dfs.client.slow.io.warning.threshold.ms 30000
- dfs.datanode.max.locked.memory 0
- dfs.namenode.retrycache.expirytime.millis 600000
- hadoop.security.group.mapping.ldap.search.attr.group.name cn
- dfs.client.block.write.replace-datanode-on-failure.best-effort false
- dfs.ha.fencing.ssh.connect-timeout 30000
- dfs.datanode.scan.period.hours 504
- hadoop.registry.zk.quorum localhost:2181
- dfs.namenode.fs-limits.max-component-length 255
- hadoop.http.cross-origin.allowed-origins *
- dfs.namenode.enable.retrycache true
- dfs.datanode.du.reserved 0
- dfs.datanode.ipc.address 0.0.0.0:50020
- hadoop.registry.system.acls sasl:yarn@, sasl:mapred@, sasl:hdfs@
- dfs.namenode.path.based.cache.retry.interval.ms 30000
- hadoop.security.crypto.cipher.suite AES/CTR/NoPadding
- dfs.client.block.write.replace-datanode-on-failure.policy DEFAULT
- dfs.namenode.http-address 0.0.0.0:50070
- hadoop.security.crypto.codec.classes.aes.ctr.nopadding org.apache.hadoop.crypto.OpensslAesCtrCryptoCodec,org.apache.hadoop.crypto.JceAesCtrCryptoCodec
- dfs.ha.tail-edits.period 60
- hadoop.security.groups.negative-cache.secs 30
- hadoop.ssl.server.conf ssl-server.xml
- hadoop.registry.jaas.context Client
- s3native.replication 3
- hadoop.security.group.mapping.ldap.search.filter.group (objectClass=group)
- hadoop.http.authentication.kerberos.principal HTTP/_HOST@LOCALHOST
- dfs.namenode.startup.delay.block.deletion.sec 0
- hadoop.security.group.mapping.ldap.search.filter.user (&(objectClass=user)(sAMAccountName={0}))
- dfs.namenode.edits.dir ${dfs.namenode.name.dir}
- dfs.namenode.checkpoint.max-retries 3
- s3.stream-buffer-size 4096
- ftp.client-write-packet-size 65536
- dfs.datanode.fsdatasetcache.max.threads.per.volume 4
- hadoop.security.sensitive-config-keys password$,fs.s3.*[Ss]ecret.?[Kk]ey,fs.azure.account.key.*,dfs.webhdfs.oauth2.[a-z]+.token,hadoop.security.sensitive-config-keys
- dfs.namenode.decommission.max.concurrent.tracked.nodes 100
- dfs.namenode.name.dir.restore false
- ipc.server.log.slow.rpc false
- dfs.heartbeat.interval 3
- dfs.namenode.secondary.http-address hadoop3:50090
- ha.zookeeper.session-timeout.ms 5000
- s3.bytes-per-checksum 512
- fs.s3a.connection.ssl.enabled true
- hadoop.http.authentication.signature.secret.file ${user.home}/hadoop-http-auth-signature-secret
- hadoop.fuse.connection.timeout 300
- dfs.namenode.checkpoint.period 3600
- ipc.server.max.connections 0
- dfs.ha.automatic-failover.enabled false
3、列出指定目录下的文件以及块的信息
- package com.exam.hdfs;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.BlockLocation;
- import org.apache.hadoop.fs.FileSystem;
- import org.apache.hadoop.fs.LocatedFileStatus;
- import org.apache.hadoop.fs.Path;
- import org.apache.hadoop.fs.RemoteIterator;
- public class TestHDFS1 {
- public static void main(String[] args) throws Exception {
- Configuration conf = new Configuration();
- System.setProperty("HADOOP_USER_NAME", "hadoop");
- conf.set("fs.defaultFS", "hdfs://hadoop1:9000");
- FileSystem fs = FileSystem.get(conf);
- /**
- * 列出指定的目录下的所有文件
- */
- RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(new Path("/"), true);
- while(listFiles.hasNext()){
- LocatedFileStatus file = listFiles.next();
- System.out.println(file.getPath()+"\t");
- System.out.println(file.getPath().getName()+"\t");
- System.out.println(file.getLen()+"\t");
- System.out.println(file.getReplication()+"\t");
- /**
- * blockLocations的长度是几? 是什么意义?
- *
- * 块的数量
- */
- BlockLocation[] blockLocations = file.getBlockLocations();
- System.out.println(blockLocations.length+"\t");
- for(BlockLocation bl : blockLocations){
- String[] hosts = bl.getHosts();
- System.out.print(hosts[0] + "-" + hosts[1]+"\t");
- }
- System.out.println();
- }
- }
- }
输出结果
- hdfs://hadoop1:9000/aa/bb/cc/hadoop.tar.gz
- hadoop.tar.gz
- 199007110
- 2
- 3
- hadoop3-hadoop1 hadoop1-hadoop2 hadoop1-hadoop4
4、上传文件
- package com.exam.hdfs;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.InputStream;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.FSDataOutputStream;
- import org.apache.hadoop.fs.FileSystem;
- import org.apache.hadoop.fs.Path;
- import org.apache.hadoop.io.IOUtils;
- public class UploadDataByStream {
- public static void main(String[] args) throws Exception {
- Configuration conf = new Configuration();
- System.setProperty("HADOOP_USER_NAME", "hadoop");
- conf.set("fs.defaultFS", "hdfs://hadoop1:9000");
- FileSystem fs = FileSystem.get(conf);
- InputStream in = new FileInputStream(new File("d:/abc.tar.gz"));
- FSDataOutputStream out = fs.create(new Path("/aa/abc.tar.gz"));
- IOUtils.copyBytes(in, out, 4096, true);
- fs.close();
- }
- }
5、下载文件
- package com.exam.hdfs;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.OutputStream;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.FSDataInputStream;
- import org.apache.hadoop.fs.FileSystem;
- import org.apache.hadoop.fs.Path;
- import org.apache.hadoop.io.IOUtils;
- public class DownloadDataByStream {
- public static void main(String[] args) throws Exception {
- Configuration conf = new Configuration();
- System.setProperty("HADOOP_USER_NAME", "hadoop");
- conf.set("fs.defaultFS", "hdfs://hadoop1:9000");
- FileSystem fs = FileSystem.get(conf);
- FSDataInputStream in = fs.open(new Path("/aa/abc.tar.gz"));
- OutputStream out = new FileOutputStream(new File("D:/abc.sh"));
- IOUtils.copyBytes(in, out, 4096, true);
- fs.close();
- }
- }
6、删除某个路径下特定类型的文件,比如class类型文件,比如txt类型文件
- package com.exam.hdfs;
- import java.net.URI;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.FileStatus;
- import org.apache.hadoop.fs.FileSystem;
- import org.apache.hadoop.fs.Path;
- public class HDFS_DELETE_CLASS {
- public static final String FILETYPE = "tar.gz";
- public static final String DELETE_PATH = "/aa";
- public static void main(String[] args) throws Exception {
- new HDFS_DELETE_CLASS().rmrClassFile(new Path(DELETE_PATH));
- }
- public void rmrClassFile(Path path) throws Exception{
- // 首先获取集群必要的信息,以得到FileSystem的示例对象fs
- Configuration conf = new Configuration();
- FileSystem fs = FileSystem.get(new URI("hdfs://hadoop1:9000"), conf, "hadoop");
- // 首先检查path本身是文件夹还是目录
- FileStatus fileStatus = fs.getFileStatus(path);
- boolean directory = fileStatus.isDirectory();
- // 根据该目录是否是文件或者文件夹进行相应的操作
- if(directory){
- // 如果是目录
- checkAndDeleteDirectory(path, fs);
- }else{
- // 如果是文件,检查该文件名是不是FILETYPE类型的文件
- checkAndDeleteFile(path, fs);
- }
- }
- // 处理目录
- public static void checkAndDeleteDirectory(Path path, FileSystem fs) throws Exception{
- // 查看该path目录下一级子目录和子文件的状态
- FileStatus[] listStatus = fs.listStatus(path);
- for(FileStatus fStatus: listStatus){
- Path p = fStatus.getPath();
- // 如果是文件,并且是以FILETYPE结尾,则删掉,否则继续遍历下一级目录
- if(fStatus.isFile()){
- checkAndDeleteFile(p, fs);
- }else{
- checkAndDeleteDirectory(p, fs);
- }
- }
- }
- // 檢查文件是否符合刪除要求,如果符合要求則刪除,不符合要求则不做处理
- public static void checkAndDeleteFile(Path path, FileSystem fs) throws Exception{
- String name = path.getName();
- System.out.println(name);
- /*// 直接判断有没有FILETYPE这个字符串,不是特别稳妥,并且会有误操作,所以得判断是不是以FILETYPE结尾
- if(name.indexOf(FILETYPE) != -1){
- fs.delete(path, true);
- }*/
- // 判断是不是以FILETYPE结尾
- int startIndex = name.length() - FILETYPE.length();
- int endIndex = name.length();
- // 求得文件后缀名
- String fileSuffix = name.substring(startIndex, endIndex);
- if(fileSuffix.equals(FILETYPE)){
- fs.delete(path, true);
- }
- }
- }
7、删除HDFS集群中的所有空文件和空目录
- public class DeleteEmptyDirAndFile {
- static FileSystem fs = null;
- public static void main(String[] args) throws Exception {
- initFileSystem();
- // 创建测试数据
- // makeTestData();
- // 删除测试数据
- // deleteTestData();
- // 删除指定文件夹下的空文件和空文件夹
- deleteEmptyDirAndFile(new Path("/aa"));
- }
- /**
- * 删除指定文件夹下的 空文件 和 空文件夹
- * @throws Exception
- */
- public static void deleteEmptyDirAndFile(Path path) throws Exception {
- //当是空文件夹时
- FileStatus[] listStatus = fs.listStatus(path);
- if(listStatus.length == 0){
- fs.delete(path, true);
- return;
- }
- // 该方法的结果:包括指定目录的 文件 和 文件夹
- RemoteIterator<LocatedFileStatus> listLocatedStatus = fs.listLocatedStatus(path);
- while (listLocatedStatus.hasNext()) {
- LocatedFileStatus next = listLocatedStatus.next();
- Path currentPath = next.getPath();
- // 获取父目录
- Path parent = next.getPath().getParent();
- // 如果是文件夹,继续往下遍历,删除符合条件的文件(空文件夹)
- if (next.isDirectory()) {
- // 如果是空文件夹
- if(fs.listStatus(currentPath).length == 0){
- // 删除掉
- fs.delete(currentPath, true);
- }else{
- // 不是空文件夹,那么则继续遍历
- if(fs.exists(currentPath)){
- deleteEmptyDirAndFile(currentPath);
- }
- }
- // 如果是文件
- } else {
- // 获取文件的长度
- long fileLength = next.getLen();
- // 当文件是空文件时, 删除
- if(fileLength == 0){
- fs.delete(currentPath, true);
- }
- }
- // 当空文件夹或者空文件删除时,有可能导致父文件夹为空文件夹,
- // 所以每次删除一个空文件或者空文件的时候都需要判断一下,如果真是如此,那么就需要把该文件夹也删除掉
- int length = fs.listStatus(parent).length;
- if(length == 0){
- fs.delete(parent, true);
- }
- }
- }
- /**
- * 初始化FileSystem对象之用
- */
- public static void initFileSystem() throws Exception{
- Configuration conf = new Configuration();
- System.setProperty("HADOOP_USER_NAME", "hadoop");
- conf.addResource("config/core-site.xml");
- conf.addResource("config/hdfs-site.xml");
- fs = FileSystem.get(conf);
- }
- /**
- * 创建 测试 数据之用
- */
- public static void makeTestData() throws Exception {
- String emptyFilePath = "D:\\bigdata\\1704mr_test\\empty.txt";
- String notEmptyFilePath = "D:\\bigdata\\1704mr_test\\notEmpty.txt";
- // 空文件夹 和 空文件 的目录
- String path1 = "/aa/bb1/cc1/dd1/";
- fs.mkdirs(new Path(path1));
- fs.mkdirs(new Path("/aa/bb1/cc1/dd2/"));
- fs.copyFromLocalFile(new Path(emptyFilePath), new Path(path1));
- fs.copyFromLocalFile(new Path(notEmptyFilePath), new Path(path1));
- // 空文件 的目录
- String path2 = "/aa/bb1/cc2/dd2/";
- fs.mkdirs(new Path(path2));
- fs.copyFromLocalFile(new Path(emptyFilePath), new Path(path2));
- // 非空文件 的目录
- String path3 = "/aa/bb2/cc3/dd3";
- fs.mkdirs(new Path(path3));
- fs.copyFromLocalFile(new Path(notEmptyFilePath), new Path(path3));
- // 空 文件夹
- String path4 = "/aa/bb2/cc4/dd4";
- fs.mkdirs(new Path(path4));
- System.out.println("测试数据创建成功");
- }
- /**
- * 删除 指定文件夹
- * @throws Exception
- */
- public static void deleteTestData() throws Exception {
- boolean delete = fs.delete(new Path("/aa"), true);
- System.out.println(delete ? "删除数据成功" : "删除数据失败");
- }
- }
8、手动拷贝某个特定的数据块(比如某个文件的第二个数据块)
- /**
- * 手动拷贝某个特定的数据块(比如某个文件的第二个数据块)
- * */
- public static void copyBlock(String str,int num) {
- Path path = new Path(str);
- BlockLocation[] localtions = new BlockLocation[0] ;
- try {
- FileStatus fileStatus = fs.getFileStatus(path);
- localtions = fs.getFileBlockLocations(fileStatus, 0, fileStatus.getLen());
- /*for(int i=0;i<localtions.length;i++) {
- //0,134217728,hadoop1,hadoop3
- //134217728,64789382,hadoop3,hadoop1
- System.out.println(localtions[i]);
- }*/
- /*System.out.println(localtions[num-1].getOffset());
- System.out.println(localtions[num-1].getLength());
- String[] hosts = localtions[num-1].getHosts();*/
- FSDataInputStream open = fs.open(path);
- open.seek(localtions[num-1].getOffset());
- OutputStream out = new FileOutputStream(new File("D:/abc.tar.gz"));
- IOUtils.copyBytes(open, out,4096,true);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
9、编写程序统计出HDFS文件系统中文件大小小于HDFS集群中的默认块大小的文件占比
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.FileSystem;
- import org.apache.hadoop.fs.LocatedFileStatus;
- import org.apache.hadoop.fs.Path;
- import org.apache.hadoop.fs.RemoteIterator;
- /**
- *
- * 编写程序统计出HDFS文件系统中文件大小小于HDFS集群中的默认块大小的文件占比
- * 比如:大于等于128M的文件个数为98,小于128M的文件总数为2,所以答案是2%
- */
- public class Exam1_SmallFilePercent {
- private static int DEFAULT_BLOCKSIZE = 128 * 1024 * 1024;
- public static void main(String[] args) throws Exception {
- Configuration conf = new Configuration();
- conf.set("fs.defaultFS", "hdfs://hadoop1:9000");
- System.setProperty("HADOOP_USER_NAME", "hadoop");
- FileSystem fs = FileSystem.get(conf);
- Path path = new Path("/");
- float smallFilePercent = getSmallFilePercent(fs, path);
- System.out.println(smallFilePercent);
- fs.close();
- }
- /**
- * 该方法求出指定目录下的小文件和总文件数的对比
- * @throws Exception
- */
- private static float getSmallFilePercent(FileSystem fs, Path path) throws Exception {
- // TODO Auto-generated method stub
- int smallFile = 0;
- int totalFile = 0;
- RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(path, false);
- while(listFiles.hasNext()){
- totalFile++;
- LocatedFileStatus next = listFiles.next();
- long len = next.getLen();
- if(len < DEFAULT_BLOCKSIZE){
- smallFile++;
- }
- }
- System.out.println(smallFile+" : "+totalFile);
- return smallFile * 1f /totalFile;
- }
- }
10、编写程序统计出HDFS文件系统中的平均数据块数(数据块总数/文件总数)
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.FileSystem;
- import org.apache.hadoop.fs.LocatedFileStatus;
- import org.apache.hadoop.fs.Path;
- import org.apache.hadoop.fs.RemoteIterator;
- /**
- *
- * 编写程序统计出HDFS文件系统中的平均数据块数(数据块总数/文件总数)
- * 比如:一个文件有5个块,一个文件有3个块,那么平均数据块数为4
- * 如果还有一个文件,并且数据块就1个,那么整个HDFS的平均数据块数就是3
- */
- public class Exam2_HDSFAvgBlocks {
- public static void main(String[] args) throws Exception {
- Configuration conf = new Configuration();
- conf.set("fs.defaultFS", "hdfs://hadoop1:9000");
- System.setProperty("HADOOP_USER_NAME", "hadoop");
- FileSystem fs = FileSystem.get(conf);
- Path path = new Path("/");
- float avgHDFSBlocks = getHDFSAvgBlocks(fs, path);
- System.out.println("HDFS的平均数据块个数为:" + avgHDFSBlocks);
- fs.close();
- }
- /**
- * 求出指定目录下的所有文件的平均数据块个数
- */
- private static float getHDFSAvgBlocks(FileSystem fs, Path path) throws Exception {
- // TODO Auto-generated method stub
- int totalFiles = 0; // 总文件数
- int totalBlocks = 0; // 总数据块数
- RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(path, false);
- while(listFiles.hasNext()){
- LocatedFileStatus next = listFiles.next();
- int length = next.getBlockLocations().length;
- totalBlocks += length;
- if(next.getLen() != 0){
- totalFiles++;
- }
- }
- System.out.println(totalBlocks+" : "+totalFiles);
- return totalBlocks * 1f / totalFiles;
- }
- }
11、编写程序统计出HDFS文件系统中的平均副本数(副本总数/总数据块数)
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.FileSystem;
- import org.apache.hadoop.fs.LocatedFileStatus;
- import org.apache.hadoop.fs.Path;
- import org.apache.hadoop.fs.RemoteIterator;
- /**
- * 编写程序统计出HDFS文件系统中的平均副本数(副本总数/总数据块数)
- * 比如:总共两个文件,一个文件5个数据块,每个数据块3个副本,第二个文件2个数据块,每个文件2个副本,最终的平均副本数 = (3*3 + 2*2)/(3+2)= 2.8
- */
- public class Exam3_HDSFAvgBlockCopys {
- public static void main(String[] args) throws Exception {
- Configuration conf = new Configuration();
- conf.set("fs.defaultFS", "hdfs://hadoop02:9000");
- System.setProperty("HADOOP_USER_NAME", "hadoop");
- FileSystem fs = FileSystem.get(conf);
- Path path = new Path("/");
- float avgHDFSBlockCopys = getHDFSAvgBlockCopys(fs, path);
- System.out.println("HDFS的平均数据块个数为:" + avgHDFSBlockCopys);
- fs.close();
- }
- /**
- * 求出指定目录下的所有文件的平均数据块个数
- */
- private static float getHDFSAvgBlockCopys(FileSystem fs, Path path) throws Exception {
- // TODO Auto-generated method stub
- int totalCopy = 0; // 总副本数
- int totalBlocks = 0; // 总数据块数
- RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(path, false);
- while(listFiles.hasNext()){
- LocatedFileStatus next = listFiles.next();
- int length = next.getBlockLocations().length;
- short replication = next.getReplication();
- totalBlocks += length;
- totalCopy += length * replication;
- }
- System.out.println(totalCopy+" : "+totalBlocks);
- return totalCopy * 1f / totalBlocks;
- }
- }
12、统计HDFS整个文件系统中的不足指定数据块大小的数据块的比例
- import java.io.IOException;
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.BlockLocation;
- import org.apache.hadoop.fs.FileSystem;
- import org.apache.hadoop.fs.LocatedFileStatus;
- import org.apache.hadoop.fs.Path;
- import org.apache.hadoop.fs.RemoteIterator;
- /**
- * 统计HDFS整个文件系统中的不足指定数据块大小的数据块的比例
- * 比如指定的数据块大小是128M,总数据块有100个,不是大小为完整的128M的数据块有5个,那么不足指定数据块大小的数据块的比例就为5%
- * 注意:千万注意考虑不同文件的指定数据块大小可能不一致。所以千万不能用默认的128M一概而论
- */
- public class Exam4_LTBlockSize {
- public static void main(String[] args) throws Exception {
- Configuration conf = new Configuration();
- conf.set("fs.defaultFS", "hdfs://hadoop02:9000");
- System.setProperty("HADOOP_USER_NAME", "hadoop");
- FileSystem fs = FileSystem.get(conf);
- Path path = new Path("/");
- float avgHDFSBlockCopys = getLessThanBlocksizeBlocks(fs, path);
- System.out.println("HDFS的不足指定数据块大小的数据块数目为:" + avgHDFSBlockCopys);
- fs.close();
- }
- private static float getLessThanBlocksizeBlocks(FileSystem fs, Path path) throws Exception {
- // TODO Auto-generated method stub
- int totalBlocks = 0; // 总副本数
- int lessThenBlocksizeBlocks = 0; // 总数据块数
- RemoteIterator<LocatedFileStatus> listFiles = fs.listFiles(path, false);
- while(listFiles.hasNext()){
- LocatedFileStatus next = listFiles.next();
- BlockLocation[] blockLocations = next.getBlockLocations();
- int length = blockLocations.length;
- if(length != 0){
- totalBlocks += length;
- long lastBlockSize = blockLocations[length - 1].getLength();
- long blockSize = next.getBlockSize();
- if(lastBlockSize < blockSize){
- lessThenBlocksizeBlocks++;
- }
- }
- }
- System.out.println(lessThenBlocksizeBlocks+" : "+totalBlocks);
- return lessThenBlocksizeBlocks * 1f / totalBlocks;
- }
- }
13、统计出一个给定数组的蓄水总量(把数组的每个位置的数看是做地势高低)
- /**
- 统计出一个给定数组的蓄水总量(把数组的每个位置的数看是做地势高低)
- 比如:int[] intArray = new int[]{4,3,2,5,6,4,4,7}
- 能蓄水:[0,1,2,0,0,2,2,0] 所以总量是:7
- 核心思路:把数组切成很多个 01数组,每一层一个01数组,统计每个01数组中的合法0的总个数(数组的左边第一个1的中间区间中的0的个数)即可
- */
- public class Exam5_WaterStoreOfArray {
- public static void main(String[] args) {
- // int[] intArray = new int[]{4,3,2,5,6,4,4,7};
- // int[] intArray = new int[]{1,2,3,4,5,6};
- int[] intArray = new int[]{3,1,2,7,3,8,4,9,5,6};
- int totalWater = getArrayWater(intArray);
- System.out.println(totalWater);
- }
- /**
- * 求出数组中的水数
- */
- private static int getArrayWater(int[] intArray) {
- int findMaxValueOfArray = findMaxValueOfArray(intArray);
- int findMinValueOfArray = findMinValueOfArray(intArray);
- int length = intArray.length;
- int totalWater = 0;
- // 循环次数就是最大值和最小值的差
- for(int i=findMinValueOfArray; i<findMaxValueOfArray; i++){
- // 循环构造每一层的01数组
- int[] tempArray = new int[length];
- for(int j=0; j<length; j++){
- if(intArray[j] > i){
- tempArray[j] = 1;
- }else{
- tempArray[j] = 0;
- }
- }
- // 获取每一个01数组的合法0个数
- int waterOfOneZeroArray = getWaterOfOneZeroArray(tempArray);
- totalWater += waterOfOneZeroArray;
- }
- return totalWater;
- }
- /**
- * 寻找逻辑是:从左右开始各找一个1,然后这两个1之间的所有0的个数,就是水数
- */
- private static int getWaterOfOneZeroArray(int[] tempArray) {
- int length = tempArray.length;
- int toatalWater = 0;
- // 找左边的1
- int i = 0;
- while(i < length){
- if(tempArray[i] == 1){
- break;
- }
- i++;
- }
- // 从右边开始找1
- int j=length-1;
- while(j >= i){
- if(tempArray[j] == 1){
- break;
- }
- j--;
- }
- // 找以上两个1之间的0的个数。
- if(i == j || i + 1 == j){
- return 0;
- }else{
- for(int k=i+1; k<j; k++){
- if(tempArray[k] == 0){
- toatalWater++;
- }
- }
- return toatalWater;
- }
- }
- /**
- *
- * 描述:找出一个数组中的最大值
- */
- public static int findMaxValueOfArray(int[] intArray){
- int length = intArray.length;
- if(length == 0){
- return 0;
- }else if(length == 1){
- return intArray[0];
- }else{
- int max = intArray[0];
- for(int i=1; i<length; i++){
- if(intArray[i] > max){
- max = intArray[i];
- }
- }
- return max;
- }
- }
- /**
- * 找出一个数组中的最小值
- */
- public static int findMinValueOfArray(int[] intArray){
- int length = intArray.length;
- if(length == 0){
- return 0;
- }else if(length == 1){
- return intArray[0];
- }else{
- int min = intArray[0];
- for(int i=1; i<length; i++){
- if(intArray[i] < min){
- min = intArray[i];
- }
- }
- return min;
- }
- }
- }
Hadoop学习之路(十)HDFS API的使用的更多相关文章
- 阿里封神谈hadoop学习之路
阿里封神谈hadoop学习之路 封神 2016-04-14 16:03:51 浏览3283 评论3 发表于: 阿里云E-MapReduce >> 开源大数据周刊 hadoop 学生 s ...
- 《Hadoop学习之路》学习实践
(实践机器:blog-bench) 本文用作博文<Hadoop学习之路>实践过程中遇到的问题记录. 本文所学习的博文为博主“扎心了,老铁” 博文记录.参考链接https://www.cnb ...
- Hadoop 学习之路(七)—— HDFS Java API
一. 简介 想要使用HDFS API,需要导入依赖hadoop-client.如果是CDH版本的Hadoop,还需要额外指明其仓库地址: <?xml version="1.0" ...
- Hadoop 学习之路(六)—— HDFS 常用 Shell 命令
1. 显示当前目录结构 # 显示当前目录结构 hadoop fs -ls <path> # 递归显示当前目录结构 hadoop fs -ls -R <path> # 显示根目录 ...
- 小强的Hadoop学习之路
本人一直在做NET开发,接触这行有6年了吧.毕业也快四年了(6年是因为大学就开始在一家小公司做门户网站,哈哈哈),之前一直秉承着学要精,就一直一门心思的在做NET(也是懒吧).最近的工作一直都和大数据 ...
- 我的hadoop学习之路
Hadoop实现了一个分布式文件系统(Hadoop Distributed File System),简称HDFS.HDFS有高容错性的特点,并且设计用来部署在低廉的(low-cost)硬件上. Ha ...
- hadoop学习第二天-了解HDFS的基本概念&&分布式集群的搭建&&HDFS基本命令的使用
一.HDFS的相关基本概念 1.数据块 1.在HDFS中,文件诶切分成固定大小的数据块,默认大小为64MB(hadoop2.x以后是128M),也可以自己配置. 2.为何数据块如此大,因为数据传输时间 ...
- Hadoop学习(2)-- HDFS
随着信息技术的高度发展,数据量越来越多,当一个操作系统管辖范围存储不下时,只能将数据分配到更多的磁盘中存储,但是数据分散在多台磁盘上非常不方便管理和维护,迫切需要一种系统来管理多台机器上的文件,因此诞 ...
- Hadoop学习之路(十三)MapReduce的初识
MapReduce是什么 首先让我们来重温一下 hadoop 的四大组件: HDFS:分布式存储系统 MapReduce:分布式计算系统 YARN:hadoop 的资源调度系统 Common:以上三大 ...
随机推荐
- HNCU专题训练_线段树(1)
1.内存控制2.敌兵布阵4.广告牌5.区间第k大数(模板题)6.just a Hook7.I Hate It8.动态的最长递增子序列(区间更新题)9.图灵树10.覆盖的面积14.买票问题16.村庄问题 ...
- CSS3 @font-face实现颜色大小可控的三角效果——张鑫旭
一.我之前介绍过的三角实现效果回顾 这里所说的三角效果之等腰直角三角形效果(等边三角形有现成字符实现,没什么好说的:还有图片实现三角众人皆知,不予以说明): 1. 字符实现三角效果关于字符实现三角我早 ...
- 基于Udp的五子棋对战游戏
引言 本文主要讲述在局域网内,使用c#基于Udp协议编写一个对战的五子棋游戏.主要从Udp的使用.游戏的绘制.对战的逻辑这三个部分来讲解. 开发环境:vs2013,.Net4.0,在文章的末尾提供源代 ...
- jQuery实现大图轮播
css样式: *{ margin: 0; padding: 0;}ul{ list-style:none;}.slideShow{ width: 620px; heigh ...
- 网鼎杯 pwn 记录
题目位置 https://gitee.com/hac425/blog_data/tree/master/wdb babyheap 通过分配和释放构建 2 个 fastbin 链 利用 show 功能, ...
- mysql 运行 sql 脚本
方式一: 打开脚本,复制里面的全部内容,登陆数据库后运行. 方式二: window cmd 运行如下命令: mysql -u root -proot --port 3306 <D:\simple ...
- 64位win10系统中无法开启vmware的VT-X嵌套虚拟化功能的解决方法
在升级了win10操作系统之后,发现Vmware Workstation在安装64位操作系统虚拟机的或者要使用Intel VT-X/EPT的时候,会一直弹出vt-x被禁用的提示,如下图: ...
- 配置 tsconfig.json
作用 指导编译器如何生成 JS 文件 参数 target: 编译目标平台(es3, es5, es2015) module: 组织代码方式(commonjs, AMD) sourceMap:编译文件对 ...
- ExpressRoute 合作伙伴和对等位置
本文中的表格提供有关 ExpressRoute 连接提供商.ExpressRoute 地理覆盖范围.通过 ExpressRoute 支持的 Azure 服务以及 ExpressRoute 系统集成商 ...
- springMVC入门-03
接着上一讲介绍springMVC针对rest风格的支持. 查询数据 使用前:/user_show?id=120 使用后:/user/120 删除数据 使用前:/user_delete?id=123 使 ...