hadoop系列文档1-hadoop安装教程

一.前言

本教程旨在在Linux系统中安装7节点Hadoop-2.7.1分布式集群。

在安装之前,你需要确保已经下载如下安装软件包:

1:Linux 操作系统 –Red hat6.4 64bit(命令cat /etc/issue查看系统信息)
2:jdk-7u79-linux-x64.gz
3:hadoop-2.7.1.tar.gz

二.安装环境


1.   安装JDK

解压

tar zxvf jdk-7u79-linux-x64.gz

设置环境变量

vim ~/.bash_profile
#jdk
exportJAVA_HOME=/usr/local/hadoop/jdk1.7.0_79

立即生效配置

source ~/.bash_profile

检测环境配置配置成功

java -version

然后每个节点都需要配置类似的配置

2.   设置hosts

vim /etc/hosts




3.设置ssh

确认已经安装ssh


如出现如下则表示已经安装好ssh


如无出现则需要自行安装好ssh

 

详细可以参考官网单节点配置

http://hadoop.apache.org/docs/r2.7.1/hadoop-project-dist/hadoop-common/SingleCluster.html

首先

ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa

然后把公钥信息添加到authorized_keys文件中

cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

验证本地ssh 登录

ssh localhost

如出现如下则表示本地ssh免密码登陆已经配置成功

 

我们需要在集群各节点间实现ssh免密码登陆

ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa

如下图表示已经安装成功

 


成功安装后,赋予ssh权限

chmod 700 ~/.ssh

成功安装后会在ssh路径下有2个文件,如下图所示

然后我们需要把安装在Master上的公钥信息复制到各个节点,命令如下

scp ~/.ssh/authorized_keys  root@hadoopslave1:~/.ssh/

复制文件的时候,这里还是会要求输入密码,这是正常的。

复制后,我们会再slave1的ssh目录中看到如下面所示:

 

然后我们需要把子节点slave1中的公钥信息.pub添加到我们的authorized_keys文件中

cat ~/.ssh/id_dsa.pub >>~/.ssh/authorized_keys

这时候,我们就已经完成Master对Slave1的免密码登陆,我们到Master验证一下

 

其他几点节点也是类似的的操作。

最后效果如下图所示

三.安装hadoop-2.7.1



1 解压hadoop-2.7.1

tar zxvf  hadoop-2.7.1.tar.gz

2 在/usr/local/hadoop/目录下,建立tmp、hdfs/name、hdfs/data目录

mkdir /usr/local/hadoop/tmp 
mkdir /usr/local/hadoop/hdfs 
mkdir /usr/local/hadoop/hdfs/data 
mkdir /usr/local/hadoop/hdfs/name

3 设置hadoop-2.7.1环境变量

vi ~/.bash_profile

4 配置hadoop2.7.1的配置文件

 core-site.xml

<configuration>
    <property>
    <name>fs.defaultFS</name>
    <value>hdfs://master:9000</value>
    </property>
     <property>
    <name>hadoop.tmp.dir</name>
    <value>/usr/local/hadoop/tmp</value>
    </property>
    <property>
    <name>io.file.buffer.size</name>
    <value>4096</value>
    </property>
</configuration>

hdfs-site.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
  <property>
      <name>dfs.replication</name>
      <value>2</value>
  </property>
  <property>
      <name>dfs.namenode.name.dir</name>
      <value>file:///usr/local/hadoop/hdfs/name</value>
  </property>
  <property>
      <name>dfs.datanode.data.dir</name>
      <value>file:///usr/local/hadoop/hdfs/data</value>
  </property>
  <property>
      <name>dfs.nameservices</name>
      <value>master</value>
  </property>

  <property>
      <name>dfs.namenode.secondary.http-address</name>
      <value>master:50090</value>
  </property>
  <property>
      <name>dfs.webhdfs.enabled</name>
      <value>true</value>
  </property>
  <property>
        <name>dfs.permissions</name>
        <value>false</value>
    </property>
</configuration>

mapred-site.xml

<configuration>
  <property>
     <name>mapreduce.framework.name</name>
     <value>yarn</value>
     <final>true</final>
  </property>
  <property>
     <name>mapreduce.jobtracker.http.address</name>
     <value>master:50030</value>
  </property>
  <property>
     <name>mapreduce.jobhistory.address</name>
     <value>master:10020</value>
  </property>
  <property>
     <name>mapreduce.jobhistory.webapp.address</name>
     <value>master:19888</value>
  </property> 
  <property>
     <name>mapred.job.tracker</name>
     <value>http://master:9001</value>
  </property> 
</configuration>

yarn-site.xml

<configuration>
<!-- Site specific YARN configuration properties -->
  <property>
     <name>yarn.resourcemanager.hostname</name>
     <value>master</value>
  </property>
  <property>
     <name>yarn.nodemanager.aux-services</name>
     <value>mapreduce_shuffle</value>
  </property>
  <property>
     <name>yarn.resourcemanager.address</name>
     <value>master:8032</value>
  </property>
  <property>
     <name>yarn.resourcemanager.scheduler.address</name>
     <value>master:8030</value>
  </property>
  <property>
     <name>yarn.resourcemanager.resource-tracker.address</name>
     <value>master:8031</value>
  </property>
  <property>
     <name>yarn.resourcemanager.admin.address</name>
     <value>master:8033</value>
  </property>
  <property>
     <name>yarn.resourcemanager.webapp.address</name>
     <value>master:8088</value>
  </property>
</configuration>

slaves

你的节点的hostname

hadoop-env.sh

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Set Hadoop-specific environment variables here.

# The only required environment variable is JAVA_HOME.  All others are
# optional.  When running a distributed configuration it is best to
# set JAVA_HOME in this file, so that it is correctly defined on
# remote nodes.

# The java implementation to use.
export JAVA_HOME=/usr/local/jdk/jdk1.7.0_79

# The jsvc implementation to use. Jsvc is required to run secure datanodes
# that bind to privileged ports to provide authentication of data transfer
# protocol.  Jsvc is not required if SASL is configured for authentication of
# data transfer protocol using non-privileged ports.
#export JSVC_HOME=${JSVC_HOME}

export HADOOP_CONF_DIR=${HADOOP_CONF_DIR:-"/etc/hadoop"}

# Extra Java CLASSPATH elements.  Automatically insert capacity-scheduler.
for f in $HADOOP_HOME/contrib/capacity-scheduler/*.jar; do
  if [ "$HADOOP_CLASSPATH" ]; then
    export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$f
  else
    export HADOOP_CLASSPATH=$f
  fi
done

# The maximum amount of heap to use, in MB. Default is 1000.
#export HADOOP_HEAPSIZE=
#export HADOOP_NAMENODE_INIT_HEAPSIZE=""

# Extra Java runtime options.  Empty by default.
export HADOOP_OPTS="$HADOOP_OPTS -Djava.net.preferIPv4Stack=true"

# Command specific options appended to HADOOP_OPTS when specified
export HADOOP_NAMENODE_OPTS="-Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_NAMENODE_OPTS"
export HADOOP_DATANODE_OPTS="-Dhadoop.security.logger=ERROR,RFAS $HADOOP_DATANODE_OPTS"

export HADOOP_SECONDARYNAMENODE_OPTS="-Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_SECONDARYNAMENODE_OPTS"

export HADOOP_NFS3_OPTS="$HADOOP_NFS3_OPTS"
export HADOOP_PORTMAP_OPTS="-Xmx512m $HADOOP_PORTMAP_OPTS"

# The following applies to multiple commands (fs, dfs, fsck, distcp etc)
export HADOOP_CLIENT_OPTS="-Xmx512m $HADOOP_CLIENT_OPTS"
#HADOOP_JAVA_PLATFORM_OPTS="-XX:-UsePerfData $HADOOP_JAVA_PLATFORM_OPTS"

# On secure datanodes, user to run the datanode as after dropping privileges.
# This **MUST** be uncommented to enable secure HDFS if using privileged ports
# to provide authentication of data transfer protocol.  This **MUST NOT** be
# defined if SASL is configured for authentication of data transfer protocol
# using non-privileged ports.
export HADOOP_SECURE_DN_USER=${HADOOP_SECURE_DN_USER}

# Where log files are stored.  $HADOOP_HOME/logs by default.
#export HADOOP_LOG_DIR=${HADOOP_LOG_DIR}/$USER

# Where log files are stored in the secure data environment.
export HADOOP_SECURE_DN_LOG_DIR=${HADOOP_LOG_DIR}/${HADOOP_HDFS_USER}

###
# HDFS Mover specific parameters
###
# Specify the JVM options to be used when starting the HDFS Mover.
# These options will be appended to the options specified as HADOOP_OPTS
# and therefore may override any similar flags set in HADOOP_OPTS
#
# export HADOOP_MOVER_OPTS=""

###
# Advanced Users Only!
###

# The directory where pid files are stored. /tmp by default.
# NOTE: this should be set to a directory that can only be written to by 
#       the user that will run the hadoop daemons.  Otherwise there is the
#       potential for a symlink attack.
export HADOOP_PID_DIR=${HADOOP_PID_DIR}
export HADOOP_SECURE_DN_PID_DIR=${HADOOP_PID_DIR}

# A string representing this instance of hadoop. $USER by default.
export HADOOP_IDENT_STRING=$USER


以上配置文件都在目录下

/usr/local/hadoop/hadoop-2.7.1/etc/hadoop


3.5.hadoop 启动


1)格式化namenode

$ bin/hdfs namenode –format

如何格式化失败,请关闭防火墙

service iptables stop

更多信息参考

http://flychao88.iteye.com/blog/1950081

 

2)启动NameNode 和 DataNode 守护进程

$ sbin/start-dfs.sh

3)启动ResourceManager 和 NodeManager 守护进程

$ sbin/start-yarn.sh

成功启动后,你将会看到以下进程


查看hadoopmaster进程 jps


查看子节点hadoopslave 进程jps

 

我们还可以查看web网页

查看Master的50070端口,可以看到hdfs文件系统的概要,如下图

 

 

 查看Master的8088端口,可以看到yarn job管理器的概要,如下图

 


至此,我们的hadoop2.7.1集群已成功安装完毕!

 

四.一些问题


1.32位和64位

因为hadoop官网上的hadoop程序都是32位(从2.5.2开始官网已有64bit),所有要编译成64位。下面介绍具体的编译方法。

如何查看自己的hadoop是什么版本的:

http://www.aboutyun.com/thread-12796-1-1.html

我们看到我们的版本已经是64bit了,所以就无需自己编译了。

如果我们用的版本是低于2.5.2的,那么我们需要自己手工转化成64bit的,以下是转化的教程。

http://www.aboutyun.com/thread-12796-1-1.html

猜你喜欢

转载自blog.csdn.net/u010237107/article/details/50755879