在Ubuntu下安装Hadoop2.7.0


安装环境:Ubuntu kylin 14.04

安装一般分为如下几步:

  1. 安装运行环境
  2. 修改主机名和用户名
  3. 配置静态IP地址
  4. 配置SSH无密码连接
  5. 安装JDK
  6. 配置Hadoop
  7. 格式化HDFS
  8. 启动Hadoop并验证安装

下载地址:

​http://www.apache.org/dyn/closer.cgi/hadoop/common/​​​
下载压缩包:
​​​http://mirrors.cnnic.cn/apache/hadoop/common/hadoop-2.7.0/​

新增用户

sudo addgroup hadoop
sudo adduser -ingroup hadoop hadoop

Hadoop 学习笔记二 单机安装_apache

sudo gedit /etc/sudoers
在文件里给hadoop权限:
hadoop ALL=(ALL) ALL
sudo reboot
然后用hadoop账号登陆系统。

安装ssh

sudo apt-get install openssh-server
sudo /etc/init.d/ssh start
ps -e | grep ssh

Hadoop 学习笔记二 单机安装_hadoop_02

ssh-keygen -t rsa -P “”

Hadoop 学习笔记二 单机安装_hadoop_03

生成的文件里:
id_rsa 私钥 id_rsa.pub 公钥

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh localhost

安装java

sudo apt-get install openjdk-7-jdk
update-alternatives –config java

Hadoop 学习笔记二 单机安装_apache_04
我这里安装了jdk1.6、jdk1.7,使用中的是jdk1.7,记录它的路径
/usr/lib/jvm/java-7-openjdk-amd64

安装hadoop

sudo mkdir /usr/local/hadoop
sudo chmod 774 /usr/local/hadoop
sudo mv hadoop-2.7.0.tar.gz /usr/local
sudo tar xzf hadoop-2.7.0.tar.gz
sudo mv hadoop-2.7.0/* /usr/local/hadoop

配置

sudo gedit ~/.bashrc

如果这时报下面错误,把终端关上重开一次。
error: XDG_RUNTIME_DIR not set in the environment.

把下面内容复制到文件末尾:

#HADOOP VARIABLES START
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
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_INSTALL/lib"
#HADOOP VARIABLES END

source ~/.bashrc
sudo gedit /usr/local/hadoop/etc/hadoop/hadoop-env.sh

修改如下:
#export JAVA_HOME=${JAVA_HOME}
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

测试

cd /usr/local/hadoop
mkdir input
cp README.txt input
bin/hadoop jar share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-2.7.0-sources.jar org.apache.hadoop.examples.WordCount input output

运行结果:
Hadoop 学习笔记二 单机安装_ubuntu_05

cat output/*
这时可以看到输出结果:
Hadoop 学习笔记二 单机安装_ubuntu_06