发布于 2014-12-09 09:04:23 | 511 次阅读 | 评论: 0 | 来源: PHPERZ
Hadoop分布式系统
一个分布式系统基础架构,由Apache基金会所开发。
用户可以在不了解分布式底层细节的情况下,开发分布式程序。充分利用集群的威力高速运算和存储。
本文为大家讲解的是在redhat下Hadoop的安装和部署,感兴趣的同学参考下.
一个分布式系统基础架构,由Apache基金会所开发。
用户可以在不了解分布式底层细节的情况下,开发分布式程序。充分利用集群的威力高速运算和存储。
系统环境:Red Hat Linux 6.4 32
Hadoop版本:hadoop-2.5.2
JDK版本:jdk-8u25-linux-i586.rpm
下载hadoop-2.5.2:
wget http://mirror.bit.edu.cn/apache/hadoop/common/stable2/hadoop-2.5.2.tar.gz
下载JDK:jdk-8u25-linux-i586.rpm
http://www.oracle.com/technetwork/java/javase/index.html
总体的流程如下:
1、实现ssh无密码验证配置
2、安装jdk,并配好环境变量
3、安装与配置Hadoop
4、格式化与启动
5、验证是否启动
利用 : ssh-kengen –t rsa 命令产生公钥,将个主机之间的公钥,相互拷贝到authorized_keys文件内。
安装好后,用java -version 检验下
配置环境变量:
###set java_env
export JAVA_HOME=/usr/java/jdk1.8.0_25/
export JRE_HOME=/usr/java/jdk1.8.0_25/jre
export CLASS_PATH=.:$CLASS_PATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
###set hadoop_env
export HADOOP_HOME=/home/zhang/hadoop-2.5.2
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_YARN_HOME=$HADOOP_HOME
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HADOOP_HOME/lib
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS=\"-Djava.library.path=$HADOOP_HOME/lib\"
解压Hadoop 到 自己的hadoop 目录
配置相关的配置文件
2.5.x版本的配置文件在:$Hadoop_Home/etc/hadoop 目录下
2.X 版本较 1.X版本改动很大,主要是用Hadoop MapReduceV2(Yarn) 框架代替了一代的架构,其中JobTracker 和 TaskTracker 不见了,取而代之的是 ResourceManager, ApplicationMaster 与 NodeManager 三个部分,而具体的配置文件位置与内容也都有了相应变化,具体的可参考文献:http://www.ibm.com/developerworks/cn /opensource/os-cn-hadoop-yarn/
(1)hadoop/etc/hadoop/hadoop-env.sh 与 hadoop/etc/hadoop/yarn-env.sh来配置两个文件里的JAVA_HOME
(2)etc/hadoop/core-site.xml,配置为:
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/zhang/hadoop-2.5.2/tmp</value>
<description>A base for other temporary directories.</description>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://namenode:9000</value>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131072</value>
</property>
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>namenode</value>
</property>
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
</configuration>
(3)etc/hadoop /hdfs-site.xml,配置为: (注意:这里需要自己手动用mkdir创建name和data文件夹,具体位置也可以自己选择,其中dfs.replication的值建议配置为与分布 式 cluster 中实际的 DataNode 主机数一致。)
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>/home/zhang/hadoop-2.5.2/hdfs/name</value>
<final>true</final>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/home/zhang/hadoop-2.5.2/hdfs/data</value>
<final>true</final>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
</configuration>
(4)etc/hadoop/mapred-site.xml,配置为:
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>Yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>namenode:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>namenode:19888</value>
</property>
<property>
<name>mapreduce.jobhistory.intermediate-done-dir</name>
<value>/mr-history/tmp</value>
</property>
<property>
<name>mapreduce.jobhistory.done-dir</name>
<value>/mr-history/done</value>
</property>
</configuration>
(5)etc/hadoop/yarn-site.xml对yarn进行配置:
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>Yarn.nodemanager.aux-services</name>
<value>mapreduce.shuffle</value>
</property>
<property>
<name>Yarn.resourcemanager.address</name>
<value>namenode:18040</value>
</property>
<property>
<name>Yarn.resourcemanager.scheduler.address</name>
<value>namenode:18030</value>
</property>
<property>
<name>Yarn.resourcemanager.resource-tracker.address</name>
<value>namenode:18025</value>
</property>
<property>
<name>Yarn.resourcemanager.admin.address</name>
<value>namenode:18041</value>
</property>
<property>
<name>Yarn.resourcemanager.webapp.address</name>
<value>namenode:8088</value>
</property>
<property>
<name>Yarn.nodemanager.local-dirs</name>
<value>/home/zhang/hadoop-2.5.2/mynode/my</value>
</property>
<property>
<name>Yarn.nodemanager.log-dirs</name>
<value>/home/zhang/hadoop-2.5.2/mynode/logs</value>
</property>
<property>
<name>Yarn.nodemanager.log.retain-seconds</name>
<value>10800</value>
</property>
<property>
<name>Yarn.nodemanager.remote-app-log-dir</name>
<value>/logs</value>
</property>
<property>
<name>Yarn.nodemanager.remote-app-log-dir-suffix</name>
<value>logs</value>
</property>
<property>
<name>Yarn.log-aggregation.retain-seconds</name>
<value>-1</value>
</property>
<property>
<name>Yarn.log-aggregation.retain-check-interval-seconds</name>
<value>-1</value>
</property>
</configuration>
(1)用scp 命令将hadoop文件夹拷贝到所有的节点机器相同路径上。
(2)验证一下SSH 无密码访问已经没有问题了
(3)关闭防火墙
如果不关闭的话可能造成,无法访问端口的问题。不关闭防火墙也可以将对应的相关端口打开比如 namenode上:9000端口
方法:http://blog.itpub.net/28929558/viewspace-1353996/
(4)启动测试
格式化:namdenode
hadoop/bin/hadoop namenode -format
查看打印信息的倒数第三行:Storage directory ~/hadoop-2.5.2/hdfs/name has been successfully formatted
则说明成功了!
启动 hdfs :
sbin/start-dfs.sh
jps 查看 namenode 上: NameNode SecondaryNameNode
datanode shang : DataNode
启动 yarn :start-yarn.sh
jps 查看 namenode 上: NameNode SecondaryNameNode ResourceManager
datanode shang : DataNode NodeManager
用 hdfs dfsadmin -report 检验一下
9189 NameNode
[zhang@namenode sbin]$ hdfs dfsadmin -report
14/12/01 23:19:15 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Configured Capacity: 8177262592 (7.62 GB)
Present Capacity: 4473057280 (4.17 GB)
DFS Remaining: 4473032704 (4.17 GB)
DFS Used: 24576 (24 KB)
DFS Used%: 0.00%
Under replicated blocks: 0
Blocks with corrupt replicas: 0
Missing blocks: 0
-------------------------------------------------
Live datanodes (1):
Name: 10.0.128.124:50010 (datanode01)
Hostname: datanode01
Decommission Status : Normal
Configured Capacity: 8177262592 (7.62 GB)
DFS Used: 24576 (24 KB)
Non DFS Used: 3704205312 (3.45 GB)
DFS Remaining: 4473032704 (4.17 GB)
DFS Used%: 0.00%
DFS Remaining%: 54.70%
Configured Cache Capacity: 0 (0 B)
Cache Used: 0 (0 B)
Cache Remaining: 0 (0 B)
Cache Used%: 100.00%
Cache Remaining%: 0.00%
Xceivers: 1
Last contact: Mon Dec 01 23:19:15 PST 2014
测试放入数据文件,并查看:
[zhang@namenode sbin]$ hadoop fs -put ../../input/ /input
14/12/02 00:18:01 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable[zhang@namenode sbin]$ hadoop fs -cat /input/test.txt
14/12/02 00:18:35 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
hello word !
验证完毕!