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
现在你在hduser账户中。 请注意下面命令中 '' 是两个单引号 ‘
$ ssh-keygen -t rsa -P ''
将public key加入到authorized_keys中,这样hadoop在运行ssh时就不需要输入密码了
将public key加入到authorized_keys中,这样hadoop在运行ssh时就不需要输入密码了
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
现在我们测试一下ssh
现在我们测试一下ssh
$ ssh localhost
如果你被询问是否确认连接,输入yes。如果你发现在即不需要输密码,cool -- 至少到目前位置你是正确的。否则,请debug。
$ exit
$ exit
下载Hadoop 2.2.0 (2.x.x)
$ cd ~
$ 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
$ 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
$ cd ~
$ 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 .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
$ cd /usr/local/hadoop/etc/hadoop
$ vim hadoop-env.sh
$ vim hadoop-env.sh
将下面的三行加入到hadoop-env.sh中,删除原来的 "export JAVA_HOME"那行
# 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再重新打开
# 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再重新打开
copy
>yarn.nodemanager.aux-services>mapreduce_shuffle>yarn.nodemanager.aux-services.mapreduce.shuffle.class>org.apache.hadoop.mapred.ShuffleHandler>
$ mv mapred-site.xml.template mapred-site.xml
$ vim mapred-site.xml
$ mkdir -p ~/mydata/hdfs/datanode
$ vim hdfs-site.xml