![](https://csdnimg.cn/release/download_crawler_static/10486869/bg1.jpg)
构建
Hadoop
集群
-----------------------------------------------------------------------------------------------------------------------------------------
安装选项:
1. Apache tarballs
:
The Apache Hadoop project and related projects provide binary (and source) tarballs for each release.
2. Packages
:
RPM and Debian packages are available from the Apache Bigtop project http://bigtop.apache.org/
3. Hadoop cluster management tools
:
Cloudera Manager and Apache Ambari are examples of dedicated tools for installing and
managing a Hadoop cluster over its whole lifecycle. They provide a simple web UI,
and are the recommended way to set up a Hadoop cluster for most users and operators.
10.1
集群规范
(Cluster Specification)
-----------------------------------------------------------------------------------------------------------------------------------------
硬件:
-------------------------------------------------------------------------------------------------------------------------------------
a typical choice of machine for running an HDFS datanode and a YARN node manager in 2014 would have had the following specifications:
处理器:
Two hex/octo-core 3 GHz CPUs
内存:
64−512 GB ECC RAM[68]
存储器:
12−24 × 1−4 TB SATA disks
网络:
Gigabit Ethernet with link aggregation
Hadoop
一般使用多核
CPU
和多磁盘,以充分利用硬件的强大功能。
Master node scenarios
------------------------------------------------------------------------------------------------------------------------------------
根据集群的大小,运行
master daemon
由很多不同的配置:
the namenode, secondary namenode, resource manager, and history server
For a small cluster (on the order of 10 nodes), it is usually acceptable to run the namenode and the resource manager on
a single master machine (as long as at least one copy of the namenode ’s metadata is stored on a remote filesystem).
namenode
对内存要求较高,因为它要在内存中保持整个名称空间文件和块的元数据信息。
网络拓扑
(Network Topology)
------------------------------------------------------------------------------------------------------------------------------------
A common Hadoop cluster architecture consists of a two-level network topology
。
每个机架有
30-40
台服务器,内部用一台
10GB
交换机,向上连接一台核心交换机或路由器
(
至少
10GB
,或更大带宽
)
,使机架间互联。该架构的突出
特点是同一机架内部的节点之间的总带宽要远高于不同机架上节点间的带宽。
机架注意事项
(Rack awareness)
--------------------------------------------------------------------------------------------------------------------------------------
为了获得
Hadoop
最佳性能,配置
Hadoop
以让其了解网络拓扑状况极为重要。如果集群只有一个机架,就无须做什么,因为这是默认配置。然而,对于
多机架集群,需要将节点映射到机架。这允许
Hadoop
在节点上部署
MapReduce
任务时更优先选择机架内
(within-rack)
传输
(
拥有更多的可用带宽
)
而非
跨机架
(off-rack)
传输。
HDFS
也能够更智能地部署块复本以达到性能和弹性的平衡。
网络位置例如节点和机架表现在一棵树中,从而反映出位置间的网络距离
(network distance)
。
namenode
使用网络位置确定复本的放置位置,
MapReduce
调度器使用网络位置确定其
map
任务输入的最近复本。
示例:对于网络,机架拓扑描述为两个网络位置
———— /switch1/rack1
和
/switch1/rack2.
因为集群中只有一个顶级的
(top-level)
交换机,位置可以
简化为
/rack1
和
/rack2.
Hadoop
配置必须指定节点地址和网络位置的一个映射。这个映射由一个
Java
接口描述,
DNSToSwitchMapping:
public interface DNSToSwitchMapping {
public List<String> resolve(List<String> names);
}
names
参数是一个
IP
地址列表,返回值是一个对应的网络位置字符串列表。
net.topology.node.switch.mapping.impl
配置属性定义了
一个
DNSToSwitchMapping
接口实现
, namenode
和
resource manager
用于解析工作节点
(worker node)
的网络位置。
对于本例的网络,我们将
node1, node2, and node3
映射到
/rack1,
以及将
node4, node5, and node6
映射到
/rack2.
大多数安装不需要自己实现接口,然而,因为默认实现是
ScriptBasedMapping,
即运行一个用户定义的脚本来确定映射,脚本位置由属性:
net.topology.script.file.name
控制。脚本必须接受可变数量的参数,要映射的主机名或
IP
地址,并且必须将对应的网络位置发送到标准输出,空格分隔。
如果没有指定脚本位置,默认是将所有节点映射为一个网络位置,称为
/default-rack
10.2
集群的构建和安装
(Cluster Setup and Installation)
-----------------------------------------------------------------------------------------------------------------------------------------
1. Installing Java
:
Java 7
或更高版本
-------------------------------------------------------------------------------------------------------------------------------------
2. Creating Unix User Accounts
:
-------------------------------------------------------------------------------------------------------------------------------------
It’s good practice to create dedicated Unix user accounts to separate the Hadoop processes from each other, and from other services
running on the same machine. The HDFS, MapReduce, and YARN services are usually run as separate users, named hdfs, mapred, and yarn,
respectively. They all belong to the same hadoop group.
最佳实践是在同一台机器上,为
Hadoop
进程分别创建专用的
Unix
用户帐户,并与其他服务分开。
HDFS, MapReduce,
以及
YARN
通常作为不同的用户
运行,用户名分别为
hdfs, mapred, and yarn.
他们同属于一个
hadoop
用户组。
3.
安装
Hadoop (Installing Hadoop)
-------------------------------------------------------------------------------------------------------------------------------------
% cd /usr/local
% sudo tar xzf hadoop-x.y.z.tar.gz
同样,需要改变
Hadoop
文件的用户名和组:
% sudo chown -R hadoop:hadoop hadoop-x.y.z
It’s convenient to put the Hadoop binaries on the shell path too:
% export HADOOP_HOME=/usr/local/hadoop-x.y.z
% export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
4.
配置
SSH (Configuring SSH)
-------------------------------------------------------------------------------------------------------------------------------------
Hadoop
的控制脚本
(but not the daemons)
依靠
SSH
执行整体集群
(cluster-wide)
的操作。例如,停止和启动集群上所有
daemon
的脚本。注意,控制
脚本是可选的,整体集群的操作也可以通过其他机制执行,例如一个分布式脚本或专用的
Hadoop
管理应用程序。
为了无间断工作,
SSH
要设置为允许
hdfs
和
yarn
用户从集群任何机器上无密码登录。实现这个任务最简单的方法是生成一个
public/private
密钥对
并把它们放到一个
NFS
位置以在整个集群上共享。
首先,通过如下指令生成一个
RSA key
对。需要做两次,一次作为
hdfs
用户,一次作为
yarn
用户。
% ssh-keygen -t rsa -f ~/.ssh/id_rsa
纵然想要无密码登录,没有密码的密钥不认为是个好的实践,因此当提示时,应输入一个密码。使用
ssh-agent
来避免为每一个连接输入密码。
下一步,需要确保
public key
存在于集群上所有要连接机器的
~/.ssh/authorized_keys
文件中。如果用户的主目录存储在一个
NFS
系统上,
密钥可以通过输入如下指令跨集群共享
(first as hdfs and then as yarn)
:
% cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
如果用户主目录没有使用
NFS
共享,则
public key
需要通过其他方法共享,例如,
ssh-copy-id
。
Test that you can SSH from the master to a worker machine by making sure ssh-agent is running, and then run ssh-add to store your
passphrase. You should be able to SSH to a worker without entering the passphrase again.
5. Configuring Hadoop
-------------------------------------------------------------------------------------------------------------------------------------
6.
格式化
HDFS
文件系统
( Formatting the HDFS Filesystem )
-------------------------------------------------------------------------------------------------------------------------------------
在能够使用之前,一个崭新的
HDFS
安装需要被格式化。格式化过程通过创建存储目录
(storage directories)
和名称节点
(namenode)
的持久化数据