安装hadoop单机模式
软件信息:
hadoop 2.5.2
jdk1.7
redhat 6.2
流程为:
安装ssh,设置ssh免密码登录
安装与配置hadoop
格式化与启动
验证hadoop启动
所有操作都是在root用户权限下完成,因为新建普通用户赋予root用户权限时,一直不能操作/etc/下的文件,这个问题没有解决,所以迫不得已。
1.安装shh
1.首先检查是否安装了SSH,
<span style="white-space:pre"> </span># which ssh
<span style="white-space:pre"> </span># which sshd
<span style="white-space:pre"> </span># which ssh-keygen
如果接到类似这样的错误消息:
<span style="white-space:pre"> </span>/usr/bin/which: no ssh in (/usr/bin:/bin:/usr/sbin...)
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"><span> </span>需要</span><span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">自己下载ssh</span>
<span style="white-space:pre"> </span># yum install openssh-service
2.生成ssh密钥对,设置ssh免密码登陆
<span style="white-space:pre"> </span># ssh-keygen -t rsa
<span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="font-family: Arial, Helvetica, sans-serif;">一直按确定就可以,此时会在/home/hadoop/.ssh下生成 id_rsa.pub 和id_rsa两个,前者为公钥,后者为私钥。</span>
<span style="white-space:pre"> </span>将公钥追加到authorized_keys中,它用于保存所有允许以当前用户登录到ssh客户端的公钥内容:
<span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="font-family: Arial, Helvetica, sans-serif;"># </span><span style="font-family: Arial, Helvetica, sans-serif;">cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys</span>
<span style="white-space:pre"> </span>登录ssh
<span style="white-space:pre"> </span><span style="font-family: Arial, Helvetica, sans-serif;"># ssh localhost</span>
<span style="white-space:pre">
</span>
<span style="white-space:pre"><span style="font-family:Arial, Helvetica, sans-serif;"><span style="white-space:pre"> </span>一直按确定
</span><span style="white-space:pre"> </span>退出</span>:
<span style="white-space:pre"></span><pre name="code" class="html"><span style="white-space:pre"> </span># exit
2.安装与配置hadoop
1.下载hadoop2.5.2
2.安装
将hadoop的压缩包放到/usr/local文件夹下,然后解压
# tar xzf hadoop2.5.2.tar.gz
<span style="white-space:pre"> </span># mv hadoop2.5.2 hadoop
3.配置
1.配置~/.bashrc
配置该文件之前,我们要知道我们的jdk安装环境,上一节讲过jdk的配置,我们jdk的环境是 /usr/java/jdk1.7.0_75
# gedit ~/.bashrc
将下面的内容复制粘贴到该文件末尾:
将下面的内容复制粘贴到该文件末尾:
<span style="white-space:pre"> </span>#HADOOP VARIABLES START
<span style="white-space:pre"> </span>export JAVA_HOME=/usr/java/jdk1.7.0_75
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>export HADOOP_INSTALL=/usr/local/hadoop
<span style="white-space:pre"> </span>export PATH=$PATH:$HADOOP_INSTALL/bin
<span style="white-space:pre"> </span>export PATH=$PATH:$HADOOP_INSTALL/sbin
<span style="white-space:pre"> </span>export HADOOP_MAPRED_HOME=$HADOOP_INSTALL
<span style="white-space:pre"> </span>export HADOOP_COMMON_HOME=$HADOOP_INSTALL
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>export HADOOP_HDFS_HOME=$HADOOP_INSTALL
<span style="white-space:pre"> </span>export YARN_HOME=$HADOOP_INSTALL
<span style="white-space:pre"> </span>export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native
<span style="white-space:pre"> </span>export HADOOP_OPTS="-Djava.library.path=$HADOOP_INSTALL/lib"
<span style="white-space:pre"> </span>#HADOOP VARIABLES END
<span style="white-space:pre"> </span># source ~/.bashrc
使配置文件生效
2.配置/usr/local/hadoop/etc/hadoop/hadoop-env.sh
早起的hadoop版本中hadoop-env.sh可能不在/usr/local/hadoop/etc/hadoop下,在/usr/local/hadoop/configure中
用编辑器打开该文件:
<span style="white-space:pre"> </span># gedit /usr/local/hadoop/etc/hadoop/hadoop-env.sh
找到文件中的JAVA_HOME=${JAVA_HOME}一项,改为
JAVA_HOME=/usr/java/jdk1.7.0_75
保存退出
4.WordCount测试
至此hadoop单机模式完成,
在/usr/local/hadoop下新建文件夹:
<span style="white-space:pre"> </span># mkdir input
将README.txt拷贝到input下
<span style="white-space:pre"> </span># cp README.TXT input/
执行以下命令:
<span style="white-space:pre"> </span># hadoop jar share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-2.5.2-sources.jar org.apache.hadoop.examples.WordCount input output
等待程序运行完成,查看运行结果:
<span style="white-space:pre"> </span># cat output/*