`
liubin2010
  • 浏览: 303313 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

伪分布式版

 
阅读更多

sudo gedit /usr/local/hadoop/etc/hadoop/core-site.xml

  1. <configuration>  
  2.     <property>  
  3.         <name>hadoop.tmp.dir</name>  
  4.         <value>/usr/local/hadoop/tmp</value>  
  5.         <description>Abase for other temporary directories.</description>  
  6.     </property>  
  7.     <property>  
  8.         <name>fs.defaultFS</name>  
  9.         <value>hdfs://localhost:9000</value>  
  10.     </property>  
  11. </configuration>  

 sudo gedit /usr/local/hadoop/etc/hadoop/mapred-site.xml //此项不必要
  1. <configuration>  
  2.  <property>     
  3.       <name>mapred.job.tracker</name>    
  4.       <value>localhost:9001</value>     
  5.      </property>     
  6. </configuration>  

 sudo gedit /usr/local/hadoop/etc/hadoop/yarn-site.xml

  1. <configuration>  
  2. <property>  
  3. <name>mapreduce.framework.name</name>  
  4. <value>yarn</value>  
  5. </property>  
  6.   
  7. <property>  
  8. <name>yarn.nodemanager.aux-services</name>  
  9. <value>mapreduce_shuffle</value>  
  10. </property>  
  11. </configuration>  

 sudo gedit /usr/local/hadoop/etc/hadoop/hdfs-site.xml

  1. <configuration>  
  2. <property>  
  3.         <name>dfs.replication</name>  
  4.         <value>1</value>  
  5.     </property>  
  6.     <property>  
  7.         <name>dfs.namenode.name.dir</name>  
  8.         <value>file:/usr/local/hadoop/dfs/name</value>  
  9.     </property>  
  10.     <property>  
  11.         <name>dfs.datanode.data.dir</name>  
  12.         <value>file:/usr/local/hadoop/dfs/data</value>  
  13.     </property>  
  14.     <property>                 //这个属性节点是为了防止后面eclopse存在拒绝读写设置的  
  15.             <name>dfs.permissions</name>  
  16.             <value>false</value>  
  17.      </property>  
  18.  </configuration>  

sudo gedit /usr/local/hadoop/etc/hadoop/masters 添加:localhost

sudo gedit /usr/local/hadoop/etc/hadoop/slaves  添加:localhost

 

关于配置的一点说明:上面只要配置 fs.defaultFS 和 dfs.replication 就可以运行,不过有个说法是如没有配置 hadoop.tmp.dir 参数,此时 Hadoop 默认的使用的临时目录为 /tmp/hadoo-hadoop,而这个目录在每次重启后都会被干掉,必须重新执行 format 才行(未验证),所以伪分布式配置中最好还是设置一下。

配置完成后,首先在 Hadoop 目录下创建所需的临时目录:

  1. cd /usr/local/hadoop  
  2. mkdir tmp dfs dfs/name dfs/data  
chmod -R 777 hadooop 2.6.0 //用于对创建文件的权限赋值
接着初始化文件系统HDFS。
  1. bin/hdfs namenode -format  
成功的话,最后的提示如下,Exitting with status 0 表示成功,Exitting with status 1: 则是出错。
sudo gedit /usr/local/hadoop-2.6.0/etc/hadoop/hadoop-env.sh
export JAVA_HOME=/usr/local/jvm/jdk1.7.0_75
  1. sbin/start-dfs.sh  
  2. sbin/start-yarn.sh  

Unable to load native-hadoop library for your platform这个提示,解决方式:
1、重新编译源码后将新的lib/native替换到集群中原来的lib/native
2、修改hadoop-env.sh ,增加
export HADOOP_OPTS="-Djava.library.path=$HADOOP_PREFIX/lib:$HADOOP_PREFIX/lib/native"

Namenode information:http://localhost:50070来查看Hadoop的信息。

All Applications:http://http://2xx.81.8x.1xx:8088/,将其中的2xx.81.8x.1xx替换为你的实际IP地址。

 

 

 

运行例子:

 

1.先在hdfs上建个文件夹

          bin/hdfs dfs -mkdir /readme                                
2.上传一些文件:bin/hdfs dfs -put README.txt  /readme

                把README.txt文件上传到hdfs的/readme中

 

3.执行指令

 

                        bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.0.jar wordcount /readme readmeout

 

4.查看结果

 

                bin/hdfs dfs -cat /readmeout/*

 

(BIS),    1
(ECCN)    1
(TSU)    1
(see    1
5D002.C.1,    1
740.13)    1
<http://www.wassenaar.org/>    1
Administration    1
Apache    1
BEFORE    1
BIS    1
Bureau    1
Commerce,    1
Commodity    1
Control    1
Core    1
Department    1
ENC    1
Exception    1
Export    2
For    1
Foundation    1
Government    1
Hadoop    1
Hadoop,    1
Industry    1
Jetty    1
License    1
Number    1
Regulations,    1
SSL    1
Section    1
Security    1
See    1
Software   

也可以将运行结果取回到本地。

rm -R ./output
bin/hdfs dfs -get output output
cat ./output/*

可以看到,使用bin/hdfs dfs -命令可操作分布式文件系统, 如

bin/hdfs dfs -ls /user/hadoop           # 查看`/user/hadoop`中的文件
bin/hdfs dfs -rm -R /user/hadoop/input/*    # 删除 input 中的文件
bin/hdfs dfs -rm -R /user/hadoop/output     # 删除 output 文件夹

问题1:找不到配置文件etc/hadoop,是SSH服务没有启动

问题2:出现运行异常,需要注意所采用的服务器文件路径是否正确

结果查看: 查看集群概况:http://localhost:8088/cluster

查看运行结果:http://localhost:50070/dfshealth.html#tab-overview



 

  • 大小: 192.6 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics