Hadoop集群搭建

1、准备工作

  • 准备6台虚拟机,内存1G
  • 虚拟机节点分配情况
序号 机器 分配
1 Park01 Zookeeper、NameNode(active)、ResourceManager(active)
2 Park02 Zookeeper、NameNode(standby)
3 Park03 Zookeeper、ResourceManager(standby)
4 Park04 DataNode、NodeManager、JournalNode
5 Park05 DataNode、NodeManager、JournalNode
6 Park06 DataNode、NodeManager、JournalNode
  • 关闭每台虚拟机防火墙
  • 更改每台虚拟机主机名,例如CH0、CH1……参考
  • 配置每台机器的hosts
    127.0.0.1 localhost
    ::1 localhost
    192.168.6.20 CH0
    192.168.6.21 CH1
    ……
    192.168.6.25 CH5
  • 配置免秘钥登录
  • 安装JDK并配置环境变量

2、Zookeeper

[root@CH0 soft]# mkdir -p /usr/lib/zookeeper
[root@CH0 soft]# tar -zxvf zookeeper-3.4.7.tar.gz -C /usr/lib/zookeeper

2.1 zoo.cfg配置

[root@CH0 soft]# cd /usr/lib/zookeeper/zookeeper-3.4.7/conf/
[root@CH0 conf]# cp zoo_sample.cfg zoo.cfg
[root@CH0 conf]# vim zoo.cfg 

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/usr/lib/zookeeper/zookeeper-3.4.7/tmp
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
server.1=192.168.6.20:2888:3888
server.2=192.168.6.21:2888:3888
server.3=192.168.6.22:2888:3888

2.2 tmp目录配置

[root@CH0 conf]# cd ..
[root@CH0 zookeeper-3.4.7]# mkdir tmp
[root@CH0 zookeeper-3.4.7]# cd tmp/
[root@CH0 tmp]# vim myid

1

2.3 其他两台虚拟机Zookeeper配置


[root@CH0 tmp]# cd ../../
[root@CH0 zookeeper]# cd ../
[root@CH0 lib]# scp -r zookeeper CH1:/usr/lib/
[root@CH0 lib]# scp -r zookeeper CH2:/usr/lib/

[root@CH1 ~]# cd /usr/lib/zookeeper/zookeeper-3.4.7/tmp/
[root@CH1 tmp]# ls
myid
[root@CH1 tmp]# vim myid 
[root@CH1 tmp]# cat myid 
2

[root@CH2 ~]# cd /usr/lib/zookeeper/zookeeper-3.4.7/tmp/
[root@CH2 tmp]# ls
myid
[root@CH2 tmp]# vim myid 
[root@CH2 tmp]# cat myid 
3

3、Hadoop安装配置

[root@CH0 soft]# mkdir -p /usr/lib/hadoop
[root@CH0 soft]# tar -zxvf hadoop-2.7.1.tar.gz -C /usr/lib/hadoop
[root@CH0 soft]# cd /usr/lib/hadoop/hadoop-2.7.1/etc/hadoop/

3.1、hadoop-env.sh配置

[root@CH0 hadoop]# vim hadoop-env.sh 

export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_171
export HADOOP_CONF_DIR=/usr/lib/hadoop/hadoop-2.7.1/etc/hadoop

3.2、core-site.xml配置

[root@CH0 hadoop]# vim core-site.xml 



fs.defaultFS
hdfs://ns



hadoop.tmp.dir
/usr/lib/hadoop/hadoop-2.7.1/tmp



ha.zookeeper.quorum
CH0:2181,CH1:2181,CH2:2181


3.3、hdfs-site.xml配置

[root@CH0 hadoop]# vim hdfs-site.xml 



dfs.nameservices
ns



dfs.ha.namenodes.ns
nn1,nn2



dfs.namenode.rpc-address.ns.nn1
CH0:9000



dfs.namenode.http-address.ns.nn1
CH0:50070



dfs.namenode.rpc-address.ns.nn2
CH1:9000



dfs.namenode.http-address.ns.nn2
CH1:50070



dfs.namenode.shared.edits.dir
qjournal://CH3:8485;CH4:8485;CH5:8485/ns



dfs.journalnode.edits.dir
/usr/lib/hadoop/hadoop-2.7.1/journal



dfs.ha.automatic-failover.enabled
true



dfs.client.failover.proxy.provider.ns
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.namenode.name.dir
file:///usr/lib/hadoop/hadoop-2.7.1/tmp/namenode



dfs.datanode.data.dir
file:///usr/lib/hadoop/hadoop-2.7.1/tmp/datanode



dfs.replication
3



dfs.permissions
false


3.4、mapred-site.xml配置

[root@CH0 hadoop]# cp mapred-site.xml.template mapred-site.xml
[root@CH0 hadoop]# vim mapred-site.xml




mapreduce.framework.name

yarn


3.5、yarn-site.xml配置

[root@CH0 hadoop]# vim yarn-site.xml 



yarn.resourcemanager.ha.enabled
true



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



yarn.resourcemanager.hostname.rm1
CH0



yarn.resourcemanager.hostname.rm2
CH2



yarn.resourcemanager.recovery.enabled
true



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



yarn.resourcemanager.zk-address
CH0:2181,CH1:2181,CH2:2181
For multiple zk services,separate them with comm



yarn.resourcemanager.cluster-id
yarn-ha




yarn.resourcemanager.hostname

CH0




yarn.nodemanager.aux-services
mapreduce_shuffle


3.6、slaves配置

[root@CH0 hadoop]# vim slaves 
CH3
CH4
CH5

3.7、目录创建

[root@CH0 hadoop]# cd ../..
[root@CH0 hadoop-2.7.1]# mkdir tmp
[root@CH0 hadoop-2.7.1]# mkdir journal
[root@CH0 hadoop-2.7.1]# cd tmp
[root@CH0 tmp]# mkdir namenode
[root@CH0 tmp]# mkdir datanode

3.8、发送给其他五台虚拟机

[root@CH0 hadoop-2.7.1]# cd ../../
[root@CH0 lib]# scp -r hadoop CH1:/usr/lib/
[root@CH0 lib]# scp -r hadoop CH2:/usr/lib/
[root@CH0 lib]# scp -r hadoop CH3:/usr/lib/
[root@CH0 lib]# scp -r hadoop CH4:/usr/lib/
[root@CH0 lib]# scp -r hadoop CH5:/usr/lib/

4、环境变量配置

[root@CH0 ~]# vim /etc/profile
#java env
JAVA_HOME=/usr/lib/jvm/jdk1.8.0_171
HADOOP_HOME=/usr/lib/hadoop/hadoop-2.7.1
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
export JAVA_HOME PATH CLASSPATH HADOOP_HOME

4.1、配置文件发送其他五台虚拟机

[root@CH0 ~]# scp /etc/profile CH1:/etc/
[root@CH0 ~]# scp /etc/profile CH2:/etc/
[root@CH0 ~]# scp /etc/profile CH3:/etc/
[root@CH0 ~]# scp /etc/profile CH4:/etc/
[root@CH0 ~]# scp /etc/profile CH5:/etc/


[root@CH0 ~]# source /etc/profile

5、Hadoop分布式启动

5.1、zookeeper启动

Park01启动

[root@CH0 ~]# cd /usr/lib/zookeeper/zookeeper-3.4.7/bin/
[root@CH0 bin]# sh zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/lib/zookeeper/zookeeper-3.4.7/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

Park02启动

[root@CH1 ~]# cd /usr/lib/zookeeper/zookeeper-3.4.7/bin/
[root@CH1 bin]# sh zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/lib/zookeeper/zookeeper-3.4.7/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

Park03启动

[root@CH2 ~]# cd /usr/lib/zookeeper/zookeeper-3.4.7/bin/
[root@CH2 bin]# sh zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /usr/lib/zookeeper/zookeeper-3.4.7/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

Park01启动状态验证

[root@CH0 bin]# sh zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/lib/zookeeper/zookeeper-3.4.7/bin/../conf/zoo.cfg
Mode: follower

Park02启动状态验证

[root@CH1 bin]# sh zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/lib/zookeeper/zookeeper-3.4.7/bin/../conf/zoo.cfg
Mode: leader

Park03启动状态验证

[root@CH2 bin]# sh zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/lib/zookeeper/zookeeper-3.4.7/bin/../conf/zoo.cfg
Mode: follower

5.2、format zkfc

[root@CH0 bin]# hdfs zkfc -formatZK
18/05/29 16:08:35 INFO ha.ActiveStandbyElector: Successfully created /hadoop-ha/ywty in ZK.
18/05/29 16:08:35 INFO zookeeper.ZooKeeper: Session: 0x263aae518180000 closed

[root@CH1 bin]# hdfs zkfc -formatZK
18/05/29 16:09:45 INFO ha.ActiveStandbyElector: Successfully created /hadoop-ha/ywty in ZK.
18/05/29 16:09:45 INFO zookeeper.ZooKeeper: Session: 0x263aae518180000 closed

5.3、JournalNode启动

[root@CH3 ~]# cd /usr/lib/hadoop/hadoop-2.7.1/sbin/
[root@CH3 sbin]# sh hadoop-daemon.sh start journalnode
[root@CH3 sbin]# jps
1464 JournalNode
1513 Jps

[root@CH4 sbin]# sh hadoop-daemon.sh start journalnode
[root@CH4 sbin]# jps
1445 JournalNode
1494 Jps

[root@CH5 sbin]# sh hadoop-daemon.sh start journalnode
[root@CH5 sbin]# jps
1449 JournalNode
1498 Jps

5.4、format NameNode

[root@CH0 bin]# hadoop namenode -format
18/05/29 16:21:00 INFO common.Storage: Storage directory /usr/lib/hadoop/hadoop-2.7.1/tmp/namenode has been successfully formatted.
18/05/29 16:21:00 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with txid >= 0
18/05/29 16:21:00 INFO util.ExitUtil: Exiting with status 0
18/05/29 16:21:00 INFO namenode.NameNode: SHUTDOWN_MSG: 
/************************************************************/

[root@CH0 ~]# cd /usr/lib/hadoop/hadoop-2.7.1/sbin/
[root@CH0 sbin]# sh hadoop-daemon.sh start namenode
starting namenode, logging to /usr/lib/hadoop/hadoop-2.7.1/logs/hadoop-root-namenode-CH0.out
[root@CH0 sbin]# jps
1604 NameNode
1676 Jps
1438 QuorumPeerMain

5.5、bootstrapStandby NameNode

[root@CH1 bin]# hdfs namenode -bootstrapStandby
18/05/29 16:29:12 INFO namenode.NameNode: registered UNIX signal handlers for [TERM, HUP, INT]
18/05/29 16:29:12 INFO namenode.NameNode: createNameNode [-bootstrapStandby]
=====================================================
About to bootstrap Standby ID yy2 from:
       Nameservice ID: ywty
    Other Namenode ID: yy1
  Other NN's HTTP address: http://CH0:50070
  Other NN's IPC  address: CH0/192.168.6.20:9000
         Namespace ID: 1549916029
        Block pool ID: BP-605564131-192.168.6.20-1527582060609
           Cluster ID: CID-a2fc36bc-6fc9-4d5f-8d95-b1c3da1557bd
       Layout version: -63
   isUpgradeFinalized: true
=====================================================
18/05/29 16:29:13 INFO common.Storage: Storage directory /usr/lib/hadoop/hadoop-2.7.1/tmp/namenode has been successfully formatted.
18/05/29 16:29:14 INFO namenode.TransferFsImage: Opening connection to http://CH0:50070/imagetransfer?getimage=1&txid=0&storageInfo=-63:1549916029:0:CID-a2fc36bc-6fc9-4d5f-8d95-b1c3da1557bd
18/05/29 16:29:14 INFO namenode.TransferFsImage: Image Transfer timeout configured to 60000 milliseconds
18/05/29 16:29:14 INFO namenode.TransferFsImage: Transfer took 0.00s at 0.00 KB/s
18/05/29 16:29:14 INFO namenode.TransferFsImage: Downloaded file fsimage.ckpt_0000000000000000000 size 351 bytes.
18/05/29 16:29:14 INFO util.ExitUtil: Exiting with status 0
18/05/29 16:29:14 INFO namenode.NameNode: SHUTDOWN_MSG: 

5.6、NameNode start

[root@CH1 ~]# cd /usr/lib/hadoop/hadoop-2.7.1/sbin/
[root@CH1 sbin]# sh hadoop-daemon.sh start namenode
starting namenode, logging to /usr/lib/hadoop/hadoop-2.7.1/logs/hadoop-root-namenode-CH1.out
[root@CH1 sbin]# jps
1572 NameNode
1644 Jps
1406 QuorumPeerMain

5.7、DataNode start

[root@CH3 sbin]# sh hadoop-daemon.sh start datanode
starting datanode, logging to /usr/lib/hadoop/hadoop-2.7.1/logs/hadoop-root-datanode-CH3.out
[root@CH3 sbin]# jps
1617 Jps
1543 DataNode
1464 JournalNode

[root@CH4 sbin]# sh hadoop-daemon.sh start datanode
starting datanode, logging to /usr/lib/hadoop/hadoop-2.7.1/logs/hadoop-root-datanode-CH4.out
[root@CH4 sbin]# jps
1523 DataNode
1445 JournalNode
1597 Jps

[root@CH5 sbin]# sh hadoop-daemon.sh start datanode
starting datanode, logging to /usr/lib/hadoop/hadoop-2.7.1/logs/hadoop-root-datanode-CH5.out
[root@CH5 sbin]# jps
1601 Jps
1527 DataNode
1449 JournalNode

5.8、ZKFC Start

[root@CH0 sbin]# sh hadoop-daemon.sh start zkfc
starting zkfc, logging to /usr/lib/hadoop/hadoop-2.7.1/logs/hadoop-root-zkfc-CH0.out
[root@CH0 sbin]# jps
1987 Jps
1604 NameNode
1438 QuorumPeerMain
2240 DFSZKFailoverController

[root@CH1 sbin]# sh hadoop-daemon.sh start zkfc
starting zkfc, logging to /usr/lib/hadoop/hadoop-2.7.1/logs/hadoop-root-zkfc-CH1.out
[root@CH1 sbin]# jps
1572 NameNode
1780 DFSZKFailoverController
1844 Jps
1406 QuorumPeerMain

5.9、Yarn Start

[root@CH0 sbin]# sh start-yarn.sh 
starting yarn daemons
starting resourcemanager, logging to /usr/lib/hadoop/hadoop-2.7.1/logs/yarn-root-resourcemanager-CH0.out
CH5: starting nodemanager, logging to /usr/lib/hadoop/hadoop-2.7.1/logs/yarn-root-nodemanager-CH5.out
CH4: starting nodemanager, logging to /usr/lib/hadoop/hadoop-2.7.1/logs/yarn-root-nodemanager-CH4.out
CH3: starting nodemanager, logging to /usr/lib/hadoop/hadoop-2.7.1/logs/yarn-root-nodemanager-CH3.out
[root@CH0 sbin]# jps
2240 DFSZKFailoverController
1604 NameNode
2356 ResourceManager
2621 Jps
1438 QuorumPeerMain

[root@CH2 sbin]# sh yarn-daemon.sh start resourcemanager
starting resourcemanager, logging to /usr/lib/hadoop/hadoop-2.7.1/logs/yarn-root-resourcemanager-CH2.out
[root@CH2 sbin]# jps
1604 ResourceManager
1643 Jps
1439 QuorumPeerMain

6、浏览器访问

Hadoop集群搭建_第1张图片
CH0 50070

Hadoop集群搭建_第2张图片
CH1 50070

你可能感兴趣的:(Hadoop集群搭建)