7台虚拟机HA高可用配置详细过程

1.修改Linux主机名
2.修改IP
3.修改主机名和IP的映射关系

一点要关闭防火墙

4.关闭防火墙
5.ssh免登陆
6.安装JDK,配置环境变量等

集群规划:
主机名 IP 安装的软件 运行的进程
weekend01 192.168.1.201 jdk、hadoop NameNode、DFSZKFailoverController(zkfc)
weekend02 192.168.1.202 jdk、hadoop NameNode、DFSZKFailoverController(zkfc)
weekend03 192.168.1.203 jdk、hadoop ResourceManager
weekend04 192.168.1.204 jdk、hadoop ResourceManager
weekend05 192.168.1.205 jdk、hadoop、zookeeper DataNode、NodeManager、JournalNode、QuorumPeerMain
weekend06 192.168.1.206 jdk、hadoop、zookeeper DataNode、NodeManager、JournalNode、QuorumPeerMain
weekend07 192.168.1.207 jdk、hadoop、zookeeper DataNode、NodeManager、JournalNode、QuorumPeerMain

说明:
1.在hadoop2.0中通常由两个NameNode组成,一个处于active状态,另一个处于standby状态。Active NameNode对外提供服务,而Standby NameNode则不对外提供服务,仅同步active namenode的状态,以便能够在它失败时快速进行切换。
hadoop2.0官方提供了两种HDFS HA的解决方案,一种是NFS,另一种是QJM。这里我们使用简单的QJM。在该方案中,主备NameNode之间通过一组JournalNode同步元数据信息,一条数据只要成功写入多数JournalNode即认为写入成功。通常配置奇数个JournalNode
这里还配置了一个zookeeper集群,用于ZKFC(DFSZKFailoverController)故障转移,当Active NameNode挂掉了,会自动切换Standby NameNode为standby状态
2.hadoop-2.2.0中依然存在一个问题,就是ResourceManager只有一个,存在单点故障,hadoop-2.4.1解决了这个问题,有两个ResourceManager,一个是Active,一个是Standby,状态由zookeeper进行协调
安装步骤:
1.安装配置zooekeeper集群(在weekend05上)
1.1解压
tar -zxvf zookeeper-3.4.5.tar.gz -C /usr/local/
1.2修改配置
cd /usr/local/zookeeper-3.4.5/conf/
cp zoo_sample.cfg zoo.cfg
vim zoo.cfg
修改:dataDir=/usr/local/zookeeper-3.4.5/tmp
在最后添加:
server.1=weekend05:2888:3888
server.2=weekend06:2888:3888
server.3=weekend07:2888:3888
保存退出
然后创建一个tmp文件夹
mkdir /usr/local/zookeeper-3.4.5/tmp
再创建一个空文件
touch /usr/local/zookeeper-3.4.5/tmp/myid
最后向该文件写入ID
echo 1 > /usr/local/zookeeper-3.4.5/tmp/myid
1.3将配置好的zookeeper拷贝到其他节点
scp -r /usr/local/zookeeper-3.4.5/ weekend06:/usr/local/
scp -r /usr/local/zookeeper-3.4.5/ weekend07:/usr/local/

        注意:修改weekend06、weekend07对应/weekend/zookeeper-3.4.5/tmp/myid内容
        weekend06:
            echo 2 > /usr/local/zookeeper-3.4.5/tmp/myid
        weekend07:
            echo 3 > /usr/local/zookeeper-3.4.5/tmp/myid

2.安装配置hadoop集群(在weekend01上操作)
    2.1解压
        tar -zxvf hadoop-2.7.3.tar.gz -C /usr/local/
    2.2配置HDFS(hadoop2.X所有的配置文件都在$HADOOP_HOME/etc/hadoop目录下)
        #将hadoop添加到环境变量中
        vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0_141
export HADOOP_HOME=/usr/local/hadoop-2.7.3
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin

        #hadoop2.X的配置文件全部在$HADOOP_HOME/etc/hadoop下
        cd /usr/local/hadoop-2.7.3/etc/hadoop

        2.2.1修改hadoo-env.sh
            export JAVA_HOME=/usr/local/jdk1.8.0_141

        2.2.2修改core-site.xml
            
                
                
                    fs.defaultFS
                    hdfs://ns1
                
                
                
                    hadoop.tmp.dir
                    /usr/local/hadoop-2.7.3/dfs
                

                
                
                    ha.zookeeper.quorum
                    weekend05:2181,weekend06:2181,weekend07:2181
                
            

        2.2.3修改hdfs-site.xml
            
                
                
                    dfs.nameservices
                    ns1
                
                
                
                    dfs.ha.namenodes.ns1
                    nn1,nn2
                
                
                
                    dfs.namenode.rpc-address.ns1.nn1
                    weekend01:9000
                
                
                
                    dfs.namenode.http-address.ns1.nn1
                    weekend01:50070
                
                
                
                    dfs.namenode.rpc-address.ns1.nn2
                    weekend02:9000
                
                
                
                    dfs.namenode.http-address.ns1.nn2
                    weekend02:50070
                
                
                
                    dfs.namenode.shared.edits.dir
                    qjournal://weekend05:8485;weekend06:8485;weekend07:8485/ns1
                
                
                
                    dfs.journalnode.edits.dir
                    /usr/local/hadoop-2.7.3/journaldata
                
                
                
                    dfs.ha.automatic-failover.enabled
                    true
                
                
                
                    dfs.client.failover.proxy.provider.ns1
                    org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider
                
                
                
                    dfs.ha.fencing.methods
                    
                        sshfence
                        shell(/bin/true)
                    
                
                
                
                    dfs.ha.fencing.ssh.private-key-files
                    /home/hadoop/.ssh/id_rsa
                
                
                
                    dfs.ha.fencing.ssh.connect-timeout
                    30000
                
            

        2.2.4修改mapred-site.xml
            
                
                
                    mapreduce.framework.name
                    yarn
                
                

        2.2.5修改yarn-site.xml
            
                    
                    
                       yarn.resourcemanager.ha.enabled
                       true
                    
                    
                    
                       yarn.resourcemanager.cluster-id
                       yrc
                    
                    
                    
                       yarn.resourcemanager.ha.rm-ids
                       rm1,rm2
                    
                    
                    
                       yarn.resourcemanager.hostname.rm1
                       weekend03
                    
                    
                       yarn.resourcemanager.hostname.rm2
                       weekend04
                    
                    
                    
                       yarn.resourcemanager.zk-address
                       weekend05:2181,weekend06:2181,weekend07:2181
                    
                    
                       yarn.nodemanager.aux-services
                       mapreduce_shuffle
                    
            


        2.2.6修改slaves(slaves是指定子节点的位置,因为要在weekend01上启动HDFS、在weekend03启动yarn,所以weekend01上的slaves文件指定的是datanode的位置,weekend03上的slaves文件指定的是nodemanager的位置)
            weekend05
            weekend06
            weekend07

        2.2.7配置免密码登陆
            #首先要配置weekend01到weekend02、weekend03、weekend04、weekend05、weekend06、weekend07的免密码登陆
            #在weekend01上生产一对钥匙
            ssh-keygen -t rsa
            #将公钥拷贝到其他节点,包括自己
            ssh-coyp-id -i ~/.ssh/id_rsa.pub  hadoop@weekend01
            .....
            ssh-coyp-id -i ~/.ssh/id_rsa.pub  hadoop@weekend07
            #配置weekend03到weekend04、weekend05、weekend06、weekend07的免密码登陆
            #在weekend03上生产一对钥匙
            ssh-keygen -t rsa
            #将公钥拷贝到其他节点
            ssh-coyp-id -i ~/.ssh/id_rsa.pub  hadoop@weekend04、weekend05、weekend06、weekend07的免密码登陆
            #在weekend03上生产一对钥匙
            ssh-keygen -t rsa
            #将公钥拷贝到其他节点
            ssh-coyp-id -i ~/.ssh/id_rsa.pub  hadoop@weekend03、weekend05、weekend06、weekend07的免密码登陆
            #注意:两个namenode之间要配置ssh免密码登陆,别忘了配置weekend02到weekend01的免登陆
            在weekend02上生产一对钥匙
            ssh-keygen -t rsa
            ssh-coyp-id -i ~/.ssh/id_rsa.pub hadoop@weekend01              

    2.4将配置好的hadoop拷贝到其他节点
        scp -r   hadoop-2.7.3  hadoop@weekend02:/usr/local/
        scp -r   hadoop-2.7.3  hadoop@weekend03:/usr/local/
        scp -r   hadoop-2.7.3  hadoop@weekend04:/usr/local/
        scp -r   hadoop-2.7.3  hadoop@weekend05:/usr/local/
        scp -r   hadoop-2.7.3  hadoop@weekend06:/usr/local/
        scp -r   hadoop-2.7.3  hadoop@weekend07:/usr/local/
    ###注意:严格按照下面的步骤
    2.5启动zookeeper集群(分别在weekend05、weekend06、weekend07上启动zk)
        cd /home/hadoop/app/zookeeper-3.4.5/bin/
        ./zkServer.sh start
        #查看状态:一个leader,两个follower
        ./zkServer.sh status

    2.6启动journalnode(分别在在weekend05、weekend06、weekend07上执行)
        cd /home/hadoop/app/hadoop-2.4.1
        sbin/hadoop-daemon.sh start journalnode
        #运行jps命令检验,weekend05、weekend06、weekend07上多了JournalNode进程

    2.7格式化HDFS
        #在weekend01上执行命令:
        hdfs namenode -format
        #格式化后会在根据core-site.xml中的hadoop.tmp.dir配置生成个文件,这里我配置的是/usr/local/hadoop-2.7.3/dfs,然后将/usr/local/hadoop-2.7.3/dfs拷贝到/usr/local/hadoop-2.7.3/下。
        scp -r dfs/ weekend02:/usr/local/hadoop-2.7.3/


    2.8格式化ZKFC(在weekend01上执行即可)
        hdfs zkfc -formatZK

    2.9启动HDFS(在weekend01上执行)
        sbin/start-dfs.sh

    2.10启动YARN(#####注意#####:是在weekend03上执行start-yarn.sh,把namenode和resourcemanager分开是因为性能问题,因为他们都要占用大量资源,所以把他们分开了,他们分开了就要分别在不同的机器上启动)
        sbin/start-yarn.sh(weekend03上执行)
        yarn-demon.sh  start  resourcemanager(weekend04上手动启动)

到此,hadoop-2.7.3配置完毕,可以统计浏览器访问:
    http://192.168.1.201:50070
    NameNode 'weekend01:9000' (active)
    http://192.168.1.202:50070
    NameNode 'weekend02:9000' (standby)

验证HDFS HA
    首先向hdfs上传一个文件
    hadoop fs -put /etc/profile /profile
    hadoop fs -ls /
    然后再kill掉active的NameNode
    kill -9 
    通过浏览器访问:http://192.168.1.202:50070
    NameNode 'weekend02:9000' (active)
    这个时候weekend02上的NameNode变成了active
    在执行命令:
    hadoop fs -ls /
    刚才上传的文件依然存在!!!
    手动启动那个挂掉的NameNode
    sbin/hadoop-daemon.sh start namenode
    通过浏览器访问:http://192.168.1.201:50070
    NameNode 'weekend01:9000' (standby)

验证YARN:
    运行一下hadoop提供的demo中的WordCount程序:
    hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar wordcount /profile /out


验证YARN:HA

    打开http://weekend01:8088   页面可以显示ResourceManager HA state:   active
    打开http://weekend02:8080   页面自动跳转http://weekend01:8088 (window上hosts文件需配置ip映射关系,否则无法访问网页)

    kill -9   weekend02上的 http://weekend02:8080 页面可以显示ResourceManager HA state:   active
    手动启动weekend01上的resourcemanger  http://weekend01:8088 页面上显示ResourceManager HA state: standby

OK,大功告成!!!

测试集群工作状态的一些指令 :
bin/hdfs dfsadmin -report 查看hdfs的各节点状态信息

bin/hdfs haadmin -getServiceState nn1 获取一个namenode节点的HA状态

sbin/hadoop-daemon.sh start namenode 单独启动一个namenode进程

./hadoop-daemon.sh start zkfc 单独启动一个zkfc进程

你可能感兴趣的:(7台虚拟机HA高可用)