本文档介绍如何安装和配置Hadoop集群,从几个节点到拥有数千个节点的超大规模集群。要体验Hadoop,您可以先在单台机器上安装(参见Single Node Setup)。
本文档不涵盖高级主题,例如高可用性。
重要: 所有生产环境的Hadoop集群都使用Kerberos来验证调用者身份,保护HDFS数据访问安全,并限制对计算服务(YARN等)的访问。
这些说明不涉及与任何Kerberos服务的集成 - 每个搭建生产集群的人都应将连接到其组织的Kerberos基础设施作为部署的关键部分。
有关如何保护集群安全的详细信息,请参阅Security。
安装Hadoop集群通常需要在集群所有机器上解压软件包,或根据操作系统通过适当的包管理系统进行安装。关键是要将硬件按功能进行划分。
通常,集群中的一台机器被指定为NameNode,另一台机器专门作为ResourceManager。这些是主节点。其他服务(如Web应用代理服务器和MapReduce作业历史服务器)通常根据负载情况,在专用硬件或共享基础设施上运行。
集群中的其余机器同时充当DataNode和NodeManager角色。这些就是工作节点。
Hadoop的Java配置由两类重要的配置文件驱动:
只读默认配置 - core-default.xml
, hdfs-default.xml
, yarn-default.xml
和 mapred-default.xml
。
站点特定配置 - etc/hadoop/core-site.xml
, etc/hadoop/hdfs-site.xml
, etc/hadoop/yarn-site.xml
和 etc/hadoop/mapred-site.xml
。
此外,您可以通过在etc/hadoop/hadoop-env.sh
和etc/hadoop/yarn-env.sh
中设置特定站点的值来控制发行版bin/目录中的Hadoop脚本。
要配置Hadoop集群,您需要配置Hadoop守护进程运行的环境
以及Hadoop守护进程的配置参数
。
HDFS守护进程包括NameNode、SecondaryNameNode和DataNode。YARN守护进程包括ResourceManager、NodeManager和WebAppProxy。如果使用MapReduce,则MapReduce作业历史服务器也会运行。对于大型安装环境,这些守护进程通常运行在不同的主机上。
管理员应使用etc/hadoop/hadoop-env.sh
脚本,并可选择性地使用etc/hadoop/mapred-env.sh
和etc/hadoop/yarn-env.sh
脚本来对Hadoop守护进程的运行环境进行站点特定的定制。
至少,您必须指定JAVA_HOME
以确保其在每个远程节点上正确定义。
管理员可以使用下表中显示的配置选项来配置各个守护进程:
守护进程 | 环境变量 |
---|---|
NameNode | HDFS_NAMENODE_OPTS |
DataNode | HDFS_DATANODE_OPTS |
Secondary NameNode | HDFS_SECONDARYNAMENODE_OPTS |
ResourceManager | YARN_RESOURCEMANAGER_OPTS |
NodeManager | YARN_NODEMANAGER_OPTS |
WebAppProxy | YARN_PROXYSERVER_OPTS |
Map Reduce 作业历史服务器 | MAPRED_HISTORYSERVER_OPTS |
例如,要将Namenode配置为使用parallelGC和4GB Java堆,应在hadoop-env.sh中添加以下语句:
export HDFS_NAMENODE_OPTS="-XX:+UseParallelGC -Xmx4g"
其他示例请参见 etc/hadoop/hadoop-env.sh
。
其他可自定义的有用配置参数包括:
HADOOP_PID_DIR
- 存储守护进程ID文件的目录。HADOOP_LOG_DIR
- 守护进程日志文件的存储目录。如果日志文件不存在,将会自动创建。HADOOP_HEAPSIZE_MAX
- Java堆内存的最大使用量。支持JVM支持的所有单位。如果未指定单位,则默认以兆字节为单位。默认情况下,Hadoop会让JVM自行决定使用量。该值可以通过上面列出的相应_OPTS
变量在每个守护进程基础上进行覆盖。例如,设置HADOOP_HEAPSIZE_MAX=1g
和HADOOP_NAMENODE_OPTS="-Xmx5g"
将为NameNode配置5GB的堆内存。在大多数情况下,您应该指定HADOOP_PID_DIR
和HADOOP_LOG_DIR
目录,确保只有运行hadoop守护进程的用户才有写入权限。否则可能存在符号链接攻击的风险。
通常也会在系统级的shell环境配置中设置HADOOP_HOME
。例如,在/etc/profile.d
目录下的一个简单脚本:
HADOOP_HOME=/path/to/hadoop export HADOOP_HOME
本节介绍需要在给定配置文件中指定的重要参数:
etc/hadoop/core-site.xml
参数 | 值 | 备注 |
---|---|---|
fs.defaultFS |
NameNode URI | hdfs://host:port/ |
io.file.buffer.size |
131072 | Size of read/write buffer used in SequenceFiles. |
etc/hadoop/hdfs-site.xml
NameNode的配置:
参数 | 值 | 备注 |
---|---|---|
dfs.namenode.name.dir |
Path on the local filesystem where the NameNode stores the namespace and transactions logs persistently. | If this is a comma-delimited list of directories then the name table is replicated in all of the directories, for redundancy. |
dfs.hosts / dfs.hosts.exclude |
List of permitted/excluded DataNodes. | If necessary, use these files to control the list of allowable datanodes. |
dfs.blocksize |
268435456 | HDFS blocksize of 256MB for large file-systems. |
dfs.namenode.handler.count |
100 | More NameNode server threads to handle RPCs from large number of DataNodes. |
参数 | 值 | 备注 |
---|---|---|
dfs.datanode.data.dir |
Comma separated list of paths on the local filesystem of a DataNode where it should store its blocks. |
If this is a comma-delimited list of directories, then data will be stored in all named directories, typically on different devices. |
etc/hadoop/yarn-site.xml
ResourceManager 和 NodeManager 的配置:
参数 | 值 | 备注 |
---|---|---|
yarn.acl.enable |
true / false |
Enable ACLs? Defaults to false. |
yarn.admin.acl |
Admin ACL | ACL to set admins on the cluster. ACLs are of for comma-separated-usersspacecomma-separated-groups. Defaults to special value of * which means anyone. Special value of just space means no one has access. |
yarn.log-aggregation-enable |
false | Configuration to enable or disable log aggregation |
参数 | 值 | 备注 |
---|---|---|
yarn.resourcemanager.address |
ResourceManager host:port for clients to submit jobs. |
host:port If set, overrides the hostname set in yarn.resourcemanager.hostname . |
yarn.resourcemanager.scheduler.address |
ResourceManager host:port for ApplicationMasters to talk to Scheduler to obtain resources. |
host:port If set, overrides the hostname set in yarn.resourcemanager.hostname . |
yarn.resourcemanager.resource-tracker.address |
ResourceManager host:port for NodeManagers. |
host:port If set, overrides the hostname set in yarn.resourcemanager.hostname . |
yarn.resourcemanager.admin.address |
ResourceManager host:port for administrative commands. |
host:port If set, overrides the hostname set in yarn.resourcemanager.hostname . |
yarn.resourcemanager.webapp.address |
ResourceManager web-ui host:port. |
host:port If set, overrides the hostname set in yarn.resourcemanager.hostname . |
yarn.resourcemanager.hostname |
ResourceManager host. |
host Single hostname that can be set in place of setting all yarn.resourcemanager*address resources. Results in default ports for ResourceManager components. |
yarn.resourcemanager.scheduler.class |
ResourceManager Scheduler class. |
CapacityScheduler (recommended), FairScheduler (also recommended), or FifoScheduler . Use a fully qualified class name, e.g., org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler . |
yarn.scheduler.minimum-allocation-mb |
Minimum limit of memory to allocate to each container request at the Resource Manager . |
In MBs |
yarn.scheduler.maximum-allocation-mb |
Maximum limit of memory to allocate to each container request at the Resource Manager . |
In MBs |
yarn.resourcemanager.nodes.include-path / yarn.resourcemanager.nodes.exclude-path |
List of permitted/excluded NodeManagers. | If necessary, use these files to control the list of allowable NodeManagers. |
参数 | 值 | 备注 |
---|---|---|
yarn.nodemanager.resource.memory-mb |
Resource i.e. available physical memory, in MB, for given NodeManager |
Defines total available resources on the NodeManager to be made available to running containers |
yarn.nodemanager.vmem-pmem-ratio |
Maximum ratio by which virtual memory usage of tasks may exceed physical memory | The virtual memory usage of each task may exceed its physical memory limit by this ratio. The total amount of virtual memory used by tasks on the NodeManager may exceed its physical memory usage by this ratio. |
yarn.nodemanager.local-dirs |
Comma-separated list of paths on the local filesystem where intermediate data is written. | Multiple paths help spread disk i/o. |
yarn.nodemanager.log-dirs |
Comma-separated list of paths on the local filesystem where logs are written. | Multiple paths help spread disk i/o. |
yarn.nodemanager.log.retain-seconds |
10800 | Default time (in seconds) to retain log files on the NodeManager Only applicable if log-aggregation is disabled. |
yarn.nodemanager.remote-app-log-dir |
/logs | HDFS directory where the application logs are moved on application completion. Need to set appropriate permissions. Only applicable if log-aggregation is enabled. |
yarn.nodemanager.remote-app-log-dir-suffix |
logs | Suffix appended to the remote log dir. Logs will be aggregated to ${yarn.nodemanager.remote-app-log-dir}/${user}/${thisParam} Only applicable if log-aggregation is enabled. |
yarn.nodemanager.aux-services |
mapreduce_shuffle | Shuffle service that needs to be set for Map Reduce applications. |
yarn.nodemanager.env-whitelist |
Environment properties to be inherited by containers from NodeManagers | For mapreduce application in addition to the default values HADOOP_MAPRED_HOME should to be added. Property value should JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_HOME,PATH,LANG,TZ,HADOOP_MAPRED_HOME |
参数 | 值 | 备注 |
---|---|---|
yarn.log-aggregation.retain-seconds |
-1 | How long to keep aggregation logs before deleting them. -1 disables. Be careful, set this too small and you will spam the name node. |
yarn.log-aggregation.retain-check-interval-seconds |
-1 | Time between checks for aggregated log retention. If set to 0 or a negative value then the value is computed as one-tenth of the aggregated log retention time. Be careful, set this too small and you will spam the name node. |
etc/hadoop/mapred-site.xml
MapReduce应用程序的配置:
参数 | 值 | 备注 |
---|---|---|
mapreduce.framework.name |
yarn | Execution framework set to Hadoop YARN. |
mapreduce.map.memory.mb |
1536 | Larger resource limit for maps. |
mapreduce.map.java.opts |
-Xmx1024M | Larger heap-size for child jvms of maps. |
mapreduce.reduce.memory.mb |
3072 | Larger resource limit for reduces. |
mapreduce.reduce.java.opts |
-Xmx2560M | Larger heap-size for child jvms of reduces. |
mapreduce.task.io.sort.mb |
512 | Higher memory-limit while sorting data for efficiency. |
mapreduce.task.io.sort.factor |
100 | More streams merged at once while sorting files. |
mapreduce.reduce.shuffle.parallelcopies |
50 | Higher number of parallel copies run by reduces to fetch outputs from very large number of maps. |
参数 | 值 | 备注 |
---|---|---|
mapreduce.jobhistory.address |
MapReduce JobHistory Server host:port | Default port is 10020. |
mapreduce.jobhistory.webapp.address |
MapReduce JobHistory Server Web UI host:port | Default port is 19888. |
mapreduce.jobhistory.intermediate-done-dir |
/mr-history/tmp | Directory where history files are written by MapReduce jobs. |
mapreduce.jobhistory.done-dir |
/mr-history/done | Directory where history files are managed by the MR JobHistory Server. |
Hadoop提供了一种机制,允许管理员配置NodeManager定期运行管理员提供的脚本来判断节点是否健康。
管理员可以通过在脚本中执行任意自选的检查来确定节点是否处于健康状态。如果脚本检测到节点处于不健康状态,则必须向标准输出打印一行以字符串ERROR开头的内容。NodeManager会定期运行该脚本并检查其输出。如上述情况,若脚本输出包含ERROR字符串,则该节点状态将被报告为unhealthy
,并被ResourceManager列入黑名单。此后将不再向该节点分配任何任务。不过NodeManager会继续运行该脚本,因此当节点恢复健康时,它将自动从ResourceManager的黑名单中移除。管理员可以在ResourceManager的Web界面中查看节点健康状况及不健康时的脚本输出信息。节点自健康状态以来的持续时间也会显示在Web界面上。
以下参数可用于控制在etc/hadoop/yarn-site.xml
中的节点健康监控脚本。
参数 | 值 | 备注 |
---|---|---|
yarn.nodemanager.health-checker.script.path |
Node health script | Script to check for node’s health status. |
yarn.nodemanager.health-checker.script.opts |
Node health script options | Options for script to check for node’s health status. |
yarn.nodemanager.health-checker.interval-ms |
Node health script interval | Time interval for running health script. |
yarn.nodemanager.health-checker.script.timeout-ms |
Node health script timeout interval | Timeout for health script execution. |
健康检查脚本不应仅因部分本地磁盘损坏就报ERROR。NodeManager能够定期检查本地磁盘的健康状况(具体检查nodemanager-local-dirs和nodemanager-log-dirs),当损坏目录数量达到配置属性yarn.nodemanager.disk-health-checker.min-healthy-disks设定的阈值时,整个节点会被标记为不健康,并将此信息同时发送给资源管理器。启动盘要么做了RAID冗余,要么其故障会由健康检查脚本识别。
在您的etc/hadoop/workers
文件中列出所有工作节点的主机名或IP地址,每行一个。辅助脚本(如下所述)将使用etc/hadoop/workers
文件同时在多台主机上运行命令。该文件不用于任何基于Java的Hadoop配置。要使用此功能,必须为运行Hadoop的账户建立ssh信任(通过无密码ssh或其他方式,如Kerberos)。
许多Hadoop组件具备机架感知能力,并利用网络拓扑结构来提升性能与安全性。Hadoop守护进程通过调用管理员配置的模块来获取集群中工作节点的机架信息。详情请参阅Rack Awareness文档获取具体说明。
强烈建议在启动HDFS前配置机架感知。
Hadoop通过Apache Commons Logging框架使用Apache log4j进行日志记录。编辑etc/hadoop/log4j.properties
文件可自定义Hadoop守护进程的日志配置(如日志格式等)。
完成所有必要的配置后,将文件分发到所有机器的HADOOP_CONF_DIR
目录。这个目录在所有机器上应该是相同的。
通常建议将HDFS和YARN作为不同的用户运行。在大多数安装中,HDFS进程以'hdfs'用户执行,而YARN通常使用'yarn'账户。
要启动Hadoop集群,您需要同时启动HDFS和YARN集群。
首次启动HDFS时,必须进行格式化。将新的分布式文件系统格式化为hdfs:
[hdfs]$ $HADOOP_HOME/bin/hdfs namenode -format
在指定节点上以hdfs用户身份运行以下命令启动HDFS NameNode:
[hdfs]$ $HADOOP_HOME/bin/hdfs --daemon start namenode
在每个指定节点上以hdfs用户身份运行以下命令启动HDFS DataNode:
[hdfs]$ $HADOOP_HOME/bin/hdfs --daemon start datanode
如果配置了etc/hadoop/workers
和SSH可信访问(参见单节点设置),则可以使用实用脚本启动所有HDFS进程。以hdfs用户身份执行:
[hdfs]$ $HADOOP_HOME/sbin/start-dfs.sh
使用以下命令启动YARN,在指定的ResourceManager上以yarn用户身份运行:
[yarn]$ $HADOOP_HOME/bin/yarn --daemon start resourcemanager
在每个指定主机上以yarn用户身份运行脚本来启动NodeManager:
[yarn]$ $HADOOP_HOME/bin/yarn --daemon start nodemanager
启动一个独立的WebAppProxy服务器。在WebAppProxy服务器上以yarn用户身份运行。如果使用多台服务器进行负载均衡,则应在每台服务器上运行:
[yarn]$ $HADOOP_HOME/bin/yarn --daemon start proxyserver
如果配置了etc/hadoop/workers
和SSH可信访问(参见单节点设置),则可以使用实用脚本启动所有YARN进程。以yarn用户身份:
[yarn]$ $HADOOP_HOME/sbin/start-yarn.sh
使用以下命令启动MapReduce JobHistory服务器,在指定的服务器上以mapred用户身份运行:
[mapred]$ $HADOOP_HOME/bin/mapred --daemon start historyserver
使用以下命令停止NameNode,在指定的NameNode上以hdfs用户身份运行:
[hdfs]$ $HADOOP_HOME/bin/hdfs --daemon stop namenode
运行脚本来停止一个作为 hdfs 的 DataNode:
[hdfs]$ $HADOOP_HOME/bin/hdfs --daemon stop datanode
如果配置了etc/hadoop/workers
和ssh可信访问(参见单节点设置),则可以使用实用脚本停止所有HDFS进程。以hdfs用户身份执行:
[hdfs]$ $HADOOP_HOME/sbin/stop-dfs.sh
使用以下命令停止ResourceManager,在指定的ResourceManager上以yarn用户身份运行:
[yarn]$ $HADOOP_HOME/bin/yarn --daemon stop resourcemanager
以yarn用户身份运行脚本来停止工作节点上的NodeManager:
[yarn]$ $HADOOP_HOME/bin/yarn --daemon stop nodemanager
如果配置了etc/hadoop/workers
和SSH可信访问(参见单节点设置),则可以使用实用脚本停止所有YARN进程。以yarn用户身份执行:
[yarn]$ $HADOOP_HOME/sbin/stop-yarn.sh
停止WebAppProxy服务器。在WebAppProxy服务器上以yarn用户身份运行。如果使用了多台服务器进行负载均衡,则应在每台服务器上运行此命令:
[yarn]$ $HADOOP_HOME/bin/yarn stop proxyserver
使用以下命令停止MapReduce JobHistory Server,在指定的服务器上以mapred用户身份运行:
[mapred]$ $HADOOP_HOME/bin/mapred --daemon stop historyserver
当Hadoop集群启动并运行后,请按照以下说明检查各组件的Web界面:
守护进程 | Web界面 | 备注 |
---|---|---|
NameNode | http://nn_host:port/ | 默认HTTP端口为9870。 |
ResourceManager | http://rm_host:port/ | 默认HTTP端口为8088。 |
MapReduce JobHistory 服务器 | http://jhs_host:port/ | 默认HTTP端口是19888。 |