官方英文文档描述的hadoop安装方法对某些步骤的描述不够详细,以下内容是自己安装hadoop时记录的过程
(1)单机安装
参考http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/SingleCluster.html1、从http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html#jdk-7u21-oth-JPR下载jdk-7u21-linux-x64.tar.gz,在Downloads文件夹中解压缩,得到jdk1.7.0_21目录。
2、执行sudo mv ./jdk1.7.0_21 /usr/local/lib/jdk1.7.0_21
3、设置环境变量,执行sudo gedit ~/.bashrc,加入以下语句
export JAVA_HOME=/usr/local/lib/jdk1.7.0_21
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
保存退出,执行source ~/.bashrc
4、sudo update-alternatives --install /usr/bin/java java /usr/local/lib/jdk1.7.0_21/bin/java 300,设置默认程序
sudo update-alternatives --install /usr/bin/javac javac /usr/local/lib/jdk1.7.0_21/bin/javac 300
sudo update-alternatives --install /usr/bin/jar jar /usr/local/lib/jdk1.7.0_21/bin/jar 300
sudo update-alternatives --config java,检查配置
5、最后执行java -version,看看java是否安装正确
6、写一个测试文件Hello.java
//Hello.java
public class Hello{
public static void main(String[] args)
{
System.out.println("Hello world!");
}
}
执行javac Hello.java,编译成功后执行java Hello,如果输出正确,则表示java安装成功。
7、按照http://www.apache.org/dyn/closer.cgi/hadoop/common/网站说明选择合适的hadoop版本进行下载,下载后得到hadoop-2.7.2.tar.gz,将解压后的文件夹移动到/usr/local/lib/
8、执行sudo gedit ~/.bashrc,加入以下语句
export HADOOP_INSTALL=/usr/local/lib/hadoop-2.7.2
export PATH=$PATH:$HADOOP_INSTALL/bin
export PATH=$PATH:$HADOOP_INSTALL/sbin
export HADOOP_MAPRED_HOME=$HADOOP_INSTALL
export HADOOP_COMMON_HOME=$HADOOP_INSTALL
export HADOOP_HDFS_HOME=$HADOOP_INSTALL
export YARN_HOME=$HADOOP_INSTALL
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_INSTALL/lib"
9、执行hadoop version,检查配置是否成功
10、现在的hadoop是单机模式,执行以下内容测试hadoop是否安装成功
$ mkdir input
$ cp etc/hadoop/*.xml input
$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar grep input output 'dfs[a-z.]+',从文件中查询匹配正则表达式的内容
$ cat output/*
11、删除input中所有内容和output目录,执行hadoop经典实例WordCount
$ bin/hadoop jar share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-2.4.0-sources.jar org.apache.hadoop.examples.WordCount input output
$ cat output/*
(2)伪分布式安装
参考http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/SingleCluster.html#Pseudo-Distributed_Operation,已经安装好了,在/usr/local/lib/hadoop-2.7.2