搭建hdfs伪分布式模式

1.在上一篇单机模式的基础上配置xml

修改core-site.xml,

vi etc/hadoop/core-site.xml

<configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://localhost:9000</value>
    </property>
</configuration>

搭建hdfs伪分布式模式

修改hdfs-site.xml,

vi etc/hadoop/hdfs-site.xml

<configuration>
  <property>
    <name>dfs.replication</name>
    <value>1</value>
  </property>
</configuration>

搭建hdfs伪分布式模式

然后本地启动MapReduce任务。先格式化文件系统


  $ ./bin/hdfs namenode -format

搭建hdfs伪分布式模式

红线部分成功格式化

搭建hdfs伪分布式模式

启动守护进程

./sbin/start-dfs.sh

搭建hdfs伪分布式模式

用jps命令来查看节点守护进程启动情况

搭建hdfs伪分布式模式

一些常用的命令。大概与linux相同

搭建hdfs伪分布式模式

比如ls命令:  ./bin/hdfs dfs -ls /

创建hdfs文件系统的目录:
./bin/hdfs dfs -mkdir /user
./bin/hdfs dfs -mkdir /user/hadoop
然后我们将之前input文件夹拷贝到hdfs文件系统中:
./bin/hdfs dfs -put input /user/hadoop
我们可以使用如下命令查看,是否将input文件夹拷贝到了hdfs文件系统中:
./bin/hdfs dfs -ls /user/hadoop/input/*


搭建hdfs伪分布式模式

删除单机模式下创建的input output

rm -rf input output

然后运行

./bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.0.0.jar wordcount input output

搭建hdfs伪分布式模式

搭建hdfs伪分布式模式

然后查看运行结果:

./bin/hdfs dfs -cat /user/hadoop/output/*

搭建hdfs伪分布式模式

与单机下运行的结果一样

接下来去研究真正的分布式模式。