[hadoop@cloud07 bin]$ ./zkServer.sh status
JMX enabled by default
Using config: /home/hadoop/app/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: follower
2.安装配置hadoop集群
2.1解压
tar -zxvf hadoop-2.4.1.tar.gz -C /home/hadoop/app/
2.2配置HDFS(hadoop2.4.1所有的配置文件都在$HADOOP_HOME/etc/hadoop目录下)
#将hadoop添加到环境变量中
vim /etc/profile
export JAVA_HOME=/usr/java/jdk1.7.0_55
export HADOOP_HOME=/home/hadoop/app/hadoop-2.4.1
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin
在cloud01上配置JAVA和Hadoop,拷贝/etc/profile到其它的机器上,可以通过以下命令实现
[hadoop@cloud01 ~]$ sudo scp -r /etc/profile root@cloud02:/etc/profile
2.2.1修改hadoo-env.sh
export JAVA_HOME=/home/hadoop/app/jdk1.7.0_65
2.2.2修改core-site.xml
fs.defaultFS
hdfs://ns1
hadoop.tmp.dir
/home/hadoop/app/hadoop-2.4.1/tmp
ha.zookeeper.quorum
cloud05:2181,cloud06:2181,cloud07:2181
2.2.3修改hdfs-site.xml
dfs.nameservices
ns1
dfs.ha.namenodes.ns1
nn1,nn2
dfs.namenode.rpc-address.ns1.nn1
cloud01:9000
dfs.namenode.http-address.ns1.nn1
cloud01:50070
dfs.namenode.rpc-address.ns1.nn2
cloud02:9000
dfs.namenode.http-address.ns1.nn2
cloud02:50070
dfs.namenode.shared.edits.dir
qjournal://cloud05:8485;cloud06:8485;cloud07:8485/ns1
dfs.journalnode.edits.dir
/home/hadoop/app/hadoop-2.4.1/journal
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
/root/.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.hostname
cloud03
yarn.nodemanager.aux-services
mapreduce_shuffle
2.2.6修改slaves(slaves是指定子节点的位置,因为要在cloud01上启动HDFS、在cloud03启动yarn,
所以cloud01上的slaves文件指定的是datanode的位置,cloud03上的slaves文件指定的是nodemanager的位置)
即cloud01 或者cloud02 机器上的slaves的节点为:
cloud05
cloud06
cloud07
即cloud03 或者cloud04 机器上的slave的节点为:
cloud05
cloud06
cloud07
2.2.7配置免密码登陆
#首先要配置cloud01到cloud02、cloud03、cloud04、cloud05、cloud06的免密码登陆
#在cloud01上生产一对钥匙
ssh-keygen -t rsa
#将公钥拷贝到其他节点,包括自己
ssh-coyp-id cloud01
ssh-coyp-id cloud02
ssh-coyp-id cloud03
ssh-coyp-id cloud04
ssh-coyp-id cloud05
ssh-coyp-id cloud06
ssh-coyp-id cloud07
#配置cloud03到cloud04、cloud05、cloud06的免密码登陆
#在cloud03上生产一对钥匙
ssh-keygen -t rsa
#将公钥拷贝到其他节点
ssh-coyp-id cloud04
ssh-coyp-id cloud05
ssh-coyp-id cloud06
ssh-coyp-id cloud07
#注意:两个namenode之间要配置ssh免密码登陆,别忘了配置cloud02到cloud01的免登陆
在cloud02上生产一对钥匙
ssh-keygen -t rsa
ssh-coyp-id -i cloud01
2.3将配置好的hadoop拷贝到其他节点
[hadoop@cloud01 ~]$ scp -r /home/hadoop/app/hadoop-2.4.1/ hadoop@cloud02:/home/hadoop/app/
[hadoop@cloud01 ~]$ scp -r /home/hadoop/app/hadoop-2.4.1/ hadoop@cloud03:/home/hadoop/app/
[hadoop@cloud01 ~]$ scp -r /home/hadoop/app/hadoop-2.4.1/ hadoop@cloud04:/home/hadoop/app/
[hadoop@cloud01 ~]$ scp -r /home/hadoop/app/hadoop-2.4.1/ hadoop@cloud05:/home/hadoop/app/
[hadoop@cloud01 ~]$ scp -r /home/hadoop/app/hadoop-2.4.1/ hadoop@cloud06:/home/hadoop/app/
[hadoop@cloud01 ~]$ scp -r /home/hadoop/app/hadoop-2.4.1/ hadoop@cloud07:/home/hadoop/app/
###注意:严格按照下面的步骤
2.4启动zookeeper集群(分别在cloud05、cloud06、cloud07上启动zk)
cd /home/hadoop/app/zookeeper-3.4.5/bin/
./zkServer.sh start
#查看状态:一个leader,两个follower
./zkServer.sh status
2.5启动journalnode(在cloud01上启动所有journalnode,注意:是调用的hadoop-daemons.sh这个脚本,注意是复数s的那个脚本)
cd /home/hadoop/app/hadoop-2.4.1
sbin/hadoop-daemons.sh start journalnode
#运行jps命令检验,cloud05、cloud06、cloud07上多了JournalNode进程,可以通过以下命令查看
[hadoop@cloud05 ~]$ jps
4422 Jps
4383 JournalNode
2788 QuorumPeerMain
[hadoop@cloud06 ~]$ jps
2819 QuorumPeerMain
4418 JournalNode
4467 Jps
[hadoop@cloud07 ~]$ jps
4434 JournalNode
4495 Jps
2807 QuorumPeerMain
2.7格式化HDFS(第一次搭建的时候执行该命令)
[hadoop@cloud01 ~]$ pwd
/home/hadoop
#在cloud01上执行命令:
hdfs namenode -format
#格式化后会在根据core-site.xml中的hadoop.tmp.dir配置生成个文件,这里我配置的是$HADOOP_HOME//tmp,
然后将$HADOOP_HOME/tmp拷贝到cloud02的下。$HADOOP_HOME/
[hadoop@cloud01 hadoop-2.4.1]$ scp -r tmp/ hadoop@cloud02:$HADOOP_HOME/
2.8格式化ZK(在cloud01上执行即可) (第一次搭建的时候执行该命令)
hdfs zkfc -formatZK
2.9启动HDFS(在cloud01上执行)
sbin/start-dfs.sh
#运行jps命令检验,cloud01、cloud02上多了NameNode进程
#运行jps命令检验,cloud05、cloud06、cloud07上多了DataNode进程
[hadoop@cloud01 ~]$ jps
3050 DFSZKFailoverController
2798 NameNode
3140 Jps
[hadoop@cloud02 ~]$ jps
3990 DFSZKFailoverController
3928 NameNode
4100 Jps
[hadoop@cloud05 ~]$ jps
4691 DataNode
4802 Jps
4758 JournalNode
2788 QuorumPeerMain
[hadoop@cloud06 ~]$ jps
4726 DataNode
2819 QuorumPeerMain
4793 JournalNode
4854 Jps
[hadoop@cloud07 ~]$ jps
4751 DataNode
4880 Jps
4819 JournalNode
2807 QuorumPeerMain
若NameNode或者DataNode某一个节点启动失败,可以单独执行命令,例如:
[hadoop@cloud01 sbin]$ hadoop-daemon.sh start namenode
[hadoop@2cloud01 sbin]$ hadoop-daemon.sh start namenode
注意: 在cloud01启动通过start-dfs.sh 启动集群时候,会出现以下情况
1)namenode 节点没有启动
2)datanode 没有启动
解决方案: 可以单独通过hadoop-daemon.sh start xx 去启动,先启动datanode,然后在启动datanode即可解决
2.10启动YARN(#####注意#####:是在cloud03上执行start-yarn.sh,把namenode和resourcemanager分开是因为性能问题,因为他们都要占用大量资源,所以把他们分开了,他们分开了就要分别在不同的机器上启动)
sbin/start-yarn.sh
3.hadoop集群验证
验证HDFS管理界面
http://192.168.2.31:50070
NameNode 'cloud01:9000' (active)
http://192.168.2.32:50070
NameNode 'cloud02:9000' (standby)
验证MR管理界面
http://192.168.2.33:8088
http://192.168.2.34:8088
验证HDFS HA
首先向hdfs上传一个文件
hadoop fs -put /etc/profile /profile
hadoop fs -ls /
然后再kill掉active的NameNode
kill -9
通过浏览器访问:http://192.168.3.32:50070
NameNode 'cloud02:9000' (active)
这个时候cloud02上的NameNode变成了active
在执行命令:
hadoop fs -ls /
-rw-r--r-- 3 root supergroup 1926 2014-02-06 15:36 /profile
刚才上传的文件依然存在!!!
手动启动那个挂掉的NameNode
sbin/hadoop-daemon.sh start namenode
通过浏览器访问:http://192.168.2.31:50070
NameNode 'cloud01:9000' (standby)
验证YARN:
运行一下hadoop提供的demo中的WordCount程序:
hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.2.0.jar wordcount /profile /out
4、常见问题
问题1: 在HA下模式下执行start-dfs.sh 来启动集群,出现下面的错误
2015-04-26 07:43:50,444 FATAL org.apache.hadoop.hdfs.server.namenode.FSEditLog: Error: recoverUnfinalizedSegments failed for required journal (JournalAndStream(mgr=QJM to [192.168.2.35:8485, 192.168.2.36:8485, 192.168.2.37:8485], stream=null))
org.apache.hadoop.hdfs.qjournal.client.QuorumException: Got too many exceptions to achieve quorum size 2/3. 3 exceptions thrown:
192.168.2.35:8485: Call From cloud01/192.168.2.31 to cloud05:8485 failed on connection exception: java.net.ConnectException: Connection refused; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused
192.168.2.36:8485: Call From cloud01/192.168.2.31 to cloud06:8485 failed on connection exception: java.net.ConnectException: Connection refused; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused
192.168.2.37:8485: Call From cloud01/192.168.2.31 to cloud07:8485 failed on connection exception: java.net.ConnectException: Connection refused; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused
at org.apache.hadoop.hdfs.qjournal.client.QuorumException.create(QuorumException.java:81)
at org.apache.hadoop.hdfs.qjournal.client.QuorumCall.rethrowException(QuorumCall.java:223)
at org.apache.hadoop.hdfs.qjournal.client.AsyncLoggerSet.waitForWriteQuorum(AsyncLoggerSet.java:142)
at org.apache.hadoop.hdfs.qjournal.client.QuorumJournalManager.createNewUniqueEpoch(QuorumJournalManager.java:182)
at org.apache.hadoop.hdfs.qjournal.client.QuorumJournalManager.recoverUnfinalizedSegments(QuorumJournalManager.java:436)
at org.apache.hadoop.hdfs.server.namenode.JournalSet$7.apply(JournalSet.java:590)
at org.apache.hadoop.hdfs.server.namenode.JournalSet.mapJournalsAndReportErrors(JournalSet.java:359)
at org.apache.hadoop.hdfs.server.namenode.JournalSet.recoverUnfinalizedSegments(JournalSet.java:587)
at org.apache.hadoop.hdfs.server.namenode.FSEditLog.recoverUnclosedStreams(FSEditLog.java:1330)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startActiveServices(FSNamesystem.java:1006)
at org.apache.hadoop.hdfs.server.namenode.NameNode$NameNodeHAContext.startActiveServices(NameNode.java:1575)
at org.apache.hadoop.hdfs.server.namenode.ha.ActiveState.enterState(ActiveState.java:61)
at org.apache.hadoop.hdfs.server.namenode.ha.HAState.setStateInternal(HAState.java:63)
at org.apache.hadoop.hdfs.server.namenode.ha.StandbyState.setState(StandbyState.java:49)
at org.apache.hadoop.hdfs.server.namenode.NameNode.transitionToActive(NameNode.java:1453)
at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.transitionToActive(NameNodeRpcServer.java:1160)
at org.apache.hadoop.ha.protocolPB.HAServiceProtocolServerSideTranslatorPB.transitionToActive(HAServiceProtocolServerSideTranslatorPB.java:107)
at org.apache.hadoop.ha.proto.HAServiceProtocolProtos$HAServiceProtocolService$2.callBlockingMethod(HAServiceProtocolProtos.java:4460)
at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:585)
at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:928)
at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2013)
at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2009)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1556)
at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2007)
2015-04-26 07:43:50,449 INFO org.apache.hadoop.util.ExitUtil: Exiting with status 1
2015-04-26 07:43:50,451 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at cloud01/192.168.2.31
************************************************************/
2015-04-26 07:58:43,850 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: STARTUP_MSG:
问题1:问题原因
在第一次格式化dfs后,启动并使用了hadoop,后来又重新执行了格式化命令(hdfs namenode -format)
可文章参考: http://www.cnblogs.com/kinglau/p/3796274.html
问题1: 解决方案
1、删除cloud01和cloud02下 $HADOOP_HOME/tmp/目录。
2、进入$HADOOP_HOME目录,然后重新执行格式化hdfs namenode -format,根据提示语,选择Y即可
3、拷贝tmp到另一个HA的节点上,例如: [hadoop@cloud01 hadoop-2.4.1]$ scp -r tmp/ hadoop@cloud02:$HADOOP_HOME/
4、在cloud01上执行hdfs zkfc -formatZK
通过以上步骤终于完成Hadoop的HA
问题2:在HA下模式下执行start-dfs.sh 来启动集群,出现下面的错误,启动一个namenode可以正常启动,另一个namenode如下面的错误
2015-07-07 18:13:59,924 INFO org.apache.hadoop.hdfs.server.common.Storage
: Lock on /home/hadoop/app/hadoop-2.4.1/tmp/dfs/name/in_use.lock acquired by nodename 16479@cloud01
2015-07-07 18:14:00,095 FATAL org.apache.hadoop.hdfs.server.namenode.NameNode: Exception in namenode join
java.lang.NumberFormatException: null
at java.lang.Long.parseLong(Long.java:404)
at java.lang.Long.valueOf(Long.java:540)
at org.apache.hadoop.hdfs.util.PersistentLongFile.readFile(PersistentLongFile.java:99)
at org.apache.hadoop.hdfs.server.namenode.NNStorage.readTransactionIdFile(NNStorage.java:423)
at org.apache.hadoop.hdfs.server.namenode.FSImageTransactionalStorageInspector.inspectDirectory(FSImageTransactionalStorageInspector.java:93)
at org.apache.hadoop.hdfs.server.namenode.NNStorage.inspectStorageDirs(NNStorage.java:991)
at org.apache.hadoop.hdfs.server.namenode.NNStorage.readAndInspectDirs(NNStorage.java:1046)
at org.apache.hadoop.hdfs.server.namenode.FSImage.loadFSImage(FSImage.java:593)
at org.apache.hadoop.hdfs.server.namenode.FSImage.recoverTransitionRead(FSImage.java:272)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.loadFSImage(FSNamesystem.java:891)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.loadFromDisk(FSNamesystem.java:638)
at org.apache.hadoop.hdfs.server.namenode.NameNode.loadNamesystem(NameNode.java:503)
at org.apache.hadoop.hdfs.server.namenode.NameNode.initialize(NameNode.java:559)
at org.apache.hadoop.hdfs.server.namenode.NameNode.(NameNode.java:724)
at org.apache.hadoop.hdfs.server.namenode.NameNode.(NameNode.java:708)
at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1358)
at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1424)
2015-07-07 18:14:00,101 INFO org.apache.hadoop.util.ExitUtil: Exiting with status 1
2015-07-07 18:14:00,107 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at cloud01/192.168.2.31
************************************************************/
解决方案: 重新格式
问题3:在启动NameNode时候,DataNode服务器出现错误
15-07-07 18:56:49,009 FATAL org.apache.hadoop.hdfs.server.datanode.DataNode: Initialization failed for Block pool (Datanode Uuid unassigned) service to cloud01/192.168.2.31:9000. Exiting.
java.io.IOException:
Incompatible clusterIDs in mo: namenode clusterID =
CID-a54dbce7-a294-4bb2-af64-6f1f70e72615;
datanode clusterID = CID-6fbc3a86-8bd9-4dc1-86a2-b76b8f2e921a
at org.apache.hadoop.hdfs.server.datanode.DataStorage.doTransition(DataStorage.java:477)
at org.apache.hadoop.hdfs.server.datanode.DataStorage.recoverTransitionRead(DataStorage.java:226)
at org.apache.hadoop.hdfs.server.datanode.DataStorage.recoverTransitionRead(DataStorage.java:254)
at org.apache.hadoop.hdfs.server.datanode.DataNode.initStorage(DataNode.java:974)
at org.apache.hadoop.hdfs.server.datanode.DataNode.initBlockPool(DataNode.java:945)
at org.apache.hadoop.hdfs.server.datanode.BPOfferService.verifyAndSetNamespaceInfo(BPOfferService.java:278)
at org.apache.hadoop.hdfs.server.datanode.BPServiceActor.connectToNNAndHandshake(BPServiceActor.java:220)
at org.apache.hadoop.hdfs.server.datanode.BPServiceActor.run(BPServiceActor.java:816)
at java.lang.Thread.run(Thread.java:745)
问题3: 原因分析
“Incompatible clusterIDs”的错误原因是在执行“hdfs namenode -format”之前,没有清空DataNode节点的data目录。
问题3: 解决办法:
1、在hdfs-site.xml配置文件中,配置了dfs.namenode.name.dir,
在master中,该配置的目录下有个current文件夹,里面有个
VERSION文件,内容如下:
[hadoop@cloud01 current]$ pwd
/home/hadoop/app/hadoop-2.4.1/tmp/dfs/name/current
[hadoop@cloud01 current]$ more VERSION
#Tue Jul 07 18:36:14 PDT 2015
namespaceID=2120151814
clusterID=CID-a54dbce7-a294-4bb2-af64-6f1f70e72615
cTime=0
storageType=NAME_NODE
blockpoolID=BP-1830896004-192.168.2.31-1436319374909
layoutVersion=-56
2、在core-site.xml配置文件中,配置了hadoop.tmp.dir,
在slave中,该配置的目录下有个dfs/data/current目录,里面也有一个
VERSION文件,内容
[hadoop@cloud05 current]$ more VERSION
#Tue Jul 07 18:14:39 PDT 2015
storageID=DS-a22fe90e-e26f-4864-8ead-8ab1e2f1c47e
clusterID=CID-6fbc3a86-8bd9-4dc1-86a2-b76b8f2e921a
cTime=0
datanodeUuid=4dfe894f-8f96-4a73-bd75-137ab4ca7261
storageType=DATA_NODE
layoutVersion=-55
3、可以把DataNode节点的中的
clusterID 替换 成NameNode 的
clusterID 就可以解决
参考文章:
http://www.infoq.com/cn/articles/hadoop-2-0-namenode-ha-federation-practice-zh/
http://slaytanic.blog.51cto.com/2057708/1423227
http://jingyan.baidu.com/article/e4d08ffdd417660fd3f60d70.html