Hadoop之——hadoop2.2.0集群搭建

网友投稿 237 2022-11-20

Hadoop之——hadoop2.2.0集群搭建

1.修改Linux主机名

2.修改IP

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

######注意######如果你们公司是租用的服务器或是使用的云主机(如华为云主机、阿里云主机等)

/etc/hosts里面要配置的是内网IP地址和主机名的映射关系

4.关闭防火墙

5.ssh免登陆

6.安装JDK,配置环境变量等

集群规划:

主机名        IP                安装的软件                    运行的进程

liuyazhuang01    192.168.1.201    jdk、hadoop                    NameNode、DFSZKFailoverController

liuyazhuang02    192.168.1.202    jdk、hadoop                    NameNode、DFSZKFailoverController

liuyazhuang03    192.168.1.203    jdk、hadoop                    ResourceManager

liuyazhuang04    192.168.1.204    jdk、hadoop、zookeeper        DataNode、NodeManager、JournalNode、QuorumPeerMain

liuyazhuang05    192.168.1.205    jdk、hadoop、zookeeper        DataNode、NodeManager、JournalNode、QuorumPeerMain

liuyazhuang06    192.168.1.206    jdk、hadoop、zookeeper        DataNode、NodeManager、JournalNode、QuorumPeerMain

说明:

在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状态

安装步骤:

1.安装配置zooekeeper集群

1.1解压

tar -zxvf zookeeper-3.4.5.tar.gz -C /liuyazhuang/

1.2修改配置

cd /liuyazhuang/zookeeper-3.4.5/conf/cp zoo_sample.cfg zoo.cfgvim zoo.cfg修改:dataDir=/liuyazhuang/zookeeper-3.4.5/tmp在最后添加:server.1=liuyazhuang04:2888:3888server.2=liuyazhuang05:2888:3888server.3=liuyazhuang06:2888:3888保存退出然后创建一个tmp文件夹mkdir /liuyazhuang/zookeeper-3.4.5/tmp再创建一个空文件touch /liuyazhuang/zookeeper-3.4.5/tmp/myid最后向该文件写入IDecho 1 > /liuyazhuang/zookeeper-3.4.5/tmp/myid

1.3拷贝配置好的zookeeper

将配置好的zookeeper拷贝到其他节点(首先分别在liuyazhuang05、liuyazhuang06根目录下创建一个liuyazhuang目录:mkdir /liuyazhuang)

scp -r /liuyazhuang/zookeeper-3.4.5/ liuyazhuang05:/liuyazhuang/scp -r /liuyazhuang/zookeeper-3.4.5/ liuyazhuang06:/liuyazhuang/注意:修改liuyazhuang05、liuyazhuang06对应/liuyazhuang/zookeeper-3.4.5/tmp/myid内容liuyazhuang05: echo 2 > /liuyazhuang/zookeeper-3.4.5/tmp/myidliuyazhuang06: echo 3 > /liuyazhuang/zookeeper-3.4.5/tmp/myid

2.安装配置hadoop集群

2.1解压

tar -zxvf hadoop-2.2.0.tar.gz -C /liuyazhuang/

2.2配置HDFS(hadoop2.0所有的配置文件都在$HADOOP_HOME/etc/hadoop目录下)

#将hadoop添加到环境变量中vim /etc/profileexport JAVA_HOME=/usr/java/jdk1.7.0_55export HADOOP_HOME=/liuyazhuang/hadoop-2.2.0export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin#hadoop2.0的配置文件全部在$HADOOP_HOME/etc/hadoop下cd /liuyazhuang/hadoop-2.2.0/etc/hadoop

2.2.1修改hadoo-env.sh

export JAVA_HOME=/usr/java/jdk1.7.0_55

2.2.2修改core-site.xml

fs.defaultFS hdfs://ns1 hadoop.tmp.dir /liuyazhuang/hadoop-2.2.0/tmp ha.zookeeper.quorum liuyazhuang04:2181,liuyazhuang05:2181,liuyazhuang06:2181

2.2.3修改hdfs-site.xml

dfs.nameservices ns1 dfs.ha.namenodes.ns1 nn1,nn2 dfs.namenode.rpc-address.ns1.nn1 liuyazhuang01:9000 dfs.namenode. liuyazhuang01:50070 dfs.namenode.rpc-address.ns1.nn2 liuyazhuang02:9000 dfs.namenode. liuyazhuang02:50070 dfs.namenode.shared.edits.dir qjournal://liuyazhuang04:8485;liuyazhuang05:8485;liuyazhuang06:8485/ns1 dfs.journalnode.edits.dir /liuyazhuang/hadoop-2.2.0/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 liuyazhuang03 yarn.nodemanager.aux-services mapreduce_shuffle

2.2.6修改slaves

修改slaves(slaves是指定子节点的位置,因为要在liuyazhuang01上启动HDFS、在liuyazhuang03启动yarn,所以liuyazhuang01上的slaves文件指定的是datanode的位置,liuyazhuang03上的slaves文件指定的是nodemanager的位置)

liuyazhuang04liuyazhuang05liuyazhuang06

2.2.7配置免密码登陆

#首先要配置liuyazhuang01到liuyazhuang02、liuyazhuang03、liuyazhuang04、liuyazhuang05、liuyazhuang06的免密码登陆#在liuyazhuang01上生产一对钥匙ssh-keygen -t rsa#将公钥拷贝到其他节点,包括自己ssh-coyp-id liuyazhuang01ssh-coyp-id liuyazhuang02ssh-coyp-id liuyazhuang03ssh-coyp-id liuyazhuang04ssh-coyp-id liuyazhuang05ssh-coyp-id liuyazhuang06#配置liuyazhuang03到liuyazhuang04、liuyazhuang05、liuyazhuang06的免密码登陆#在liuyazhuang03上生产一对钥匙ssh-keygen -t rsa#将公钥拷贝到其他节点ssh-coyp-id liuyazhuang04ssh-coyp-id liuyazhuang05ssh-coyp-id liuyazhuang06#注意:两个namenode之间要配置ssh免密码登陆,别忘了配置liuyazhuang02到liuyazhuang01的免登陆在liuyazhuang02上生产一对钥匙ssh-keygen -t rsassh-coyp-id -i liuyazhuang01

2.4将配置好的hadoop拷贝到其他节点

scp -r /liuyazhuang/ liuyazhuang02:/scp -r /liuyazhuang/ liuyazhuang03:/scp -r /liuyazhuang/hadoop-2.2.0/ root@liuyazhuang04:/liuyazhuang/scp -r /liuyazhuang/hadoop-2.2.0/ root@liuyazhuang05:/liuyazhuang/scp -r /liuyazhuang/hadoop-2.2.0/ root@liuyazhuang06:/liuyazhuang/

###注意:严格按照下面的步骤

2.5启动zookeeper集群

(分别在liuyazhuang04、liuyazhuang05、liuyazhuang06上启动zk)

cd /liuyazhuang/zookeeper-3.4.5/bin/./zkServer.sh start#查看状态:一个leader,两个follower./zkServer.sh status

2.6启动journalnode

(在liuyazhuang01上启动所有journalnode,注意:是调用的hadoop-daemons.sh这个脚本,注意是复数s的那个脚本)

cd /liuyazhuang/hadoop-2.2.0sbin/hadoop-daemons.sh start journalnode

#运行jps命令检验,liuyazhuang04、liuyazhuang05、liuyazhuang06上多了JournalNode进程

2.7格式化HDFS

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

2.8格式化ZK(在liuyazhuang01上执行即可)

hdfs zkfc -formatZK

2.9启动HDFS(在liuyazhuang01上执行)

sbin/start-dfs.sh

2.10启动YARN

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

sbin/start-yarn.sh

到此,hadoop2.2.0配置完毕,可以统计浏览器访问:

'liuyazhuang01:9000' (active)'liuyazhuang02:9000' (standby)

验证HDFS HA

首先向hdfs上传一个文件hadoop fs -put /etc/profile /profilehadoop fs -ls /然后再kill掉active的NameNodekill -9 通过浏览器访问:'liuyazhuang02:9000' (active)这个时候liuyazhuang02上的NameNode变成了active在执行命令:hadoop fs -ls /-rw-r--r-- 3 root supergroup 1926 2014-02-06 15:36 /profile刚才上传的文件依然存在!!!手动启动那个挂掉的NameNodesbin/hadoop-daemon.sh start namenode通过浏览器访问:'liuyazhuang01:9000' (standby)

验证YARN:

运行一下hadoop提供的demo中的WordCount程序:

hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.2.0.jar wordcount /profile /out

OK,大功告成!!!

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:英创信息技术ESM335x工控主板ISA总线DMA数据传输简介
下一篇:解析整合mybatis
相关文章

 发表评论

暂时没有评论,来抢沙发吧~