Hadoop-2.6.0环境搭建精简极致指导
HopToad
欢迎关注微信公众号:HopToad
转载请标出处
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: