ubuntu安装hadoop详细步骤
原文地址: http://blog.csdn.net/feixia586/article/details/24950111?utm_source=tuicool&utm_medium=referral
hadoop官方网站对其安装配置hadoop的步骤太粗略,在这篇博客中,我会详细介绍在ubuntu中如何安装hadoop,并处理可能出现的一些问题。这里介绍的方法是用一台机器虚拟多个节点,这个方法已在如下环境中测试通过:
OS: Ubuntu 13.10
Hadoop: 2.2.0 (2.x.x)
个人认为在其他版本上安装Hadoop 2.x.x的方法基本相同,因此如果严格按照我给的步骤,应该不会有问题。
前提
安装 jdk 和 openssh
$ sudo apt-get install openjdk-7-jdk
$ java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1~0.13.10.1)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
$ sudo apt-get install openssh-server
openjdk的默认路径是 /usr/lib/jvm/java-7-openjdk-amd64. 如果你的默认路径和我的不同,请再后面的操作中替换此路径。
添加Hadoop用户组和用户
$ sudo addgroup hadoop$ sudo adduser --ingroup hadoop hduser
$ sudo adduser hduser sudo
然后切换到hduser账户
配置SSH
将public key加入到authorized_keys中,这样hadoop在运行ssh时就不需要输入密码了
现在我们测试一下ssh
$ exit
下载Hadoop 2.2.0 (2.x.x)
$ wget http://www.trieuvan.com/apache/hadoop/common/hadoop-2.2.0/hadoop-2.2.0.tar.gz
$ sudo tar -xzvf hadoop-2.2.0.tar.gz -C /usr/local
$ cd /usr/local
$ sudo mv hadoop-2.2.0 hadoop
$ sudo chown -R hduser:hadoop hadoop
$ vim .bashrc
将下面的内容复制到.bashrc中
#Hadoop variables
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export HADOOP_INSTALL=/usr/local/hadoop
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
###end of paste
退出.bashrc
$ vim hadoop-env.sh
# begin of paste
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/export HADOOP_COMMON_LIB_NATIVE_DIR="/usr/local/hadoop/lib/native/"
export HADOOP_OPTS="$HADOOP_OPTS -Djava.library.path=/usr/local/hadoop/lib/"
### end of paste
退出terminal再重新打开
- <property>
- <name>fs.default.name</name>
- <value>hdfs://localhost:9000</value>
- </property>
- <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>
$ vim mapred-site.xml
- <property>
- <name>mapreduce.framework.name</name>
- <value>yarn</value>
- </property>
$ mkdir -p ~/mydata/hdfs/datanode
$ vim hdfs-site.xml
- <property>
- <name>dfs.replication</name>
- <value>1</value>
- </property>
- <property>
- <name>dfs.namenode.name.dir</name>
- <value>file:/home/hduser/mydata/hdfs/namenode</value>
- </property>
- <property>
- <name>dfs.datanode.data.dir</name>
- <value>file:/home/hduser/mydata/hdfs/datanode</value>
- </property>
格式化 namenode
17785 SecondaryNameNode
17436 NameNode
17591 DataNode
18096 NodeManager
17952 ResourceManager
23635 Jps
当执行start-dfs.sh的时候,你可能会看到 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable,不用担心,其实可以正常使用,我们会在trouble shooting那一节谈到这个问题。
测试并运行示例
$ hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-client-jobclient-2.2.0-tests.jar TestDFSIO -write -nrFiles 20 -fileSize 10
$ hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-client-jobclient-2.2.0-tests.jar TestDFSIO -clean
$ hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-2.2.0.jar pi 2 5
网页界面
HDFS status: http://localhost:50070
Secondary NameNode status: http://localhost:50090
Trouble-shooting
1. Unable to load native-hadoop library for your platform.
这是一个警告,基本不会影响hadoop的使用,但是在之后我们还是给予解决这个warning的方法。通常来讲,出现这个warning的原因是你在64位的系统上,但是hadoop的package是为32位的机器编译的。在这种情况下,确认你不要忘记在hadoop-env.sh中加入这几行:export HADOOP_OPTS="$HADOOP_OPTS -Djava.library.path=/usr/local/hadoop/lib/"
我们不希望有warning,如何解决?方法是自己重新编译源代码。重新编译其实很简单:
安装 maven
$ sudo apt-get install maven
安装 protobuf-2.5.0 or later
$ curl -# -O https://protobuf.googlecode.com/files/protobuf-2.5.0.tar.gz
$ tar -xzvf protobuf-2.5.0.tar.gz
$ cd protobuf-2.5.0
$ ./configure --prefix=/usr
$ make
$ sudo make install
$ cd ..
现在并编译hadoop源代码,注意编译之前需要先给源代码打个补丁
$ wget http://www.eu.apache.org/dist/hadoop/common/stable/hadoop-2.2.0-src.tar.gz
$ tar -xzvf hadoop-2.2.0-src.tar.gz
$ cd hadoop-2.2.0-src
$ wget https://issues.apache.org/jira/secure/attachment/12614482/HADOOP-10110.patch
$ patch -p0 < HADOOP-10110.patch
$ mvn package -Pdist,native -DskipTests -Dtar
现在到 hadoop-dist/target/ 目录下, 你会看到 hadoop-2.2.0.tar.gz or hadoop-2.2.0, 他们就是编译后的hadoop包。 你可以使用自己编译的包,同样按照之前的步骤安装64位的hadoop。如果你已经安装了32位的hadoop,只需要替换 /usr/local/hadoop/lib/native 目录,然后将如下两行从hadoop-env.sh中移除即可:
export HADOOP_COMMON_LIB_NATIVE_DIR="/usr/local/hadoop/lib/native/"
export HADOOP_OPTS="$HADOOP_OPTS -Djava.library.path=/usr/local/hadoop/lib/"
2. datanode 不能被启动
参考文献
http://www.csrdu.org/nauman/2014/01/23/geting-started-with-hadoop-2-2-0-building/
http://codesfusion.blogspot.com/2013/10/setup-hadoop-2x-220-on-ubuntu.html?m=1
http://www.ercoppa.org/Linux-Install-Hadoop-220-on-Ubuntu-Linux-1304-Single-Node-Cluster.htm
http://www.ercoppa.org/Linux-Compile-Hadoop-220-fix-Unable-to-load-native-hadoop-library.htm