主要步骤跟Hadoop1.0(1.0安装地址)一致,主要在配置这块有更改
安装
-
下载地址:http://archive.apache.org/dist/hadoop/core/hadoop-2.6.5/
-
hadoop安装目录创建./tmp目录,./dfs/name,./dfs/data
-
修改./etc/hadoop/hadoop-env.sh
# 设置JAVA_HOME
export JAVA_HOME="/usr/local/src/jdk1.8.0_181/"
- 修改./etc/hadoop/yarn-env.sh
# 设置JAVA_HOME
JAVA_HOME="/usr/local/src/jdk1.8.0_181/"
- 修改./etc/hadoop/slaves
slave1
slave2
- 修改./etc/hadoop/core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://master:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/usr/local/src/hadoop-2.6.5/tmp</value>
</property>
</configuration>
- 修改./etc/hadoop/hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>master:9001</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/usr/local/src/hadoop-2.6.5/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/usr/local/src/hadoop-2.6.5/dfs/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
</configuration>
- 修改./etc/hadoop/mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>slave1:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>slave1:19888</value>
</property>
</configuration>
- 修改./etc/hadoop/yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>master:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>master:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>master:8035</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>master:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>master:8088</value>
</property>
<property>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
</property>
<property>
<name>yarn.log-aggregation.retain-seconds</name>
<value>259200</value>
</property>
<property>
<name>yarn.log.server.url</name>
<value>http://slave1:19888/jobhistory/logs</value>
</property>
<property>
<name>yarn.nodemanager.vmem-pmem-ratio</name>
<value>4.0</value>
</property>
</configuration>
-
和Hadoop1.0一样,第一次启动前,需要格式化hdfs:./bin/hadoop namenode -format
-
启动:./sbin/start-all.sh
-
使用:跟Hadoop1.0一样,使用./bin/hadoop命令
-
关闭:./sbin/stop-all.sh
提交MapReduce任务
基本上没什么变化,除了Hadoop streaming地址变了
[wadeyu@master mr_count]$ cat run.sh
HADOOP_CMD=/usr/local/src/hadoop-2.6.5/bin/hadoop
HADOOP_STREAMING_JAR=/usr/local/src/hadoop-2.6.5/share/hadoop/tools/lib/hadoop-streaming-2.6.5.jar
INPUT_FILE=/data/The_Man_of_Property.txt
OUTPUT_DIR=/output/wc
$HADOOP_CMD fs -rmr -skipTrash $OUTPUT_DIR
$HADOOP_CMD jar $HADOOP_STREAMING_JAR \\
-input $INPUT_FILE \\
-output $OUTPUT_DIR \\
-mapper "python map.py" \\
-reducer "python red.py" \\
-file ./map.py \\
-file ./red.py
参考资料
【0】八斗学院内部培训资料