1:配置免密码登录
使用ssh-keygen生成密钥,会在当前目录下生成一个.ssh文件夹和id_rsa私钥公钥;
把公钥拷贝到同一台主机对应的.ssh目录下,然后加载进authorized_keys文件里
cat id_rsa.pub>>authorized_keys //所有的公钥都要追加进这个文件;
把authorized_keys文件拷贝到每台主机的.ssh目录;然后逐个登录一次
也可以使用ssh-copy-id myuser@mynode
2:安装zookeeper;配置conf/zoo.cfg;添加每个主机和myid;
启动zookeeper:bin/zkServer.sh start
3:如果java是通过下载压缩包的形式的,那么需要配置一下系统环境
vim /etc/profile
添加:
export JAVA_HOME=/home/hadoop/jdk1.7.0_80
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
source /etc/profile
4:修改hadoop配置文件:
配置文件都在hadoop安装目录下的etc/hadoop/目录下
core-site.xml文件:


 
 
     fs.defaultFS
     hdfs://mycluster //hdfs-site.xml配置文件里对应的名称
 
 
 
     dfs.journalnode.edits.dir
     /var/hadoop/jn //需要创建jn/mycluster文件夹
 

 
 
    hadoop.tmp.dir
    /var/hadoop/tmp
 

hdfs-site.xml



 
     dfs.nameservices
     mycluster
 

 
 
     dfs.ha.namenodes.mycluster
     nn1,nn2
 

 
 
     dfs.namenode.rpc-address.mycluster.nn1
     master:8020
 
 
     dfs.namenode.rpc-address.mycluster.nn2
     slave-one:8020
 

 
 
     dfs.namenode.http-address.mycluster.nn1
     master:50070
 
 
     dfs.namenode.http-address.mycluster.nn2
     slave-one:50070
 

 
 
     dfs.namenode.shared.edits.dir
 qjournal://master:8485;slave-one:8485;slave-two:8485/mycluster
 

 
 
     dfs.client.failover.proxy.provider.mycluster
     org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider
 

 
    
            dfs.ha.fencing.methods
            sshfence
        
 
        
            dfs.ha.fencing.ssh.private-key-files
            /root/.ssh/id_rsa
        

 
 
    dfs.replication
    3
 

 
 
    dfs.permissions.enabled
    false
 

 
 
        dfs.ha.automatic-failover.enabled
        true
    

    
    
        ha.zookeeper.quorum
        master:2181,slave-one:2181,slave-two:2181
    



                dfs.namenode.secondary.http-address
                master:50090
        
        
                dfs.namenode.name.dir
                /var/hadoop/dfs/name
        
        
                dfs.datanode.data.dir
                /var/hadoop/dfs/data
        
        
                dfs.replication
                2
        

配置mapred-site.xml文件:


        
                mapreduce.framework.name
                yarn
         
         
                mapreduce.jobhistory.address 
                master:10020 
         
         
                mapreduce.jobhistory.webapp.address 
                master:19888 
         
         
                mapreduce.job.ubertask.enable 
                true 
        

配置yarn-site.xml文件



    yarn.resourcemanager.ha.enabled
    true


    yarn.resourcemanager.cluster-id
    cluster1


    yarn.resourcemanager.ha.rm-ids
    rm1,rm2


    yarn.resourcemanager.hostname.rm1
    master


    yarn.resourcemanager.hostname.rm2
    slave-one


    yarn.resourcemanager.webapp.address.rm1
    master:8088


    yarn.resourcemanager.webapp.address.rm2
    slave-one:8088


    yarn.resourcemanager.zk-address
    master:2181,slave-one:2181,slave-two:2181


    yarn.resourcemanager.store.class
    org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore


    yarn.nodemanager.recovery.enabled
    true


    yarn.nodemanager.recovery.dir
    /var/hadoop/yarn-recovery


    yarn.nodemanager.address
    45454


 yarn.nodemanager.aux-services
 mapreduce_shuffle


 yarn.log-aggregation-enable
 true

创建文件夹:
mkdir -p /var/hadoop/jn/mycluster mkdir -p /var/hadoop/tmp mkdir -p /var/hadoop/dfs/name mkdir -p /var/hadoop/dfs/data mkdir -p /var/hadoop/yarn-recovery
配置hadoop-env.sh的java_home路径:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0
配置slaves文件:添加所有节点主机
master
slave-one
slave-two
5:每一台机子上都启动journalnode节点:为格式化做准备
sbin/hadoop-daemon.sh start journalnode
6:在一台主机上格式化namenode:
bin/hdfs namenode -format mycluster
7:在该台主机格式化完namenode后,启动namenode,方便给其他主机同步namenode信息
sbin/hadoop-daemon.sh start namenode
8:在其他主机上同步namenode信息:由于namenode节点只需要两个,所以只同步配置里的主机
bin/hdfs namenode -bootstrapstandby
如果同步成功,可以看到集群的id等相关信息;如果不成功;查看主机监控的地址是否有误;
如果监听127.0.0.1会导致连接不上,修改/etc/hosts文件
9:配置zookeeper故障转移:对namenode进行zk格式化;需要确保namenode进行已经启动
在一台主机上运行:
bin/hdfs zkfc -formatZK
10:关闭所有hdfs:sbin/stop-dfs.sh;然后再重新启动所有sbin/start-dfs.sh
11:配置yarn:需要在每一台ResourceManager上启动
sbin/yarn-daemon.sh start resourcemanager
12:查看yarn启动状态:
bin/yarn rmadmin -getServiceState rm1|rm2 //rm1,rm2是定义的名称

当前版本一个Namespace只运行最多两个namenode节点;例如mycluster只能有nn1和nn2两个namenode节点;nn1和nn2名称可以自己命名;