目的
本文档描述了如何在多个节点以及大集群中数千个节点进行安装,配置和管理Hadoop集群。
先决条件
在Apache官网站点下载的Hadoop的稳定版本。
安装
安装Hadoop集群通常需要在所有集群计算机上的解压软件hadoop软件包或安装的RPM。
通常,集群中一台机器被指定为NameNode和另一台机器的作为的ResourceManager,独立存在的。这两台集群机器都是Master(主节点)。
在集群中剩下的机器为集群的Datanode(数据节点)和NodeManager(节点管理器),这部分成为slave(从节点)。
在非安全模式下运行hadoop
以下各节描述了如何配置Hadoop集群。
配置文件
hadoop的配置是由两种重要类型的配置文件进行驱动的:默认是只读的配置:- core-default.xml, hdfs-default.xml, yarn-default.xml and mapred-default.xml。
特殊节点配置:conf/core-site.xml, conf/hdfs-site.xml, conf/yarn-site.xml and conf/mapred-site.xml。
此外,你可以通过分布的bin/文件夹下的hadoop脚本conf/hadoop-env.sh和yarn-env.sh。通过设置设定值进行控制。
节点配置:
要配置Hadoop集群,你需要配置在Hadoop运行的环境中配置环境变量以及为Hadoop守护进程的配置参数。
Hadoop启动进程是NameNode/DataNode and ResourceManager/NodeManager。
配置Hadoop运行环境
管理员可以使用的conf/hadoop-env.sh 和 conf/yarn-env.sh脚本做的Hadoop运行的进程环境中的特定节点的配置。至少你应该正确配置集群远程节点上的JAVA_HOME 。
在大多数情况下,你也应该设置HADOOP_PID_DIR 和 HADOOP_SECURE_DN_PID_DIR。设置只有运行在Hadoop进程中的用户才可以有写的权限。否则有可能受到攻击。
管理员可以使用下表所示的配置选项配置各个守护进程:
进程值 | 环境变量 |
---|---|
NameNode | HADOOP_NAMENODE_OPTS |
DataNode | HADOOP_DATANODE_OPTS |
Secondary NameNode | HADOOP_SECONDARYNAMENODE_OPTS |
ResourceManager | YARN_RESOURCEMANAGER_OPTS |
NodeManager | YARN_NODEMANAGER_OPTS |
WebAppProxy | YARN_PROXYSERVER_OPTS |
Map Reduce Job History Server | HADOOP_JOB_HISTORYSERVER_OPTS |
例如,要配置的Namenode使用parallelGC,下面的语句应该在的hadoop-env.sh加入:
export HADOOP_NAMENODE_OPTS="-XX:+UseParallelGC ${HADOOP_NAMENODE_OPTS}"
其他有用的配置参数,你可以自定义包括:
HADOOP_LOG_DIR / YARN_LOG_DIR -hadoop的守护进程的日志文件的存储目录。他们如果目录不存在,会自动创建。
HADOOP_HEAPSIZE / YARN_HEAPSIZE-堆大小的上限设置。以MB为单位例如:如果varibale设置为1000堆将被设置为1000MB。这是用来配置堆大小的守护进程。默认情况下,该值是1000,如果你想单独配置值为每个守护进程设置就可以使用。
-
守护进程 环境变量 ResourceManager YARN_RESOURCEMANAGER_HEAPSIZE NodeManager YARN_NODEMANAGER_HEAPSIZE WebAppProxy YARN_PROXYSERVER_HEAPSIZE Map Reduce Job History Server HADOOP_JOB_HISTORYSERVER_HEAPSIZE
在非安全模式下配置hadoop守护进程。
本节讨论在给定的配置文件中指定重要的参数的问题:
- conf/core-site.xml
参数 值 注释 fs.defaultFS NameNode URI hdfs://host:port/ io.file.buffer.size 131072 SequenceFiles文件中.读写缓存size设定 - conf/hdfs-site.xml:配置 NameNode:
-
参数 值 Notes dfs.namenode.name.dir 在本地文件系统所在的NameNode的存储空间和持续化处理日志 如果这是一个以逗号分隔的目录列表,然后将名称表被复制的所有目录,以备不时之需。 dfs.namenode.hosts /dfs.namenode.hosts.exclude Datanodes
permitted/excluded列表如有必要,可以使用这些文件来控制允许数据节点的列表 dfs.blocksize 268435456 大型的文件系统HDFS块大小为256MB dfs.namenode.handler.count 100 设置更多的namenode线程,处理从datanode发出的大量RPC请求 - Configurations for DataNode:
Parameter Value Notes dfs.datanode.data.dir 逗号分隔的一个DataNode上,它应该保存它的块的本地文件系统的路径列表 如果这是一个以逗号分隔的目录列表,那么数据将被存储在所有命名的目录,通常在不同的设备。
-
- conf/yarn-site.xml
- 配置ResourceManager 和 NodeManager:
参数 值 备注 yarn.acl.enable true /false 启用ACL的?默认为false。 yarn.admin.acl Admin ACL 访问控制列表,在群集上设置管理员。 ACL是为逗号分隔usersspacecomma分隔组。默认为*特殊值这意味着任何人。只是空间的特殊值意味着没有人进入。 yarn.log-aggregation-enable false 配置来启用或禁用日志聚合 - 配置 ResourceManager:
参数 值 备注 yarn.resourcemanager.address 客户端对ResourceManager主机通过 host:port 提交作业 host:port yarn.resourcemanager.scheduler.address ApplicationMasters 通过ResourceManager 主机访问host:port 跟踪调度程序获资源 host:port yarn.resourcemanager.resource-tracker.address NodeManagers通过ResourceManager主机访问 host:port host:port yarn.resourcemanager.admin.address 管理命令通过ResourceManager 主机访问host:port host:port yarn.resourcemanager.webapp.address ResourceManager web页面host:port. host:port yarn.resourcemanager.scheduler.class ResourceManager 调度类(Scheduler class) CapacityScheduler(推荐),FairScheduler(也推荐),orFifoScheduler yarn.scheduler.minimum-allocation-mb 每个容器内存最低限额分配到的资源管理器要求 I以MB为单位 yarn.scheduler.maximum-allocation-mb 资源管理器分配给每个容器的内存最大限制 以MB为单位 yarn.resourcemanager.nodes.include-path /yarn.resourcemanager.nodes.exclude-path NodeManagers 的permitted/excluded列表 如有必要,可使用这些文件来控制允许NodeManagers列表。 - 配置 NodeManager:
参数 值 备注 yarn.nodemanager.resource.memory-mb givenNodeManager即资源的可用物理内存,以MB为单位 定义在节点管理器总的可用资源,以提供给运行容器 yarn.nodemanager.vmem-pmem-ratio 最大比率为一些任务的虚拟内存使用量可能会超过物理内存率 每个任务的虚拟内存的使用可以通过这个比例超过了物理内存的限制。虚拟内存的使用上的节点管理器任务的总量可以通过这个比率超过其物理内存的使用。 yarn.nodemanager.local-dirs 数据写入本地文件系统路径的列表用逗号分隔 多条存储路径可以提高磁盘的读写速度 yarn.nodemanager.log-dirs 本地文件系统日志路径的列表逗号分隔。 多条存储路径可以提高磁盘的读写速度 yarn.nodemanager.log.retain-seconds 10800 如果日志聚合被禁用。默认的时间(以秒为单位)保留在节点管理器只适用日志文件, yarn.nodemanager.remote-app-log-dir /logs HDFS目录下的应用程序日志移动应用上完成。需要设置相应的权限。仅适用日志聚合功能。 yarn.nodemanager.remote-app-log-dir-suffix logs 后缀追加到远程日志目录。日志将被汇总到 ${yarn.nodemanager.remote-app-log-dir}/${user}/${thisParam} 仅适用日志聚合功能。 yarn.nodemanager.aux-services mapreduce_shuffle Shuffle service 需要加以设置的Map Reduce的应用程序服务。 - 配置历史记录服务器(需要被移到别处):
参数 值 备注 yarn.log-aggregation.retain-seconds -1 如何长期保持聚集日志删除之前。 -1禁用。请注意,设置这个太小了,你将名称节点的垃圾邮件 yarn.log-aggregation.retain-check-interval-seconds -1 检查汇总的日志保留的时间。如果设置为0或负值,则该值被计算为十分之一的聚合日志保留时间。请注意,设置这个太小了,你将称为名称节点的垃圾邮件。
- 配置ResourceManager 和 NodeManager:
- conf/mapred-site.xml
- 配置 MapReduce 应用程序:
参数 值 备注 mapreduce.framework.name yarn 执行框架设置为 Hadoop YARN. mapreduce.map.memory.mb 1536 对maps更大的资源限制的. mapreduce.map.java.opts -Xmx1024M maps 中对jvm child设置更大的堆大小 mapreduce.reduce.memory.mb 3072 设置 reduces对于较大的资源限制 mapreduce.reduce.java.opts -Xmx2560M reduces对 child jvms Larger heap-size 设置 mapreduce.task.io.sort.mb 512 更高的内存限制,而对数据进行排序的效率。 mapreduce.task.io.sort.factor 100 在文件排序中更多的流合并为一次 mapreduce.reduce.shuffle.parallelcopies 50 通过reduces从非常多的map中读取较多的平行副本 - 配置MapReduce的JobHistory服务器:
Parameter Value Notes mapreduce.jobhistory.address MapReduce JobHistory Server host:port 默认端口号 10020. mapreduce.jobhistory.webapp.address MapReduce JobHistory Server Web UIhost:port 默认端口号 19888. mapreduce.jobhistory.intermediate-done-dir /mr-history/tmp 在历史文件被写入由MapReduce作业 mapreduce.jobhistory.done-dir /mr-history/done 目录中的历史文件是由MR JobHistory Server管理。
- 配置 MapReduce 应用程序:
参数 | 值 | 备注 |
---|---|---|
yarn.nodemanager.health-checker.script.path | Node health script | 检查节点健康状态的脚本 |
yarn.nodemanager.health-checker.script.opts | Node health script options | 检查节点的健康状态脚本选项 |
yarn.nodemanager.health-checker.script.interval-ms | Node health script interval | 运行健康脚本的时间间隔 |
yarn.nodemanager.health-checker.script.timeout-ms | Node health script timeout interval | 健康脚本的执行超时时间 |
Operating the Hadoop Cluster
Once all the necessary configuration is complete, distribute the files to the HADOOP_CONF_DIR directory on all the machines.
This section also describes the various Unix users who should be starting the various components and uses the same Unix accounts and groups used previously:
Hadoop Startup
To start a Hadoop cluster you will need to start both the HDFS and YARN cluster.
Format a new distributed filesystem as hdfs:
[hdfs]$ $HADOOP_PREFIX/bin/hdfs namenode -format <cluster_name>
Start the HDFS with the following command, run on the designated NameNode as hdfs:
[hdfs]$ $HADOOP_PREFIX/sbin/hadoop-daemon.sh --config $HADOOP_CONF_DIR --script hdfs start namenode
Run a script to start DataNodes on all slaves as root with a special environment variable HADOOP_SECURE_DN_USER set to hdfs:
[root]$ HADOOP_SECURE_DN_USER=hdfs $HADOOP_PREFIX/sbin/hadoop-daemon.sh --config $HADOOP_CONF_DIR --script hdfs start datanode
Start the YARN with the following command, run on the designated ResourceManager as yarn:
[yarn]$ $HADOOP_YARN_HOME/sbin/yarn-daemon.sh --config $HADOOP_CONF_DIR start resourcemanager
Run a script to start NodeManagers on all slaves as yarn:
[yarn]$ $HADOOP_YARN_HOME/sbin/yarn-daemon.sh --config $HADOOP_CONF_DIR start nodemanager
Start a standalone WebAppProxy server. Run on the WebAppProxy server as yarn. If multiple servers are used with load balancing it should be run on each of them:
[yarn]$ $HADOOP_YARN_HOME/bin/yarn start proxyserver --config $HADOOP_CONF_DIR
Start the MapReduce JobHistory Server with the following command, run on the designated server as mapred:
[mapred]$ $HADOOP_PREFIX/sbin/mr-jobhistory-daemon.sh start historyserver --config $HADOOP_CONF_DIR
Hadoop Shutdown
Stop the NameNode with the following command, run on the designated NameNode as hdfs:
[hdfs]$ $HADOOP_PREFIX/sbin/hadoop-daemon.sh --config $HADOOP_CONF_DIR --script hdfs stop namenode
Run a script to stop DataNodes on all slaves as root:
[root]$ $HADOOP_PREFIX/sbin/hadoop-daemon.sh --config $HADOOP_CONF_DIR --script hdfs stop datanode
Stop the ResourceManager with the following command, run on the designated ResourceManager as yarn:
[yarn]$ $HADOOP_YARN_HOME/sbin/yarn-daemon.sh --config $HADOOP_CONF_DIR stop resourcemanager
Run a script to stop NodeManagers on all slaves as yarn:
[yarn]$ $HADOOP_YARN_HOME/sbin/yarn-daemon.sh --config $HADOOP_CONF_DIR stop nodemanager
Stop the WebAppProxy server. Run on the WebAppProxy server as yarn. If multiple servers are used with load balancing it should be run on each of them:
[yarn]$ $HADOOP_YARN_HOME/bin/yarn stop proxyserver --config $HADOOP_CONF_DIR
Stop the MapReduce JobHistory Server with the following command, run on the designated server as mapred:
[mapred]$ $HADOOP_PREFIX/sbin/mr-jobhistory-daemon.sh stop historyserver --config $HADOOP_CONF_DIR
web 接口
一旦Hadoop集群的建立和运行检查Web-UI,如下所述的组件:
Daemon Web Interface Notes NameNode http://nn_host:port/ 默认http端口号 50070. ResourceManager http://rm_host:port/ 默认http端口号 8088. MapReduce JobHistory Server http://jhs_host:port/ 默认http端口号19888.