hadoop安装
1 下载
地址http://hadoop.apache.org/releases.html
2 解压
tar -zxvf hadoop-2.6.5.tar.gz -C /opt/wsqt/core
mv hadoop-2.6.5/hadoop
3 修改HDFS配置文件
清空相关配置文件复制以下配置文件,或手动修改。
etc/hadoop/slaves
##此文件中hostname为所有的datanode数据节点,每个一行
hadoop003
hadoop004
hadoop005
etc/hadoop/core-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!--##集群hdfs逻辑名wsqt,集群内对外提供服务。-->
<property>
<name>fs.defaultFS</name>
<value>hdfs://wsqt/</value>
</property>
<!--##临时目录,很多临时数据都以此为默认根目录。-->
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/wsqt/data/namenode</value>
</property>
<!--##zookeeper服务节点-->
<property>
<name>ha.zookeeper.quorum</name>
<value>hadoop003:2181,hadoop004:2181,hadoop005:2181</value>
</property>
<!--##流文件的缓冲区为 128k-->
<property>
<name>io.file.buffer.size</name>
<value>131072</value>
</property>
<!--##压缩算法,我们目前使用snappy压缩-->
<property>
<name>io.compression.codecs</name>
<value>org.apache.hadoop.io.compress.DefaultCodec,org.apache.hadoop.io.compress.GzipCodec,org.apache.hadoop.io.compress.BZip2Codec,org.apache.hadoop.io.compress.SnappyCodec</value>
</property>
<!--##回收站,单位分钟-->
<property>
<name>fs.trash.interval</name>
<value>10080</value>
<description>Number of minutes between trash checkpoints.
If zero, the trash feature is disabled.
</description>
</property>
<!--##balance带宽,单位bytes,默认10M,修改为50-100M-->
<property>
<name>dfs.balance.bandwidthPerSec</name>
<value>104857600</value>
<description>
Specifies themaximum bandwidth that each datanode can utilize for the balancing purpose interm of the number of bytes per second.
</description>
</property>
</configuration>
etc/hadoop/hdfs-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!--##集群hdfs逻辑名wsqt-->
<property>
<name>dfs.nameservices</name>
<value>wsqt</value>
</property>
<!--##集群wsqt的namenode节点服务逻辑名为nn1和nn2-->
<property>
<name>dfs.ha.namenodes.wsqt</name>
<value>nn1,nn2</value>
</property>
<!--##nn1的配置为hadoop001-->
<property>
<name>dfs.namenode.rpc-address.wsqt.nn1</name>
<value>hadoop001:9000</value>
</property>
<property>
<name>dfs.namenode.http-address.wsqt.nn1</name>
<value>0.0.0.0:50070</value>
</property>
<!--##nn2的配置为hadoop002-->
<property>
<name>dfs.namenode.rpc-address.wsqt.nn2</name>
<value>hadoop002:9000</value>
</property>
<property>
<name>dfs.namenode.http-address.wsqt.nn2</name>
<value>0.0.0.0:50070</value>
</property>
<!--##journalnode服务节点配置-->
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://hadoop001:8485;hadoop002:8485;hadoop003:8485/wsqt</value>
</property>
<!--##journalnode服务数据存储目录-->
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/opt/wsqt/data/journal</value>
</property>
<!--##ha热切配置-->
<property>
<name>dfs.ha.automatic-failover.enabled.wsqt</name>
<value>true</value>
</property>
<!--HDFS客户端用来和活动的namenode联系的java类-->
<property>
<name>dfs.client.failover.proxy.provider.wsqt</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<property>
<name>dfs.ha.fencing.methods</name>
<value>sshfence</value>
</property>
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/home/hadoop/.ssh/id_rsa</value>
</property>
<!--##namenode数据存放目录,处于安全考虑可以设置多个目录,用逗号隔开。默认设置是file://${hadoop.tmp.dir}/dfs/name-->
<property>
<name>dfs.namenode.name.dir</name>
<value>/opt/wsqt/data/namenode/dfs/name</value>
</property>
<!--##datanode数据存放目录,默认是file://${hadoop.tmp.dir}/dfs/data,这个参数为数据盘目录,用逗号隔开。生产环境,需要将此参数设置为数据盘目录-->
<property>
<name>dfs.datanode.data.dir</name>
<value>/opt/wsqt/data/disk1/data </value>
<description>default:file://${hadoop.tmp.dir}/dfs/data. for example:/disk1/data,/disk2/data,/disk3/data</description>
</property>
<!--##块大小,默认64MB-->
<property>
<name>dfs.block.size</name>
<value>268435456</value>
</property>
<!--##数据节点datanode的服务连接处理线程数-->
<property>
<name>dfs.datanode.handler.count</name>
<value>20</value>
</property>
<!--##主节点namenode的服务连接处理线程数-->
<property>
<name>dfs.namenode.handler.count</name>
<value>20</value>
</property>
<!--##datanode的最大句柄数 -->
<property>
<name>dfs.datanode.max.xcievers</name>
<value>131072</value>
</property>
<!--## HDFS写入过程中的2个超时设置 -->
<property>
<name>dfs.datanode.socket.write.timeout</name>
<value>0</value>
</property>
<property>
<name>dfs.socket.timeout</name>
<value>180000</value>
</property>
<!--##硬盘损坏数导致datanode失效—(如果单机只有一块磁盘的情况下 不要配置)
<property>
<name>dfs.datanode.failed.volumes.tolerated</name>
<value>3</value>
</property>
-->
<!--##块副本复制数,生产模式下3份,既考虑高可用又考虑存储占用。-->
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
<property>
<name>mapred.child.env</name>
<value>JAVA_LIBRARY_PATH=$HADOOP_HOME/lib/native</value>
</property>
</configuration>
etc/hadoop/hadoop-env.sh
export WSQT_HOME=/opt/wsqt
export JAVA_HOME=${WSQT_HOME}/core/java
export HADOOP_HOME=${WSQT_HOME}/core/hadoop
#配置文件目录
export HADOOP_CONF_DIR=${HADOOP_HOME}/etc/hadoop
export HADOOP_CONF_DIR=${HADOOP_CONF_DIR:-"/etc/hadoop"}
# Extra Java CLASSPATH elements. Automatically insert capacity-scheduler.
for f in $HADOOP_HOME/contrib/capacity-scheduler/*.jar; do
if [ "$HADOOP_CLASSPATH" ]; then
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$f
else
export HADOOP_CLASSPATH=$f
fi
done
# The maximum amount of heap to use, in MB. Default is 1000.
#大型集群,或者集群扩容时需要适当增加这个参数,默认是1000MB.
#export HADOOP_HEAPSIZE=4096
#export HADOOP_NAMENODE_INIT_HEAPSIZE=1024
# Extra Java runtime options. Empty by default.
export HADOOP_OPTS="$HADOOP_OPTS -Djava.net.preferIPv4Stack=true"
# Command specific options appended to HADOOP_OPTS when specified
##namenode启动的java参数
export HADOOP_NAMENODE_OPTS="-Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_NAMENODE_OPTS"
##datanode启动的java参数
export HADOOP_DATANODE_OPTS="-Dhadoop.security.logger=ERROR,RFAS $HADOOP_DATANODE_OPTS"
export HADOOP_SECONDARYNAMENODE_OPTS="-Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_
SECONDARYNAMENODE_OPTS"
export HADOOP_NFS3_OPTS="$HADOOP_NFS3_OPTS"
export HADOOP_PORTMAP_OPTS="-Xmx512m $HADOOP_PORTMAP_OPTS"
# The following applies to multiple commands (fs, dfs, fsck, distcp etc)
# The following applies to multiple commands (fs, dfs, fsck, distcp etc)
#集群过大的时候,某些错误可能比较慢,可以适当增加这个参数
export HADOOP_CLIENT_OPTS="-Xmx512m $HADOOP_CLIENT_OPTS"
#HADOOP_JAVA_PLATFORM_OPTS="-XX:-UsePerfData $HADOOP_JAVA_PLATFORM_OPTS"
# On secure datanodes, user to run the datanode as after dropping privileges.
# This **MUST** be uncommented to enable secure HDFS if using privileged ports
# to provide authentication of data transfer protocol. This **MUST NOT** be
# defined if SASL is configured for authentication of data transfer protocol
# using non-privileged ports.
export HADOOP_SECURE_DN_USER=${HADOOP_SECURE_DN_USER}
# Where log files are stored. $HADOOP_HOME/logs by default.
export HADOOP_LOG_DIR=${WSQT_HOME}/logs/hadoop/$USER
# Where log files are stored. $HADOOP_HOME/logs by default.
#export HADOOP_LOG_DIR=${HADOOP_LOG_DIR}/$USER
# Where log files are stored in the secure data environment.
export HADOOP_SECURE_DN_LOG_DIR=${HADOOP_LOG_DIR}/${HADOOP_HDFS_USER}
###
# HDFS Mover specific parameters
###
# Specify the JVM options to be used when starting the HDFS Mover.
# These options will be appended to the options specified as HADOOP_OPTS
# and therefore may override any similar flags set in HADOOP_OPTS
#
# export HADOOP_MOVER_OPTS=""
###
# Advanced Users Only!
###
# The directory where pid files are stored. /tmp by default.
# NOTE: this should be set to a directory that can only be written to by
# the user that will run the hadoop daemons. Otherwise there is the
# potential for a symlink attack.
# The directory where pid files are stored. /tmp by default.
# /tmp目录里由于会系统设置默认清楚过期文件,所以pid文件时间一长就没了,在关闭集群的时候就会报错显示没有服务需要关闭。虽然服务仍然存在。
# NOTE: this should be set to a directory that can only be written to by
# the user that will run the hadoop daemons. Otherwise there is the
# potential for a symlink attack.
export HADOOP_PID_DIR=${WSQT_HOME}/tmp
export HADOOP_PID_DIR=${HADOOP_PID_DIR}
export HADOOP_SECURE_DN_PID_DIR=${HADOOP_PID_DIR}
# A string representing this instance of hadoop. $USER by default.
export HADOOP_IDENT_STRING=$USER
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HADOOP_HOME/lib/native
修改YARN配置文件
etc/hadoop/mapred-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!--##配置计算机构为2代yarn -->
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<!--##配置jobhistoryserver-->
<property>
<name>mapreduce.jobhistory.address</name>
<value>hadoop001:10020</value>
</property>
<!--##配置jobhistoryserver的web端-->
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>hadoop001:19888</value>
</property>
<!--##提交任务时使用的目录,默认/tmp/hadoop-yarn/staging-->
<property>
<name>yarn.app.mapreduce.am.staging-dir</name>
<value>/opt/wsqt/data/yarn/staging</value>
</property>
<!--启动task管理的子进程时的内存设置-->
<property>
<name>mapred.child.java.opts</name>
<value>-Xmx4g</value>
</property>
<!--排序文件的内存缓存大小为512M-->
<property>
<name>io.sort.mb</name>
<value>512</value>
</property>
<!--排完序的文件的合并时的打开文件句柄数-->
<property>
<name>io.sort.factor</name>
<value>20</value>
</property>
<!--##jvm重用,-1表示为无限制重用-->
<property>
<name>mapred.job.reuse.jvm.num.tasks</name>
<value>-1</value>
</property>
<!--##shuffle并行copy数-->
<property>
<name>mapreduce.reduce.shuffle.parallelcopies</name>
<value>20</value>
</property>
<!--##reduce是否输出压缩 -->
<property>
<name>mapreduce.output.fileoutputformat.compress</name>
<value>true</value>
</property>
<!--##reduce输出压缩编码 -->
<property>
<name>mapreduce.output.fileoutputformat.compress.codec</name>
<value>org.apache.hadoop.io.compress.SnappyCodec</value>
</property>
<!--##map是否输出压缩 -->
<property>
<name>mapreduce.map.output.compress</name>
<value>true</value>
</property>
<!--##map输出压缩编码为snappy压缩-->
<property>
<name>mapreduce.map.output.compress.codec</name>
<value>org.apache.hadoop.io.compress.SnappyCodec</value>
</property>
<!--##输出压缩的方式为对块进行压缩 -->
<property>
<name>mapreduce.output.fileoutputformat.compress.type</name>
<value>BLOCK</value>
</property>
<!--##mapreduce job执行的临时数据目录,若未使用yarn架构,直接使用mapredcue计算的话,则应使用旧参数名mapred.local.dir,否则不能生效-->
<property>
<name>mapreduce.cluster.local.dir</name>
<value>/opt/wsqt/data/disk1/tmp/mapred/local </value>
<description>The local directory where MapReduce stores intermediate data files. May be a comma-separated list of directories on different devices in order to spread disk i/o. Directories that do not exist are ignored. file://${hadoop.tmp.dir}/mapred/local</description>
</property>
<!--##是否对Map Task启用推测执行机制 -->
<property>
<name>mapreduce.map.speculative</name>
<value>false</value>
</property>
<!--##map是否对Reduce Task启用推测执行机制-->
<property>
<name>mapreduce.reduce.speculative</name>
<value>false</value>
</property>
</configuration>
etc/hadoop/mapred-env.sh
##控制jobhistoryserver的jvm内存占用(MB)
export HADOOP_JOB_HISTORYSERVER_HEAPSIZE=1000
##mapred日志
export HADOOP_MAPRED_ROOT_LOGGER=INFO,RFA
#export HADOOP_JOB_HISTORYSERVER_OPTS=
#export HADOOP_MAPRED_LOG_DIR="" # Where log files are stored. $HADOOP_MAPRED_HOME/logs by default.
#export HADOOP_JHS_LOGGER=INFO,RFA # Hadoop JobSummary logger.
#export HADOOP_MAPRED_PID_DIR= # The pid files are stored. /tmp by default.
#export HADOOP_MAPRED_IDENT_STRING= #A string representing this instance of hadoop. $USER by default
#export HADOOP_MAPRED_NICENESS= #The scheduling priority for daemons. Defaults to 0.
etc/hadoop/yarn-site.xml
<?xml version="1.0"?>
<configuration>
<!--##NodeManager上运行的附属服务。需配置成mapreduce_shuffle,才可运行MapReduce程序-->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<!--##nodemanager临时数据目录-->
<property>
<name>yarn.nodemanager.local-dirs</name>
<value>/opt/wsqt/data/disk1/tmp/yarn/local</value>
<description>default:${hadoop.tmp.dir}/nm-local-dir.List of directories to store localized files in. An application's localized file directory will be found in: ${yarn.nodemanager.local-dirs}/usercache/${user}/appcache/application_${appid}. Individual containers' work directories, called container_${contid}, will be subdirectories of this.May be a comma-separated list of directories on different devices in order to spread disk i/o</description>
</property>
<!--##nodemanager日志目录-->
<property>
<name>yarn.nodemanager.log-dirs</name>
<value>/opt/wsqt/logs/yarn/userlogs</value>
</property>
<!--##是否启用日志聚集功能,它能将运行完成的Container/任务日志上传到HDFS上,从而减轻NodeManager负载,且提供一个中央化存储和分析机制。默认情况下,Container/任务日志存在在各个NodeManager上-->
<property>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
</property>
<!--##当应用程序运行结束后,日志被转移到的HDFS目录-->
<property>
<description>Where to aggregate logs</description>
<name>yarn.nodemanager.remote-app-log-dir</name>
<value>hdfs://wsqt/var/log/hadoop-yarn/apps</value>
</property>
<!--在HDFS上聚集的日志最多保存多长时间-->
<property>
<name>yarn.log-aggregation.retain-seconds</name>
<value>2592000</value>
<final>false</final>
</property>
<!--多长时间检查一次日志,并将满足条件的删除,如果是0或者负数,则为上一个值的1/10-->
<property>
<name>yarn.log-aggregation.retain-check-interval-seconds</name>
<value>3600</value>
<final>false</final>
</property>
<!--##resourcemanager连接失败的重试间隔-->
<!-- Resource Manager Configs -->
<property>
<name>yarn.resourcemanager.connect.retry-interval.ms</name>
<value>2000</value>
</property>
<!--##resourcemanager的ha是否启用 -->
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<!--##resourcemanager的ha热切—故障转移-->
<property>
<name>yarn.resourcemanager.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
<!-- ##使嵌入式自动故障转移。HA环境启动,与 ZKRMStateStore 配合 处理fencing -->
<property>
<name>yarn.resourcemanager.ha.automatic-failover.embedded</name>
<value>true</value>
</property>
<!--##yarn集群名称,确保HA选举时对应的集群 -->
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>wsqt</value>
</property>
<!--##yarn集群两个resourcemanager的逻辑名称rm1、rm2 -->
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
</property>
<!--##本服务器resourcemanager对应逻辑名称rm1,这个参数在rm1和rm2上不同,我们确定hadoop001为rm1,hadoop002为rm2,那么在hadoop001的yarn-site.xml里配置此参数为rm1,而在hadoop002的yarn-site.xml里配置此参数为rm2。这是服务器之间少数几个不同配置。 -->
<property>
<name>yarn.resourcemanager.ha.id</name>
<value>rm1</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
</property>
<!--是否启用resourcemanager的恢复;若为false,也就是说resourcemanager挂了相应的正在运行的任务在rm恢复后不能重新启动 -->
<property>
<name>yarn.resourcemanager.recovery.enabled</name>
<value>true</value>
<description>Enable RM to recover state after starting. If true, then yarn.resourcemanager.store.class must be specified. </description>
</property>
<!--HA时,RMStateStore需要配置为这个值。 -->
<property>
<name>yarn.resourcemanager.store.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore</value>
</property>
<!--配置与zk的连接地址 -->
<property>
<name>yarn.resourcemanager.zk.state-store.address</name>
<value>hadoop003:2181,hadoop004:2181, hadoop005:2181</value>
</property>
<!--等待间隔 -->
<property>
<name>yarn.app.mapreduce.am.scheduler.connection.wait.interval-ms</name>
<value>5000</value>
</property>
<!-- RM1 configs -->
<!--##yarn集群配置rm1的ip及端口 -->
<property>
<name>yarn.resourcemanager.address.rm1</name>
<value>hadoop001:23140</value>
</property>
<!--Resourcemanager的调度程序的ip及端口 -->
<property>
<name>yarn.resourcemanager.scheduler.address.rm1</name>
<value>hadoop001:23130</value>
</property>
<!--Web页面的端口 https的ip及端口 -->
<property>
<name>yarn.resourcemanager.webapp.https.address.rm1</name>
<value>hadoop001:23189</value>
</property>
<!--Web页面的端口 http的ip及端口 -->
<property>
<name>yarn.resourcemanager.webapp.address.rm1</name>
<value>hadoop001:23188</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address.rm1</name>
<value>hadoop001:23125</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address.rm1</name>
<value>hadoop001:23141</value>
</property>
<!-- RM2 configs -->
<!--##yarn集群配置rm2的ip及端口 -->
<property>
<name>yarn.resourcemanager.address.rm2</name>
<value>hadoop002:23140</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address.rm2</name>
<value>hadoop002:23130</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.https.address.rm2</name>
<value>hadoop002:23189</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address.rm2</name>
<value>hadoop002:23188</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address.rm2</name>
<value>hadoop002:23125</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address.rm2</name>
<value>hadoop002:23141</value>
</property>
<!--##yarn集群配置nodemanager的相关端口 -->
<!-- Node Manager Configs -->
<property>
<description>Address where the localizer IPC is.</description>
<name>yarn.nodemanager.localizer.address</name>
<value>0.0.0.0:23344</value>
</property>
<property>
<description>NM Webapp address.</description>
<name>yarn.nodemanager.webapp.address</name>
<value>0.0.0.0:23999</value>
</property>
<property>
<name>mapreduce.shuffle.port</name>
<value>23080</value>
</property>
<!--##zookeeper的地址和端口 -->
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>hadoop003:2181,hadoop004:2181,hadoop005:2181</value>
</property>
<!--##Amount of physical memory, in MB, that can be allocated for containers,这里是nodemanager节点所有containers可以使用的物理内存的大小 -->
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>122880</value>
</property>
<!--##nodemanager节点上每个container可以使用的物理内存的大小,小于此值的申请自动修改为此值。默认1024,加大有助于减少内存不足,但是加大也容易造成内存浪费。可以根据job的数据量设置合适值,其他的在脚本中手动set参数 -->
<property>
<name>yarn.scheduler.minimum-allocation-mb</name>
<value>4096</value>
</property>
<!--##nodemanager节点上所有containers可以使用的CPU核数,设置为与虚拟核数相等 -->
<property>
<name>yarn.nodemanager.resource.cpu-vcores</name>
<value>24</value>
<description>number of all the cpu cores</description>
</property>
<property>
<name>yarn.app.mapreduce.am.scheduler.connection.wait.interval-ms</name>
<value>5000</value>
<final>false</final>
</property>
</configuration>
etc/hadoop/yarn-env.sh
export WSQT_HOME=/opt/wsqt
# User for YARN daemons
export HADOOP_YARN_USER=${HADOOP_YARN_USER:-yarn}
# resolve links - $0 may be a softlink
export YARN_CONF_DIR="${YARN_CONF_DIR:-$HADOOP_YARN_HOME/conf}"
export JAVA_HOME=${WSQT_HOME}/core/java
# some Java parameters
# export JAVA_HOME=/home/y/libexec/jdk1.6.0/
if [ "$JAVA_HOME" != "" ]; then
#echo "run java in $JAVA_HOME"
JAVA_HOME=$JAVA_HOME
fi
if [ "$JAVA_HOME" = "" ]; then
echo "Error: JAVA_HOME is not set."
exit 1
fi
JAVA=$JAVA_HOME/bin/java
JAVA_HEAP_MAX=-Xmx1000m
# For setting YARN specific HEAP sizes please use this
# Parameter and set appropriately
# YARN_HEAPSIZE=1000
# check envvars which might override default args
if [ "$YARN_HEAPSIZE" != "" ]; then
JAVA_HEAP_MAX="-Xmx""$YARN_HEAPSIZE""m"
fi
# Resource Manager specific parameters
# Specify the max Heapsize for the ResourceManager using a numerical value
# in the scale of MB. For example, to specify an jvm option of -Xmx1000m, set
# the value to 1000.
# This value will be overridden by an Xmx setting specified in either YARN_OPTS
# and/or YARN_RESOURCEMANAGER_OPTS.
# If not specified, the default value will be picked from either YARN_HEAPMAX
# or JAVA_HEAP_MAX with YARN_HEAPMAX as the preferred option of the two.
#大型集群,或者集群扩容时需要适当增加这个参数,默认是1000MB.
#export YARN_RESOURCEMANAGER_HEAPSIZE=1000
#大型集群,或者集群扩容时需要适当增加这个参数,默认是1000MB.
#export YARN_NODEMANAGER_HEAPSIZE=1000
# so that filenames w/ spaces are handled correctly in loops below
IFS=
##控制yarn日志,包括resourcemanager和nodemanager,其余参数基本默认
export YARN_LOG_DIR=${WSQT_HOME}/logs/yarn
##控制yarn服务的pid文件位置
export YARN_PID_DIR=${WSQT_HOME}/tmp
# default log directory & file
if [ "$YARN_LOG_DIR" = "" ]; then
YARN_LOG_DIR="$HADOOP_YARN_HOME/logs"
fi
if [ "$YARN_LOGFILE" = "" ]; then
YARN_LOGFILE='yarn.log'
fi
# default policy file for service-level authorization
if [ "$YARN_POLICYFILE" = "" ]; then
YARN_POLICYFILE="hadoop-policy.xml"
fi
# restore ordinary wsqtaviour
unset IFS
YARN_OPTS="$YARN_OPTS -Dhadoop.log.dir=$YARN_LOG_DIR"
YARN_OPTS="$YARN_OPTS -Dyarn.log.dir=$YARN_LOG_DIR"
YARN_OPTS="$YARN_OPTS -Dhadoop.log.file=$YARN_LOGFILE"
YARN_OPTS="$YARN_OPTS -Dyarn.log.file=$YARN_LOGFILE"
YARN_OPTS="$YARN_OPTS -Dyarn.home.dir=$YARN_COMMON_HOME"
YARN_OPTS="$YARN_OPTS -Dyarn.id.str=$YARN_IDENT_STRING"
YARN_OPTS="$YARN_OPTS -Dhadoop.root.logger=${YARN_ROOT_LOGGER:-INFO,console}"
YARN_OPTS="$YARN_OPTS -Dyarn.root.logger=${YARN_ROOT_LOGGER:-INFO,console}"
if [ "x$JAVA_LIBRARY_PATH" != "x" ]; then
YARN_OPTS="$YARN_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
fi
YARN_OPTS="$YARN_OPTS -Dyarn.policy.file=$YARN_POLICYFILE
分发到其他节点上
scp -r hadoop/ hadoop\@hadoop002:\$PWD
scp -r hadoop/ hadoop\@hadoop003:\$PWD
scp -r hadoop/ hadoop\@hadoop004:\$PWD
scp -r hadoop/ hadoop\@hadoop005:\$PWD
启动HDFS
格式化HDFS的Zookeeper存储目录
格式化操作的目的是在ZK集群中建立一个节点,用于保存集群中NameNode的状态数据
在hadoop003上执行(只需在一个zookeeper节点执行即可):hdfs zkfc -formatZK
验证:zkCli.sh 并执行 ls / 显示信息
再执行quit可推出交互
启动JournalNode集群
- 所有journalnode节点上分别执行:
/opt/wsqt/core/hadoop/sbin/hadoop-daemon.sh start journalnode
- 所有journalnode节点上执行jps检测是否存在服务
[hadoop@data1 ~]$ jps |grep JournalNode
格式化并启动第一个NameNode
- 任选一个 ,这里选择hadoop001,执行:
##格式化当前节点的namenode数据
hdfs namenode -format
##格式化journalnode的数据,这个是ha需要做的
hdfs namenode -initializeSharedEdits
##启动当前节点的namenode服务
hadoop-daemon.sh start namenode
- 在hadoop001执行jps验证namenode服务是否存在
[hadoop@name2 ~]$ jps |grep NameNode
54542 NameNode
格式化并启动第二个NameNode
- 在hadoop002执行:
##启hadoop001已经格式化过,然后同步至hadoop002
hdfs namenode -bootstrapStandby
##启动当前节点的namenode服务
hadoop-daemon.sh start namenode
- 在hadoop002执行jps验证namenode服务是否存在
[hadoop@name2 ~]$ jps |grep NameNode
54542 NameNode
此时登陆http://hadoop001:50070与http://haoop001:50070皆显示standby状态
这里如果PC连接服务器使用浏览器需要输入IP_ADDRESS:50070来进行访问。
启动所有DataNode
- 在hadoop001执行:
##一次性启动全部DataNode节点
hadoop-daemons.sh start datanode
##或者在每个datanode上执行
hadoop-daemon.sh start datanode
- 在所有datanode节点上执行jps验证是否存在datanode服务
[hadoop@hadoop003 ~]$ jps |grep -i datanode
8439 DataNode
启动ZooKeeperFailoverController
- 所有namenode节点分别执行:
hadoop-daemon.sh start zkfc
- 验证:zkCli.sh 并执行 ls / 再执行quit可推出交互
[hadoop@hadoop001 ~]$ zkCli.sh
[zk: localhost:2181(CONNECTED) 0] ls /
[hadoop-ha, zookeeper]
##这两个服务第一个是供hdfs的ha可用,第二个是zookeeper自己服务。
[zk: localhost:2181(CONNECTED) 8] ls /hadoop-ha
[wsqt]
##这个这hdfs的逻辑名称有参数dfs.nameservices设置
[zk: localhost:2181(CONNECTED) 9] ls /hadoop-ha/wsqt
[ActiveBreadCrumb, ActiveStandbyElectorLock]
登陆namenode服务器web端查看服务器状态
此时登陆http://hadoop001:50070与http://haoop002:50070
其中一个为active另一个为standby状态。
这里如果PC连接服务器使用浏览器需要输入IP_ADDRESS:50070来进行访问。
启动YARN
启动hdfs后,创建必要目录
创建hdfs下的history目录
hadoop fs -mkdir -p /user/history
hadoop fs -chmod -R 777 /user/history
hadoop fs -chown hadoop:hadoop /user/history
创建hdfs下的log目录
hadoop fs -mkdir -p /var/log/hadoop-yarn
hadoop fs -chown hadoop:hadoop /var/log/hadoop-yarn
创建hdfs下的/tmp
##如果不创建/tmp按照指定的权限,那么WSQT的其他组件将会有问题。尤其是,如果不创建的话,其他进程会以严格的权限自动创建这个目录,这样就会影响到其他程序适用。
hadoop fs -mkdir /tmp
hadoop fs -chmod -R 777 /tmp
在hadoop001上执行start-yarn.sh:
##此脚本将会启动hadoop001上的resourcemanager及所有的nodemanager节点
/opt/wsqt/core/hadoop/sbin/start-yarn.sh
##关于单独启动单个resourcemanager和nodemanager的命令如下
/opt/wsqt/core/hadoop/sbin/yarn-daemon.sh start resourcemanager
/opt/wsqt/core/hadoop/sbin/yarn-daemon.sh start nodemanager
在hadoop002上启动resourcemanager:
/opt/wsqt/core/hadoop/sbin/yarn-daemon.sh start resourcemanager
在hadoop001上启动jobhistory server
##启动jobhistoryserver主要作用是记录yarn执行任务之后的日志。需要在/opt/wsqt/core/hadoop/etc/hadoop/mapred-site.xml参数文件中设置参数mapreduce.jobhistory.address和mapreduce.jobhistory.webapp.address
目前我们选择hadoop001作为historyserver。
/opt/wsqt/core/hadoop/sbin/mr-jobhistory-daemon.sh start historyserver
登陆resourcemanager服务器web端查看服务器状态
此时登陆http://hadoop001:23188与http://haoop002:23188
其中一个为active另一个为standby状态。活跃节点可以正常访问,备用节点会自动跳转至活跃节点的web地址。
http://resourcemanager_ipaddress:23188
这里如果PC连接服务器使用浏览器需要输入IP_ADDRESS:23188来进行访问。
Active节点可访问正常。如下图:
Standby节点web自动跳转至Active几点。如下图:
登jobhistory服务器web端查看job状态
我们通过参数设置了hadoop001为historyserver。
此时登陆http://hadoop001:19888查看web界面。可通过日志查看已执行完的job运行状况。
这里如果PC连接服务器使用浏览器需要输入IP_ADDRESS:19888来进行访问。
/部署为三篇:
- 软件版本、系统环境、jdk、scala、zookeeper
https://www.jianshu.com/p/8a1f1b40073f - hadoop安装
https://www.jianshu.com/p/c88c208ba68c - Kafka Spark Flume安装
https://www.jianshu.com/p/ea8c2a4e0bf8