本文是根据Hadoop官网安装教程写的Hadoop YARN在单机伪分布式环境下的安装报告,仅供参考。
1. 安装环境如下:
操作系统:Ubuntu14.04
Hadoop版本:hadoop-2.5.0
Java版本:openjdk-1.7.0_55
2. 下载Hadoop-2.5.0,下载地址 http://mirrors.cnnic.cn/apache/hadoop/common/hadoop-2.5.0/hadoop-2.5.0.tar.gz
本文的$HADOOP_HOME为:/home/baisong/hadoop-2.5.0(用户名为baisong)。在 ~/.bashrc文件中添加环境变量,如下:
export HADOOP_HOME=/home/baisong/hadoop-2.5.0
然后编译,命令如下:
$ source ~/.bashrc
3. 安装JDK,并设置JAVA_HOME环境变量。在/etc/profile文件最后添加如下内容
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386 //根据自己Java安装目录而定
export PATH=$JAVA_HOME/bin:$PATH
输入以下命令使配置生效
$ source /etc/profile
4. 配置SSH。首先生成秘钥,命令如下,然后一路回车确认,不需要任何输入。
$ ssh-keygen -t rsa
然后把公钥写入authorized_keys文件中,命令如下:
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
最后,输入下述命令,按提示输入 yes 即可。
$ ssh localhost
$ ssh Hama
5. 修改Hadoop配置文件,进入${HADOOP_HOME}/etc/hadoop/目录。
1)设置环境变量,hadoop-env.sh中添加Java安装目录,如下:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
2)修改core-site.xml,添加如下内容。
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/baisong/hadooptmp</value>
</property>
注:hadoop.tmp.dir项可选(上述设置需手动创建hadooptmp文件夹)。
3)修改hdfs-site.xml,添加以下内容“。
<property>
<name>dfs.repliacation</name>
<value>1</value>
</property>
4)将mapred-site.xml.template重命名为mapred-site.xml,并添加如下内容。
$ mv mapred-site.xml.template mapred-site.xml //重命名
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
5)修改yarn-site.xml,添加以下内容。
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
6. 格式化HDFS,命令如下:
bin/hdfs namenode -format //bin/hadoop namenode -format命令已过时
格式化成功会在/home/baisong/hadooptmp创建dfs文件夹。
7.启动HDFS,命令如下:
$ sbin/start-dfs.sh
遇到如下错误:
14/10/29 16:49:01 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Starting namenodes on [OpenJDK Server VM warning: You have loaded library /home/baisong/hadoop-2.5.0/lib/native/libhadoop.so.1.0.0 which might have disabled stack guard. The VM will try to fix the stack guard now. It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'. localhost] sed: -e expression #1, char 6: unknown option to `s' VM: ssh: Could not resolve hostname vm: Name or service not known library: ssh: Could not resolve hostname library: Name or service not known have: ssh: Could not resolve hostname have: Name or service not known which: ssh: Could not resolve hostname which: Name or service not known might: ssh: Could not resolve hostname might: Name or service not known warning:: ssh: Could not resolve hostname warning:: Name or service not known loaded: ssh: Could not resolve hostname loaded: Name or service not known have: ssh: Could not resolve hostname have: Name or service not known Server: ssh: Could not resolve hostname server: Name or service not known分析原因知,没有设置 HADOOP_COMMON_LIB_NATIVE_DIR和HADOOP_OPTS环境变量,在 ~/.bashrc文件中添加如下内容并编译。
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib"
$ source ~/.bashrc
重新启动HDFS,输出如下,表示启动成功。
可以用过Web界面来查看NameNode运行状况,URL为http://localhost:50070
停止HDFS的命令为:
$ sbin/stop-dfs.sh
8. 启动YARN,命令如下:
$ sbin/start-yarn.sh
可以用过Web界面来查看NameNode运行状况,URL为http://localhost:8088
停止HDFS的命令为:
$ sbin/stop-yarn.sh
上述HDFS和YARN启动完成后,可通过jps命令查看是否启动成功。
9. 运行测试程序。
1)测试计算PI,命令如下:
$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.0.jar pi 20 10
2)测试 grep,首先需要上传输入文件到HDFS上,命令如下:
$ bin/hdfs dfs -put etc/hadoop input
运行grep程序,命令如下:
$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.0.jar grep input output ‘dfs[a-z.]+‘
运行结果输出如下:
10. 添加环境变量,方便使用start-dfs.sh、start-yarn.sh等命令(可选)。
在 ~/.bashrc文件中添加环境变量,如下:
export PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
然后编译,命令如下:
$ source ~/.bashrc
下图是 ~/.bashrc文件中添加的变量,以便参考。
原文地址:http://blog.csdn.net/xin_jmail/article/details/40556267