如何实现HDFS

41次阅读
没有评论

这篇文章将为大家详细讲解有关如何实现 HDFS-Hadoop 分布式文件系统,丸趣 TV 小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

hdfs 和传统文件系统对比:

1, 支持超大文件;

2,hdfs 数据块独立于具体磁盘数据块, 容错性;

hadoop 节点分类: 管理 / 工作节点:

管理节点: 管理文件系统树以及整棵树内所有文件和目录, 如果管理节点挂了, 整个系统就挂了;

工作节点: 存储具体数据的节点, 定期向管理节点发送自己节点的数据列表;

hdfs 管理节点防挂机制: 双机热备份和定时备份;

伪分布模式部署:

1,hadoop 通过 ssh 对各个节点进行通讯, 所以需要配置 ssh, 并且用空口令;

    其实这个只是通讯方式的问题, 可以用 ssh, 根据安全需要, 也可以改用其他通讯模式., 甚至可以用 java socket 重写。

配置 ssh

t@ubuntu:~$ ssh-keygen -t rsa -P   -f ~/.ssh/id_rsa
Generating public/private rsa key pair.
Your identification has been saved in /home/t/.ssh/id_rsa.
Your public key has been saved in /home/t/.ssh/id_rsa.pub.
The key fingerprint is:
5c:f9:27:86:a5:88:97:1b:07:fe:3c:95:90:a8:e8:8f t@ubuntu
The key s randomart image is:
+--[ RSA 2048]----+
| |
| . o |
| o = . |
| . = = * . |
| . o S + * . |
| . . * o o |
| . . + |
| o . |
| E . |
+-----------------+
t@ubuntu:~$ cat ~/.ssh/id_rsa.pub   ~/.ssh/authorized_keys

配置文件

core-site.xml:

?xml version= 1.0  encoding= UTF-8 ? 
 ?xml-stylesheet type= text/xsl  href= configuration.xsl ? 
 Licensed under the Apache License, Version 2.0 (the  License 
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an  AS IS  BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License. See accompanying LICENSE file.
 !-- Put site-specific property overrides in this file. -- 
 configuration 
  property 
  name fs.default.name /name 
  value hdfs://localhost /value 
  /property 
 /configuration

hdfs-site.xml 

?xml version= 1.0  encoding= UTF-8 ? 
 ?xml-stylesheet type= text/xsl  href= configuration.xsl ? 
 Licensed under the Apache License, Version 2.0 (the  License 
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an  AS IS  BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License. See accompanying LICENSE file.
 !-- Put site-specific property overrides in this file. -- 
 configuration 
  property 
  name dfs.replication /name 
  value 1 /value 
  /property 
 /configuration

mapred-site.xml

?xml version= 1.0 ? 
 ?xml-stylesheet type= text/xsl  href= configuration.xsl ? 
 Licensed under the Apache License, Version 2.0 (the  License 
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an  AS IS  BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License. See accompanying LICENSE file.
 !-- Put site-specific property overrides in this file. -- 
 configuration 
  property 
  name mapred.job.tracker /name 
  value localhost:8021 /value 
  /property 
 /configuration

备注:hadoop 最新版本已经不存在 conf 文件夹, 配置文件直接写在

$HADOOP_INSTALL/hadoop-2.6.2/etc/hadoop/

格式化 hdfs 文件系统

t@ubuntu:~/hadoop/hadoop-2.6.2/etc/hadoop$ hadoop namenode -format

按 权威 一书方法会报错, 需要在 hadoop-env.sh 中配置 java_home

启动 hdfs 守护进程:

t@ubuntu:~$ start-dfs.sh

查看 namenode:http://ip:50070/

关闭 hdfs 守护进程:

t@ubuntu:~$ stop-dfs.sh

执行 hadoop 文件输出:

t@ubuntu:~/hadoop/ex$ hadoop jar hadoop-urlCat.jar hdfs://localhost/testHadoop.txt URLCat output1
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/t/hadoop/hadoop-2.6.2/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/t/hadoop/ex/hadoop-examples.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
haddop 测试文件 

hadoop 文件操作基本命令

t@ubuntu:~/hadoop/ex$ hadoop fs 
Usage: hadoop fs [generic options]
 [-appendToFile  localsrc  ...  dst]
 [-cat [-ignoreCrc]  src  ...]
 [-checksum  src  ...]
 [-chgrp [-R] GROUP PATH...]
 [-chmod [-R]  MODE[,MODE]... | OCTALMODE  PATH...]
 [-chown [-R] [OWNER][:[GROUP]] PATH...]
 [-copyFromLocal [-f] [-p] [-l]  localsrc  ...  dst ]
 [-copyToLocal [-p] [-ignoreCrc] [-crc]  src  ...  localdst ]
 [-count [-q] [-h]  path  ...]
 [-cp [-f] [-p | -p[topax]]  src  ...  dst ]
 [-createSnapshot  snapshotDir  [ snapshotName]]
 [-deleteSnapshot  snapshotDir   snapshotName]
 [-df [-h] [path  ...]]
 [-du [-s] [-h]  path  ...]
 [-expunge]
 [-get [-p] [-ignoreCrc] [-crc]  src  ...  localdst ]
 [-getfacl [-R]  path ]
 [-getfattr [-R] {-n name | -d} [-e en]  path ]
 [-getmerge [-nl]  src   localdst ]
 [-help [cmd ...]]
 [-ls [-d] [-h] [-R] [path  ...]]
 [-mkdir [-p]  path  ...]
 [-moveFromLocal  localsrc  ...  dst]
 [-moveToLocal  src   localdst]
 [-mv  src  ...  dst]
 [-put [-f] [-p] [-l]  localsrc  ...  dst ]
 [-renameSnapshot  snapshotDir   oldName   newName]
 [-rm [-f] [-r|-R] [-skipTrash]  src  ...]
 [-rmdir [--ignore-fail-on-non-empty]  dir  ...]
 [-setfacl [-R] [{-b|-k} {-m|-x  acl_spec}  path ]|[--set  acl_spec   path]]
 [-setfattr {-n name [-v value] | -x name}  path ]
 [-setrep [-R] [-w]  rep   path  ...]
 [-stat [format]  path  ...]
 [-tail [-f]  file ]
 [-test -[defsz]  path ]
 [-text [-ignoreCrc]  src  ...]
 [-touchz  path  ...]
 [-usage [cmd ...]]
Generic options supported are
-conf  configuration file  specify an application configuration file
-D  property=value  use value for given property
-fs  local|namenode:port  specify a namenode
-jt  local|resourcemanager:port  specify a ResourceManager
-files  comma separated list of files  specify comma separated files to be copied to the map reduce cluster
-libjars  comma separated list of jars  specify comma separated jar files to include in the classpath.
-archives  comma separated list of archives  specify comma separated archives to be unarchived on the compute machines.
The general command line syntax is
bin/hadoop command [genericOptions] [commandOptions]
t@ubuntu:~/hadoop/ex$ hadoop fs -ls /

关于“如何实现 HDFS-Hadoop 分布式文件系统”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。