主机名 | IP | 安装的软件 | 运行的进程 |
---|---|---|---|
mini1 | 192.168.1.200 | jdk、hadoop | NameNode、DFSZKFailoverController(zkfc) |
mini2 | 192.168.1.201 | jdk、hadoop | NameNode、DFSZKFailoverController(zkfc) |
mini3 | 192.168.1.202 | jdk、hadoop | ResourceManager |
mini4 | 192.168.1.203 | jdk、hadoop | ResourceManager |
mini5 | 192.168.1.205 | jdk、hadoop、zookeeper | DataNode、NodeManager、JournalNode、QuorumPeerMain |
mini6 | 192.168.1.206 | jdk、hadoop、zookeeper | DataNode、NodeManager、JournalNode、QuorumPeerMain |
mini7 | 192.168.1.207 | jdk、hadoop、zookeeper | DataNode、NodeManager、JournalNode、QuorumPeerMain |
tar -zxvf zookeeper-3.4.5.tar.gz -C /home/hadoop/app/
将zoo_sample.cfg文件重命名为zoo.cfg
cd /home/hadoop/app/zookeeper-3.4.5/conf/
cp zoo_sample.cfg zoo.cfg
修改zoo.cfg文件
vi zoo.cfg
#修改:
dataDir=/home/hadoop/app/zookeeper-3.4.5/tmp
#在最后添加:
server.1=mini05:2888:3888
server.2=mini06:2888:3888
server.3=mini07:2888:3888
保存退出
然后创建一个tmp文件夹
mkdir /home/hadoop/app/zookeeper-3.4.5/tmp
echo 1 > /home/hadoop/app/zookeeper-3.4.5/tmp/myid
将配置好的zookeeper拷贝到其他节点(首先分别在mini06、mini07根目录下创建一个hadoop目录:mkdir /hadoop)
分别拷贝到mini06、mini07 :
scp -r /home/hadoop/app/zookeeper-3.4.5/ mini06:/home/hadoop/app/
scp -r /home/hadoop/app/zookeeper-3.4.5/ mini07:/home/hadoop/app/
注意:修改mini06、mini07对应/hadoop/zookeeper-3.4.5/tmp/myid内容.
mini06:
echo 2 > /home/hadoop/app/zookeeper-3.4.5/tmp/myid
mini07:
echo 3 > /home/hadoop/app/zookeeper-3.4.5/tmp/myid
tar -zxvf hadoop-2.7.3.tar.gz -C /home/hadoop/app/
将hadoop添加到环境变量中
vi /etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_102
export HADOOP_HOME=/hadoop/hadoop-2.7.3
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
hadoop2.0的配置文件全部在$HADOOP_HOME/etc/hadoop下,所以需要先进入/home/hadoop/app/hadoop-2.7.3/etc/hadoop目录,下面的文件修改就不在描述进入/home/hadoop/app/hadoop-2.7.3/etc/hadoop了
cd /home/hadoop/app/hadoop-2.7.3/etc/hadoop
然后修改hadoo-env.sh
主要修改使用的jdk
export JAVA_HOME=/home/hadoop/app/jdk1.8.0_102
注意这里面已经把HDFS访问路径抽象出来一个统一的访问接口了
<configuration>
<property>
<name>fs.defaultFSname>
<value>hdfs://bi/value>
property>
<property>
<name>hadoop.tmp.dirname>
<value>/home/hadoop/app/hdpdata/value>
property>
<property>
<name>ha.zookeeper.quorumname>
<value>mini5:2181,mini6:2181,mini7:2181value>
property>
configuration>
<configuration>
<property>
<name>dfs.nameservicesname>
<value>bivalue>
property>
<property>
<name>dfs.ha.namenodes.biname>
<value>nn1,nn2value>
property>
<property>
<name>dfs.namenode.rpc-address.bi.nn1name>
<value>mini1:9000value>
property>
<property>
<name>dfs.namenode.http-address.bi.nn1name>
<value>mini1:50070value>
property>
<property>
<name>dfs.namenode.rpc-address.bi.nn2name>
<value>mini2:9000value>
property>
<property>
<name>dfs.namenode.http-address.bi.nn2name>
<value>mini2:50070value>
property>
<property>
<name>dfs.namenode.shared.edits.dirname>
<value>qjournal://mini5:8485;mini6:8485;mini7:8485/bivalue>
property>
<property>
<name>dfs.journalnode.edits.dirname>
<value>/home/hadoop/journaldatavalue>
property>
<property>
<name>dfs.ha.automatic-failover.enabledname>
<value>truevalue>
property>
<property>
<name>dfs.client.failover.proxy.provider.biname>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvidervalue>
property>
<property>
<name>dfs.ha.fencing.methodsname>
<value>
sshfence
shell(/bin/true)
value>
property>
<property>
<name>dfs.ha.fencing.ssh.private-key-filesname>
<value>/home/hadoop/.ssh/id_rsavalue>
property>
<property>
<name>dfs.ha.fencing.ssh.connect-timeoutname>
<value>30000value>
property>
configuration>
<configuration>
<property>
<name>mapreduce.framework.namename>
<value>yarnvalue>
property>
configuration>
<configuration>
<property>
<name>yarn.resourcemanager.ha.enabledname>
<value>truevalue>
property>
<property>
<name>yarn.resourcemanager.cluster-idname>
<value>yrcvalue>
property>
<property>
<name>yarn.resourcemanager.ha.rm-idsname>
<value>rm1,rm2value>
property>
<property>
<name>yarn.resourcemanager.hostname.rm1name>
<value>mini3value>
property>
<property>
<name>yarn.resourcemanager.hostname.rm2name>
<value>mini4value>
property>
<property>
<name>yarn.resourcemanager.zk-addressname>
<value>mini5:2181,mini6:2181,mini7:2181value>
property>
<property>
<name>yarn.nodemanager.aux-servicesname>
<value>mapreduce_shufflevalue>
property>
configuration>
mini5
mini6
mini7
scp -r /hadoop/ mini02:/
scp -r /hadoop/ mini03:/
scp -r /hadoop/hadoop-2.7.3/ hadoop@mini04:/hadoop/
scp -r /hadoop/hadoop-2.7.3/ hadoop@mini05:/hadoop/
scp -r /hadoop/hadoop-2.7.3/ hadoop@mini06:/hadoop/
scp -r /hadoop/hadoop-2.7.3/ hadoop@mini07:/hadoop/
首次启动严格按照以下顺序启动,应为需要格式化集群
启动zookeeper
cd /hadoop/zookeeper-3.4.5/bin/
./zkServer.sh start
查看启动状态,一个leader,两个follower
./zkServer.sh status
执行
cd /hadoop/hadoop-2.7.3
sbin/hadoop-daemon.sh start journalnode
运行jps命令检验,mini05、mini06、mini07上多了JournalNode进程就是ok的了
在mini1上执行命令:
hdfs namenode -format
格式化后会在根据core-site.xml中的hadoop.tmp.dir配置生成个文件,这里我配置的是/hadoop/hadoop-2.7.3/tmp,然后将/hadoop/hadoop-2.7.3/tmp拷贝到mini02的/hadoop/hadoop-2.7.3/下。
拷贝数据可以使用命令:
scp -r tmp/ mini02:/home/hadoop/app/hadoop-2.7.3/
也可以使用以下命令进行数据拷贝:
hdfs namenode -bootstrapStandby
在mini1上执行一次即可
hdfs zkfc -formatZK
在mini01上执行
sbin/start-dfs.sh
mini02上执行
sbin/start-yarn.sh
到此hadoop的配置已经配置完毕,可以进行HA验证,进行浏览器访问:
集群再次启动就不要那么繁琐了,只需要一次启动