1、 软件下载
从官网http://apache.fayea.com/hadoop/common/ 下载hadoop
从Oracle官网下载
JDK
http://www.oracle.com/technetwork/java/javase/downloads/index.html(1.8.25)
hadoop-example的jar用来简单测试
http://www.java2s.com/Code/Jar/h/Downloadhadoopexamples111jar.htm
2、 硬件准备
准备3~4台机器
本人这次是准备了3台虚拟机。
1台master,2个slave
3、 操作步骤
a) 安装64位操作系统(如REHL 6.5)
b) 设置主机名字(便于统筹规划)
192.168.1.200 master
192.168.1.201 slave1
192.168.1.202 slave2
将IP解析复制到每个机器的/etc/hosts中。
c) 设置ssh无密码访问(实现主节点到所有从节点即可)
a) 各个节点运行ssh-keygen -t rsa ,然后将~/.ssh/id_rsa.pub 文件中的内容都加入到master节点中的~/.ssh/authorized_keys 文件中。
d) 安装JDK
解压JDK包如下:
tar zxvfjdk-8u25-linux-x64.gz
编辑配置文件
vi/etc/profile
加入如下:
JAVA_HOME=/opt/jdk
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$SCALA_HOME/bin:$PATH
exportJAVA_HOME CLASSPATH PATH
运行如下进行确认JDK安装
java-version
e) 安装Hadoop
a) 解压
tar -zxvfhadoop-2.6.0.tar.gz
b) 编辑配置文件
vi/etc/profile
HADOOP_HOME=/opt/hadoop
HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
PATH=$HADOOP_HOME/bin:$PATH
exportHADOOP_HOME HADOOP_CONF_DIR PATH
c) 配置文件生效
source/etc/profile
d) 修改core-site.xml
/opt/hadoop/etc/hadoop下的core-site.xml
如下:
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://master:9000</value>
<description>NameNode URI.</description>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131072</value>
<description>Size of read/write buffer used inSequenceFiles.</description>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/data/hadoop/tmp</value>
<description>A base for other temporary directories.</description>
</property>
</configuration>
e) 编辑hdfs-site.xml
如下:
<configuration>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>master:50090</value>
<description>The secondary namenode http server address andport.</description>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:///data/dfs/name</value>
<description>Path on the local filesystem where the NameNodestores the namespace and transactions logs persistently.</description>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:///data/dfs/data</value>
<description>Comma separated list of paths on the local filesystemof a DataNode where it should store its blocks.</description>
</property>
<property>
<name>dfs.namenode.checkpoint.dir</name>
<value>file:///data/dfs/namesecondary</value>
<description>Determines where on the local filesystem the DFSsecondary name node should store the temporary images to merge. If this is acomma-delimited list of directories then the image is replicated in all of thedirectories for redundancy.</description>
</property>
</configuration>
f) 编辑slaves文件
如下:
master
slave1
slave2
g) 启动hdfs
先格式化namenode
hdfs namenode –format
启动dfs
设置/opt/hadoop/etc/hadoop/hadoop-env.sh文件中的JAVA变量。
start-dfs.sh
查看进程
jps
主节点:[root@master sbin]# jps
2291 DataNode
2452SecondaryNameNode
2170 NameNode
2573 Jps
从节点:
[root@slave1.ssh]# jps
1841 DataNode
1917 Jps
h) 编辑yarn-site.xml
如下:
<configuration>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>master</value>
<description>The hostname of theRM.</description>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
<description>Shuffle service that needs to be set for Map Reduceapplications.</description>
</property>
</configuration>
i) 编辑mapred-site.xml
如下:
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
<description>Theruntime framework for executing MapReduce jobs. Can be one of local, classic oryarn.</description>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>master:10020</value>
<description>MapReduce JobHistoryServer IPC host:port</description>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>master:19888</value>
<description>MapReduce JobHistoryServer Web UI host:port</description>
</property>
</configuration>
j) 启动yarn资源管理
执行如下:
start-yarn.sh
执行jps进行查看。
完毕。
Jps查看
主节点:
[root@master sbin]# jps
2720 NodeManager
2291 DataNode
2452 SecondaryNameNode
2953 Jps
2170 NameNode
2621 ResourceManager
从节点:
[root@slave1 .ssh]# jps
1841 DataNode
2082 Jps
1958 NodeManager
4、 简单测试
如:在master运行如下命令:
#hadoop jar hadoop-examples-1.2.1.jar pi 1 10
该命令测试分布式计算性能,计算pi的值。第1个10指的是要运行10次map任务
第2个数字指的是每个map任务拆分多少个job.
可以通过
IE进行图形化观察
如下图1:
CentOS安装和配置Hadoop2.2.0 http://www.linuxidc.com/Linux/2014-01/94685.htm
Ubuntu 13.04上搭建Hadoop环境 http://www.linuxidc.com/Linux/2013-06/86106.htm
Ubuntu 12.10 +Hadoop 1.2.1版本集群配置 http://www.linuxidc.com/Linux/2013-09/90600.htm
Ubuntu上搭建Hadoop环境(单机模式+伪分布模式) http://www.linuxidc.com/Linux/2013-01/77681.htm
Ubuntu下Hadoop环境的配置 http://www.linuxidc.com/Linux/2012-11/74539.htm
单机版搭建Hadoop环境图文教程详解 http://www.linuxidc.com/Linux/2012-02/53927.htm
搭建Hadoop环境(在Winodws环境下用虚拟机虚拟两个Ubuntu系统进行搭建) http://www.linuxidc.com/Linux/2011-12/48894.htm
更多Hadoop相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-01/111258.htm