Hadoop分布式HA的安装部署
集群的规划
ip 基本的软件 运行的进程
uplooking01 jdk、zk、hadoop NameNode、zkfc、zk、journalNode
uplooking02 jdk、zk、hadoop NameNode、zkfc、zk、journalNode、datanode、ResourceManager、NodeManager
uplooking03 jdk、zk、hadoop zk、journalNode、datanode、ResourceManager、NodeManager
zookeeper和hadoop分布式集群的搭建
零、清理工作:
删除/home/uplooking/app/下的软件
删除/home/uplooking/data/hadoop/下的数据
删除/home/uplooking/data/zookeeper/下的数据
[uplooking@uplooking01 ~]$ rm -r app/hadoop
[uplooking@uplooking01 ~]$ rm -r app/zookeeper
[uplooking@uplooking01 ~]$ rm -r data/hadoop/name/*
[uplooking@uplooking01 ~]$ rm -r data/hadoop/data/*
[uplooking@uplooking01 ~]$ rm -r data/hadoop/tmp/*
[uplooking@uplooking01 ~]$ rm -r data/hadoop/secondary
[uplooking@uplooking01 ~]$ rm -r data/zookeeper/*
在uplooking02和uplooking03上做同样的事
一、zookeeper集群
1、解压:
[uplooking@uplooking01 ~]$ tar -zxvf soft/zookeeper-3.4.6.tar.gz -C app/
2、重命名
[uplooking@uplooking01 ~]$ mv app/zookeeper-3.4.6 app/zookeeper
3、配置文件重命名
[uplooking@uplooking01 zookeeper]$ cp conf/zoo_sample.cfg conf/zoo.cfg
4、修改配置文件$ZOOKEEPER_HOME/conf/zoo.cfg
dataDir=/home/uplooking/app/zookeeper/data
dataLogDir=/home/uplooking/logs/zookeeper
server.101=uplooking01:2888:3888
server.102=uplooking02:2888:3888
server.103=uplooking03:2888:3888
启动server表示当前节点就是zookeeper集群中的一个server节点
server后面的.数字(不能重复)是当前server节点在该zk集群中的唯一标识
=后面则是对当前server的说明,用":"分隔开,
第一段是当前server所在机器的主机名
第二段和第三段以及2818端口
2181--->zookeeper服务器开放给client连接的端口
2888--->zookeeper服务器之间进行通信的端口
3888--->zookeeper和外部进程进行通信的端口
5、在dataDir=/home/uplooking/app/zookeeper/data下面创建一个文件myid
uplooking01机器对应的server.后面的101
uplooking02机器对应的server.后面的102
uplooking03机器对应的server.后面的103
6、需要将在uplooking01上面的zookeeper拷贝之uplooking02和uplooking03,这里使用scp远程拷贝
scp -r app/zookeeper uplooking@uplooking02:/home/uplooking/app
scp -r app/zookeeper uplooking@uplooking03:/home/uplooking/app
在拷贝的过程中需要设置ssh免密码登录
在uplooking02和uplooking03上面生成ssh密钥
ssh-keygen -t rsa
将密钥拷贝授权文件中
uplooking02:
ssh-keygen -t rsa
ssh-copy-id -i uplooking@uplooking02
uplooking03:
ssh-keygen -t rsa
ssh-copy-id -i uplooking@uplooking03
uplooking01:
ssh-copy-id -i uplooking@uplooking03
7、修改myid文件
[uplooking@uplooking02 ~]$ echo 102 > app/zookeeper/data/myid
[uplooking@uplooking03 ~]$ echo 103 > app/zookeeper/data/myid
8、同步环境变量文件
[uplooking@uplooking01 ~]$ scp .bash_profile uplooking@uplooking02:/home/uplooking/
[uplooking@uplooking01 ~]$ scp .bash_profile uplooking@uplooking03:/home/uplooking/
9、启动
在1、2、3分别执行zkServer.sh start
错误提示:
2018-03-02 10:20:10,221 [myid:] - ERROR [main:QuorumPeerMain@85] - Invalid config, exiting abnormally
org.apache.zookeeper.server.quorum.QuorumPeerConfig$ConfigException: Error processing /home/uplooking/app/zookeeper/bin/.
./conf/zoo.cfg
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:123)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:101)
at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:78)
Caused by: java.lang.IllegalArgumentException: dataLogDir =/home/uplooking/logs/zookeeper is missing.
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parseProperties(QuorumPeerConfig.java:253)
at org.apache.zookeeper.server.quorum.QuorumPeerConfig.parse(QuorumPeerConfig.java:119)
... 2 more
Invalid config, exiting abnormally
----------------------------------------------------------------------------------------------------
Hadoop分布式HA的部署
1、解压
[uplooking@uplooking01 ~]$ tar -zvxf soft/hadoop-2.6.4.tar.gz -C app/
2、重命名
[uplooking@uplooking01 ~]$ mv app/hadoop-2.6.4/ app/hadoop
3、修改配置文件
hadoop-env.sh、yarn-env.sh、hdfs-site.xml、core-site.xml、mapred-site.xml、yarn-site.xml、slaves
1°、hadoop-env.sh
export JAVA_HOME=/opt/jdk
2°、yarn-env.sh
export JAVA_HOME=/opt/jdk
3°、slaves
uplooking02
uplooking03
4°、hdfs-site.xml
<configuration>
<!--指定hdfs的nameservice为ns1,需要和core-site.xml中的保持一致 -->
<property>
<name>dfs.nameservices</name>
<value>ns1</value>
</property>
<!-- ns1下面有两个NameNode,分别是nn1,nn2 -->
<property>
<name>dfs.ha.namenodes.ns1</name>
<value>nn1,nn2</value>
</property>
<!-- nn1的RPC通信地址 -->
<property>
<name>dfs.namenode.rpc-address.ns1.nn1</name>
<value>uplooking01:9000</value>
</property>
<!-- nn1的http通信地址 -->
<property>
<name>dfs.namenode.http-address.ns1.nn1</name>
<value>uplooking01:50070</value>
</property>
<!-- nn2的RPC通信地址 -->
<property>
<name>dfs.namenode.rpc-address.ns1.nn2</name>
<value>uplooking02:9000</value>
</property>
<!-- nn2的http通信地址 -->
<property>
<name>dfs.namenode.http-address.ns1.nn2</name>
<value>uplooking02:50070</value>
</property>
<!-- 指定NameNode的元数据在JournalNode上的存放位置 -->
<property>
<name>dfs.namenode.shared.edits.dir</name>
<value>qjournal://uplooking01:8485;uplooking02:8485;uplooking03:8485/ns1</value>
</property>
<!-- 指定JournalNode在本地磁盘存放数据的位置 -->
<property>
<name>dfs.journalnode.edits.dir</name>
<value>/home/uplooking/data/hadoop/journal</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/home/uplooking/data/hadoop/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/home/uplooking/data/hadoop/data</value>
</property>
<!-- 开启NameNode失败自动切换 -->
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
<!-- 配置失败自动切换实现方式 -->
<property>
<name>dfs.client.failover.proxy.provider.ns1</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
<!-- 配置隔离机制方法,多个机制用换行分割,即每个机制暂用一行-->
<property>
<name>dfs.ha.fencing.methods</name>
<value>
sshfence
shell(/bin/true)
</value>
</property>
<!-- 使用sshfence隔离机制时需要ssh免登陆 -->
<property>
<name>dfs.ha.fencing.ssh.private-key-files</name>
<value>/home/uplooking/.ssh/id_rsa</value>
</property>
<!-- 配置sshfence隔离机制超时时间 -->
<property>
<name>dfs.ha.fencing.ssh.connect-timeout</name>
<value>30000</value>
</property>
</configuration>
5°、core-site.xml
<configuration>
<!-- 指定hdfs的nameservice为ns1 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://ns1</value>
</property>
<!-- 指定hadoop临时目录 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/home/uplooking/data/hadoop/tmp</value>
</property>
<!-- 指定zookeeper地址 -->
<property>
<name>ha.zookeeper.quorum</name>
<value>uplooking01:2181,uplooking02:2181,uplooking03:2181</value>
</property>
</configuration>
6°、mapred-site.xml
<configuration>
<!-- mr依赖的框架名称 yarn-->
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<!-- mr转化历史任务的rpc通信地址-->
<property>
<name>mapreduce.jobhistory.address</name>
<value>uplooking02:10020</value>
</property>
<!-- mr转化历史任务的http通信地址-->
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>uplooking02:19888</value>
</property>
<!-- 会在hdfs的根目录下面创建一个history的文件夹,存放历史任务的相关运行情况-->
<property>
<name>yarn.app.mapreduce.am.staging-dir</name>
<value>/history</value>
</property>
<!-- map和reduce的日志级别-->
<property>
<name>mapreduce.map.log.level</name>
<value>INFO</value>
</property>
<property>
<name>mapreduce.reduce.log.level</name>
<value>INFO</value>
</property>
</configuration>
7°、yarn-site.xml
<configuration>
<!-- 开启RM高可靠 -->
<property>
<name>yarn.resourcemanager.ha.enabled</name>
<value>true</value>
</property>
<!-- 指定RM的cluster id -->
<property>
<name>yarn.resourcemanager.cluster-id</name>
<value>yrc</value>
</property>
<!-- 指定RM的名字 -->
<property>
<name>yarn.resourcemanager.ha.rm-ids</name>
<value>rm1,rm2</value>
</property>
<!-- 分别指定RM的地址 -->
<property>
<name>yarn.resourcemanager.hostname.rm1</name>
<value>uplooking02</value>
</property>
<property>
<name>yarn.resourcemanager.hostname.rm2</name>
<value>uplooking03</value>
</property>
<!-- 指定zk集群地址 -->
<property>
<name>yarn.resourcemanager.zk-address</name>
<value>uplooking01:2181,uplooking02:2181,uplooking03:2181</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
4、准备hadoop所需要的几个目录
[uplooking@uplooking01 hadoop]$ mkdir -p /home/uplooking/data/hadoop/journal
[uplooking@uplooking01 hadoop]$ mkdir -p /home/uplooking/data/hadoop/name
[uplooking@uplooking01 hadoop]$ mkdir -p /home/uplooking/data/hadoop/data
[uplooking@uplooking01 hadoop]$ mkdir -p /home/uplooking/data/hadoop/tmp
5、同步到uplooking02和uplooking03
[uplooking@uplooking01 ~]$ scp -r data/hadoop uplooking@uplooking02:/home/uplooking/data/
[uplooking@uplooking01 ~]$ scp -r data/hadoop uplooking@uplooking03:/home/uplooking/data/
[uplooking@uplooking01 ~]$ scp -r app/hadoop uplooking@uplooking02:/home/uplooking/app/
[uplooking@uplooking01 ~]$ scp -r app/hadoop uplooking@uplooking03:/home/uplooking/app/
6、格式化&启动
1°、启动zk
2°、启动jouralnode
hadoop-deamon.sh start journalnode
3°、在uplooking01或者uplooking02中的一台机器上面格式化hdfs
hdfs namenode -format
18/03/02 11:16:20 INFO common.Storage: Storage directory /home/uplooking/data/hadoop/name has been successfully formatted.
说明格式化成功
将格式化后的namenode的元数据信息拷贝到另外一台namenode之上就可以了
将uplooking01上面产生的namenode的元数据信息,拷贝到uplooking02上面,
scp -r /home/uplooking/data/hadoop/name uplooking@uplooking02:/home/uplooking/data/hadoop/
4°、格式化zkfc
hdfs zkfc -formatZK
实际上是在zookeeper中创建一个目录节点/hadoop-ha/ns1
5°、启动hdfs
在uplooking01机器上面或者uplooking02上面启动、start-dfs.sh
6、启动yarn
在yarn配置的机器上面启动start-yarn.sh
在uplooking02上面启动start-yarn.sh
在uplooking03上面启动脚本
yarn-daemon.sh start resourcemanager
7°、要启动hdfs中某一个节点,使用脚本hadoop-daemon.sh start 节点进程名
7、访问和验证
1°、访问
web
hdfs
http://uplooking01:50070
http://uplooking02:50070
其中一个是active,一个是standby
yarn
http://uplooking02:8088
http://uplooking03:8088
在浏览的时候standby会重定向跳转之active对应的页面
shell
我们是无法操作standby对应的hdfs的,只能操作active的namenode
Operation category READ is not supported in state standby
2、ha的验证
NameNode HA
访问:
uplooking01:50070
uplooking02:50070
其中一个active的状态,一个是StandBy的状态
当访问standby的namenode时候:
Operation category READ is not supported in state standby
Yarn HA
web访问:默认端口是8088
uplooking02:8088
uplooking03:8088
This is standby RM. Redirecting to the current active RM: http://uplooking02:8088/
3、简单操作
cd /home/uplooking/app/hadoop/share/hadoop/mapreduce
[uplooking@uplooking01 mapreduce]$ yarn jar hadoop-mapreduce-examples-2.6.4.jar wordcount /hello /output/mr/wc
-------------------------------------------------------------------------------
给普通用户添加sudo
step 1、切换到root用户下面
step 2、给/etc/sudoers文件添加写的权限
[root@uplooking01 uplooking]# ll /etc/sudoers
-r--r-----. 1 root root 4002 Mar 1 2012 /etc/sudoers
[root@uplooking01 uplooking]# chmod u+w /etc/sudoers
step 3、在/etc/sudoers添加一行内容
uplooking ALL=(ALL) ALL(大概在99行的位置)
step 4、完毕之后提取写的权限
[root@uplooking01 uplooking]# chmod u-w /etc/sudoers
step 5、同步sudoers到其它的机器上面
[root@uplooking01 uplooking]# scp /etc/sudoers root@uplooking02:/etc/
[root@uplooking01 uplooking]# scp /etc/sudoers root@uplooking03:/etc/
-------------------------------------------------------------------------------
MapReduce
MapReduce是一种分布式计算模型,由Google提出,主要用于搜索领域,解决海量数据的计算问题。
MapReduce是分布式运行的,由两个阶段组成:Map和Reduce,Map阶段是一个独立的程序,有很多个节点同时运行,每个节点处理一部分数据。Reduce阶段是一个独立的程序,有很多个节点同时运行,每个节点处理一部分数据。
MapReduce框架都有默认实现,用户只需要覆盖map()和reduce()两个函数,即可实现分布式计算,非常简单。这两个函数的形参和返回值都是<key、 value>,使用的时候一定要注意构造<k,v>。
MapReduce在处理多于10PB数据时趋向于变慢。
zookeeper集群搭建
最新推荐文章于 2024-04-12 16:25:44 发布