1.下载解压hadoop2.6

tar  -zxvf  hadoop-2.6.0.tar.gz

2.修改hadoop-env.sh

export JAVA_HOME=/usr/local/jdk1.7.0_80
export  HADOOP_CLASSPATH=$HADOOP_CLASSPATH:/usr/local/hbase-0.98.15/lib/*

3.修改yarn-env.sh、

export JAVA_HOME=/usr/local/jdk1.7.0_80
export YARN_LOG_DIR=/usr/local/hadoop-2.6.0/logs/hadoop

4.修改core-site.xml

<configuration>
        <!-- 指定hdfs的nameservice为cluster-->
    <property>
                <name>fs.defaultFS</name>
                <value>hdfs://cluster</value>
        </property>
        <property>
                <name>io.file.buffer.size</name>
                <value>131072</value>
        </property>
        <!-- 指定hadoop临时目录 -->
        <property>
                <name>hadoop.tmp.dir</name>
                <value>/usr/local/hadoop-2.6.0/tmp</value>
        </property>
        <!--指定可以在任何IP访问-->
        <property>
                <name>hadoop.proxyuser.hduser.hosts</name>
                <value>*</value>
        </property>
        <!--指定所有用户可以访问-->
        <property>
                <name>hadoop.proxyuser.hduser.groups</name>
                <value>*</value>
        </property>
        <!-- 指定zookeeper地址 -->
        <property>
                <name>ha.zookeeper.quorum</name>
                <value>node01:2181,node02:2181,node03:2181</value>
        </property>
        <property>    
                <name>fs.trash.interval</name>
                <value>1440</value>
                <description>save one day(1440 min---60*24)</description>
        </property>
</configuration>

4.修改hdfs-site.xml

<configuration>
        <!--一个Hadoop HDFS Datanode 有一个同时处理文件的上限-->
        <property>
                <name>dfs.datanode.max.xcievers</name>
                <value>4096</value>
        </property>
        <!--指定hdfs的nameservice为cluster,需要和core-site.xml中的保持一致 -->
        <property>
                <name>dfs.nameservices</name>
                <value>cluster</value>
        </property>
        <!-- cluster下面有两个NameNode,分别是node01,node02-->
        <property>
                <name>dfs.ha.namenodes.cluster</name>
                <value>node01,node02</value>
        </property>
        <!-- node01的RPC通信地址 -->
        <property>
                <name>dfs.namenode.rpc-address.cluster.node01</name>
                <value>node01:9000</value>
        </property>
        <!-- node01的http通信地址 -->
        <property>
                <name>dfs.namenode.http-address.cluster.node01</name>
                <value>node01:50070</value>
        </property>
        <!--node02的RPC通信地址 -->
        <property>
                <name>dfs.namenode.rpc-address.cluster.node02</name>
                <value>node02:9000</value>
        </property>
        <!--node02的http通信地址 -->
        <property>
                <name>dfs.namenode.http-address.cluster.node02</name>
                <value>node02:50070</value>
        </property>
        <!-- 指定NameNode的元数据在JournalNode上的存放位置 -->
        <property>
                <name>dfs.namenode.shared.edits.dir</name>
                <value>qjournal://node01:8485;node02:8485;node03:8485/cluster</value>
        </property>
        <!--NameNode的元数据在JournalNode上的存放位置-->
        <property>
                <name>dfs.journalnode.edits.dir</name>
                <value>/usr/local/hadoop-2.6.0/tmp/journal</value>
        </property>
        <!-- 配置隔离机制方法,多个机制用换行分割,即每个机制占用一行-->
        <property>
                <name>dfs.ha.fencing.methods</name>
                <value>sshfence</value>
        </property>
        <!-- 使用sshfence隔离机制时需要ssh免登陆 -->
        <property>
                <name>dfs.ha.fencing.ssh.private-key-files</name>
                <value>/root/.ssh/id_rsa</value>
        </property>
        <!-- 配置sshfence隔离机制超时时间 -->
        <property>
                <name>dfs.ha.fencing.ssh.connect-timeout</name>
                <value>30000</value>
        </property>
        <!--指定支持高可用自动切换机制-->
        <property>
                <name>dfs.ha.automatic-failover.enabled.cluster</name>
                <value>true</value>
        </property>
        <!-- 配置失败自动切换实现方式 -->
        <property>
                <name>dfs.client.failover.proxy.provider.cluster</name>
                <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
        </property>
        <!--指定namenode名称空间的存储地址-->
        <property>
                <name>dfs.namenode.name.dir</name>
                <value>/usr/local/hadoop-2.6.0/tmp/dfs/name</value>
        </property>
        <!--指定datanode数据存储地址-->
        <property>
                <name>dfs.datanode.data.dir</name>
                <value>/usr/local/hadoop-2.6.0/tmp/dfs/data</value>
        </property>
        <!--指定数据冗余份数-->
        <property>
                <name>dfs.replication</name>
                <value>3</value>
        </property>
        <!--指定可以通过web访问hdfs目录-->
        <property>
                <name>dfs.webhdfs.enabled</name>
                <value>true</value>
        </property>
        <!--保证数据恢复 -->
        <property>
                <name>dfs.journalnode.http-address</name>
                <value>0.0.0.0:8480</value>
        </property>
        <property>
                <name>dfs.journalnode.rpc-address</name>
                <value>0.0.0.0:8485</value>
        </property>
        <property>
                <name>ha.zookeeper.quorum</name>
                <value>node01:2181,node02:2181,node03:2181</value>
        </property>
        <!--关闭hdfs权限验证-->
        <property>
                <name>dfs.permissions</name>
                <value>false</value>
        </property>
</configuration>

配置YARN

将mapred-site.xml.templat重命名成mapred-site.xml

5.修改mapred-site.xml

<configuration>
        <!-- 指定mr框架为yarn方式 -->
        <property>
                <name>mapreduce.framework.name</name>
                <value>yarn</value>
        </property>
                <!-- 配置 MapReduce JobHistory Server 地址 ,默认端口10020 -->
        <property>
                <name>mapreduce.jobhistory.address</name>
                <value>node01:10020</value>
        </property>
        <!-- 配置 MapReduce JobHistory Server web ui 地址, 默认端口19888 -->
        <property>
                <name>mapreduce.jobhistory.webapp.address</name>
                <value>node01:19888</value>
        </property>
</configuration>

6.修改yarn-site.xml

<configuration>

<!-- Site specific YARN configuration properties -->
    <!--rm失联后重新链接的时间-->
        <property>
                <name>yarn.resourcemanager.connect.retry-interval.ms</name>
                <value>2000</value>
        </property>
        <!--开启resource manager HA,默认为false-->
        <property>
                <name>yarn.resourcemanager.ha.enabled</name>
                <value>true</value>
        </property>
        <!--配置resource manager -->
        <property>
                <name>yarn.resourcemanager.ha.rm-ids</name>
                <value>rm1,rm2</value>
        </property>
        <property>
                <name>ha.zookeeper.quorum</name>
                <value>node01:2181,node02:2181,node03:2181</value>
        </property>
        <!--开启故障自动切换-->
        <property>
                <name>yarn.resourcemanager.ha.automatic-failover.enabled</name>
                <value>true</value>
        </property>
        <property>
                <name>yarn.resourcemanager.hostname.rm1</name>
                <value>node01</value>
        </property>          
        <property>
                <name>yarn.resourcemanager.hostname.rm2</name>
                <value>node02</value>
        </property>
        <!--在namenode1上配置rm1,在namenode2上配置rm2,注意:一般都喜欢把配置好的文件远程复制到其它机器上,但这个在YARN的另一个机器上一定要修改-->
        <property>
                <name>yarn.resourcemanager.ha.id</name>
                <value>rm1</value>
                <description>If we want to launch more than one RM in single node, we need this configuration</description>
        </property>
        <!--开启自动恢复功能-->
        <property>
                <name>yarn.resourcemanager.recovery.enabled</name>
                <value>true</value>
        </property>
        <!--配置与zookeeper的连接地址-->
        <property>
                <name>yarn.resourcemanager.zk-state-store.address</name>
                <value>node01:2181,node02:2181,node03:2181</value>
        </property>
        <property>
                <name>yarn.resourcemanager.store.class</name>
                <value>org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore</value>
        </property>
        <property>
                <name>yarn.resourcemanager.zk-address</name>
                <value>node01:2181,node02:2181,node03:2181</value>
        </property>
        <property>
                <name>yarn.resourcemanager.cluster-id</name>
        <value>RM_HA_ID</value>
        </property>
        <!--schelduler失联等待连接时间-->
        <property>
                <name>yarn.app.mapreduce.am.scheduler.connection.wait.interval-ms</name>
                <value>5000</value>
        </property>
        <!--配置rm1-->
        <property>
                <name>yarn.resourcemanager.address.rm1</name>
                <value>node01:8132</value>
        </property>
        <property>
                <name>yarn.resourcemanager.scheduler.address.rm1</name>
                <value>node01:8130</value>
        </property>
        <property>
                <name>yarn.resourcemanager.webapp.address.rm1</name>
                <value>node01:8188</value>
        </property>
        <property>
                <name>yarn.resourcemanager.resource-tracker.address.rm1</name>
                <value>node01:8131</value>
        </property>
        <property>
                <name>yarn.resourcemanager.admin.address.rm1</name>
                <value>node01:8033</value>
        </property>
        <property>
                <name>yarn.resourcemanager.ha.admin.address.rm1</name>
                <value>node01:23142</value>
        </property>
        <!--配置rm2-->
        <property>
                <name>yarn.resourcemanager.address.rm2</name>
                <value>node02:8132</value>
        </property>
        <property>
                <name>yarn.resourcemanager.scheduler.address.rm2</name>
                <value>node02:8130</value>
        </property>
        <property>
                <name>yarn.resourcemanager.webapp.address.rm2</name>
                <value>node02:8188</value>
        </property>
        <property>
                <name>yarn.resourcemanager.resource-tracker.address.rm2</name>
                <value>node02:8131</value>
        </property>
        <property>
                <name>yarn.resourcemanager.admin.address.rm2</name>
        <value>node02:8033</value>
        </property>
        <property>
                <name>yarn.resourcemanager.ha.admin.address.rm2</name>
                <value>node02:23142</value>
        </property>
        <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>
        <property>
                <name>yarn.nodemanager.local-dirs</name>
                <value>/usr/local/hadoop-2.6.0/tmp/yarn/local</value>
        </property>
        <property>
                <name>yarn.nodemanager.log-dirs</name>
                <value>/usr/local/hadoop-2.6.0/tmp/log/hadoop</value>
        </property>
        <property>
                <name>mapreduce.shuffle.port</name>
                <value>23080</value>
        </property>
        <!--故障处理类-->
        <property>
                <name>yarn.client.failover-proxy-provider</name>
                <value>org.apache.hadoop.yarn.client.ConfiguredRMFailoverProxyProvider</value>
        </property>
        <property>
                <name>yarn.resourcemanager.ha.automatic-failover.zk-base-path</name>
                <value>/yarn-leader-election</value>
                <description>Optional setting. The default value is /yarn-leader-election</description>
        </property>
    <property>
        <name>yarn.log-aggregation-enable</name>
        <value>true</value>
    </property>
</configuration>

7.修改slaves
(slaves是指定子节点的位置, slaves文件指定的是datanode的位置, slaves文件指定的是nodemanager的位置)

node01
node02
node03

8.复制hadoop文件夹到其他节点
将node01节点上的hadoop 文件夹复制到其他节点

scp -rq /usr/local/hadoop-2.6.0/  root@node02:/usr/local/
scp -rq /usr/local/hadoop-2.6.0/  root@node03:/usr/local/

格式化hdfs、namenode启动集群
1.格式化ZK集群:

hadoop/bin/hdfs zkfc –formatZK

2.启动journalnode集群
在node01、node02、node03节点分别执行

hadoop/sbin/hadoop-daemon.sh start journalnode

3.格式化namenode、启动namenode
在node01上执行

hadoop/bin/hdfs namenode -format

在node01上启动

hadoop/sbin/hadoop-daemon.sh start namenode

在node02上执行

hadoop/bin/hdfs namenode -bootstrapStandby

在node02上启动

hadoop/sbin/hadoop-daemon.sh start namenode

4.启动datanode
在node01上执行

hadoop/sbin/hadoop-daemons.sh start datanode

5.启动ZKFC

sbin/hadoop-daemon.sh start zkfc

6.启动Yarn
执行命令

/sbin/start-yarn.sh

在node02启动yarn(HA模式启动不了需要单独启动)

yarn-daemon.sh start resourcemanager

7.启动JobHistoryServer
在node01节点执行

mr-jobhistory-daemon.sh start historyserver

yarn的管理地址 http://192.168..:8188/cluster