最近在学hadoop,hadoop的配置之前配置过,这次重新配置一次加深下印象,配置过程自己简单罗列了一下,比较简单,可能只有自己能看懂吧,以后有时间完善下。
1、安装jdk
2、安装hadoop
3、配置xml文件(有挖坑了,file文件夹一定要写对,file:/usr...)
4、启动:
先执行:hadoop namenode -fromat
配置:core-site.xml 中的hadoop.tmp.dir 可以改变位置,以后只要执行一次即可
配置文件见附件1
第一次启动之前先格式户namenode:
hadoop namenode -format
再执行:sh start-all.sh 或者:sh start-dfs.sh 和 sh start-yarn.sh
(启动完后,通过jps查看启动的进程)
5、添加文件
hadoop fs -mkdir /input //新建input文件夹
hadoop fs -put /input/*.xml /input //将文件放到input文件夹中存储
hadoop fs -ls /input/ //显示文件夹内的文件列表
hadoop fs -ls -R / //递归查看所有的文件
6、执行一次简单的运算
bin/hadoop share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /input/ /output/wordcount1
查看结果:
hadoop fs -cat /output/wordcout1/*
如果打包包括介绍文件,不需要指定执行类了,弄了一晚上才弄出来,菜鸟啊
比如我的打包文件为HadoopDemo.jar, 其中包括了META-INF了,所以直接执行:
hadoop jar source/.jar MaxTemperature /input/temperature/*.gz /output/MaxTemp
然后查看运算结果:
hadoop fs -cat /output/MaxTemp/*
附件1:需要配置的文件(core-site.xml, yarn-site.xml,mapred-site.xml,hdfs-site.xml )
core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://master:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/lck/Hadoop/tmp</value>
</property>
</configuration>
hdfs-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>master:10020</value>
</property>
<property
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
</configuration>
mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>master:10020</value>
</property>
</configuration>
yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>