服务器规划
br-apm-001 | br-apm-002 | br-apm-003 |
---|---|---|
zookeeper | zookeeper | zookeeper |
jdk | jdk | jdk |
namenode | namenode | |
datanode | datanode | datanode |
ResourceManage | ResourceManage | |
NodeManager | NodeManager | NodeManager |
# 解压到安装目录 tar -zxvf jdk-8u212-linux-x64.tar.gz -C /data/br/base # 配置环境变量 export JAVA_HOME=/data/br/base/jdk export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar # 拷贝至其他服务器 scp -P2226 /etc/profile root@10.241.80.124 scp -P2226 /etc/profile root@10.241.80.125 # 3台服务器分别执行,使其生效 source /etc/profile java -version |
---|
tar -zxvf zookeeper-3.5.6-bin.tar.gz -C /data/br/base
# 修改zoo.cfg配置文件
tickTime=6000
initLimit=10
syncLimit=5
clientPort=2181
admin.serverPort=18080
admin.enableServer=false
#设置zk文件存放目录
dataDir=/data/br/base/zookeeper/data
autopurge.snapRetainCount=3
autopurge.purgeInterval=1
maxClientCnxns=500
#指定zk集群中各个机器的信息
server.1:br-apm-001:2888:3888
server.2:br-apm-002:2888:3888
server.3:br-apm-003:2888:3888 | | —- | 2)拷贝到其他服务器 | #拷贝至br-apm-002
scp -P2226 /etc/profile root@10.241.80.124
#拷贝至br-apm-003
scp -P2226 /etc/profile root@10.241.80.125 | | —- | 3)创建myid文件 | # 每台服务器添加内容为server.X:br-apm-001:2888:3888中的server后的数字
echo ‘1’ > /data/br/base/data/myid #(br-apm-001)
echo ‘2’ > /data/br/base/data/myid #(br-apm-002)
echo ‘3’ > /data/br/base/data/myid #(br-apm-003) | | —- | 4)启动集群 | # 添加/etc/profile
export ZOOKEEPER_HOME=/data/br/base/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
export ZK_SERVER_HEAP=“-Xms1024m -Xmx1024m”
source /etc/profile
# 3台服务器分别执行
bin/zkServer.sh start | | —- | 4、 hadoop安装 1) 配置服务器 # 解压到指定目录 tar -zxvf hadoop-3.3.1 -C /data/br/base/ # 配置环境变量 export HADOOP_HOME=“/data/br/base/hadoop-3.3.2” export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin source /etc/profile 2)修改配置文件 (1) hadoop-env.sh、 mapred-env.sh、yarn-env.sh文件的JAVA_HOME参数 | # hadoop/etc/hadoop/文件
export JAVA_HOME=/data/br/base/jdk | | —- | (2)core-site.xml vim ${HADOOP_HOME}/etc/hadoop/core-site.xml <?xml version=”1.0”?>
namenode格式化默认存放路径:${HADOOP_HOME}/dfs/name/current/ VERSION datanode格式化默认存放路径:${HADOOP_HOME}/dfs/data/current/ VERSION fs.defaultFS 配置的是HDFS的地址。 hadoop.tmp.dir配置的是Hadoop临时目录,比如HDFS的NameNode数据默认都存放这个目录下,查看*- default.xml等默认配置文件,就可以看到很多依赖${hadoop.tmp.dir}的配置。默认的 hadoop.tmp.dir是/tmp/hadoop-${user.name},此时有个问题就是NameNode会将HDFS的元数据存储在 这个/tmp目录下,如果操作系统重启了,系统会清空/tmp目录下的东西,导致NameNode元数据丢失,是个非 常严重的问题,所以,必须修改这个路径。 |
---|
(3) hdfs-site.xml
<?xml version=”1.0” encoding=”UTF-8”?> <?xml-stylesheet type=”text/xsl” href=”configuration.xsl”?> <!— Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. See accompanying LICENSE file. —>(4) mapred-site.xml
vim ${HADOOP_HOME}/etc/hadoop/mapred-site.xml <?xml version=”1.0”?> <?xml-stylesheet type=”text/xsl” href=”configuration.xsl”?> <!— Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. See accompanying LICENSE file. —>(5)yarn-site.xml
ResouceManager记录着当前集群的资源分配情况和JOB运行状态,YRAN HA 利用Zookeeper等共享 存储介质来存储这些信息来达到高可用。利用Zookeeper来实现ResourceManager自动故障转移。 MasterHADaemon:控制RM的 Master的启动和停止,和RM运行在一个进程中,可以接收外部RPC命 令。 共享存储:Active Master将信息写入共享存储,Standby Master读取共享存储信息以保持和 Active Master同步。 ZKFailoverController:基于Zookeeper实现的切换控制器,由ActiveStandbyElector和 HealthMonitor组成,ActiveStandbyElector负责与Zookeeper交互,判断所管理的Master是进入 Active还是Standby;HealthMonitor负责监控Master的活动健康情况,是个监视器。 Zookeeper:核心功能是维护一把全局锁控制整个集群上只有一个Active的ResourceManager。 vim ${HADOOP_HOME}/etc/hadoop/yarn-site.xml <?xml version=”1.0”?> <!— Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. See accompanying LICENSE file. —>vim ${HADOOP_HOME}/etc/hadoop/slaves #指定hdfs上有哪些datanode节点 br-apm-001 br-apm-002 br-apm-003 |
---|
格式化是对HDFS这个分布式文件系统中的DataNode进行分块,统计所有分块后的初始元数据的存储在 NameNode中。 格式化后,查看core-site.xml里hadoop.tmp.dir(/data/br/base/hadoop/tmp目录)指定的 目录下是否有了dfs目录,如果有,说明格式化成功。 因为按照前面的规划01,02两台机器分配NameNode,需格式化。 |
---|
hadoop-daemon.sh start journalnode
# 三台服务器启动zk集群
zkServer.sh start
# br-apm-001机器进行namenode格式化
hdfs namenode -format
hadoop-daemon.sh start namenode
# br-apm-002机器进行namenode格式化(br-apm-001需要先启动namenode)
hdfs namenode -bootstrapStandby
hadoop-daemon.sh start namenode | | —- | | fsimage是NameNode元数据在内存满了后,持久化保存到的文件。
fsimage.md5 是校验文件,用于校验fsimage的完整性。
seen_txid 是hadoop的版本
vession文件里保存
namespaceID:NameNode的唯一ID
clusterID:集群ID NameNode和DataNode的集群ID应该一致,表明是一个集群。
注意:
如果需要重新格式化NameNode,需要先将原来NameNode和DataNode下的文件全部删除,不然会报错,
NameNode和DataNode所在目录是在core-site.xml中hadoop.tmp.dir、dfs.namenode.name.dir、 dfs.datanode.data.dir属性配置的。
因为每次格式化,默认是创建一个集群ID,并写入NameNode和DataNode的VERSION文件中(VERSION文件 所在目录为dfs/name/current 和 dfs/data/current),重新格式化时,默认会生成一个新的集群ID, 如果不删除原来的目录,会导致namenode中的VERSION文件中是新的集群ID,而DataNode中是旧的集群
ID,不一致时会报错。 | | —- | | # 格式化zk
hdfs zkfc -formatZK
# 启动集群启动,集群NameNode、DataNode、JournalNode、zkfc(zkfc只针对NameNode监听)
${HADOOP_HOME}/sbin/start-dfs.sh
# br-apm-001启动yarn
sbin/start-yarn.sh
# br-apm-002和br-apm-003上启动resourcemanager:
sbin/yarn-daemon.sh start resourcemanager | | —- | 7*、开启历史服务 Hadoop开启历史服务可以在web页面上查看Yarn上执行job情况的详细信息。可以通过历史服务器查看已经运 行完的Mapreduce作业记录,比如用了多少个Map、用了多少个Reduce、作业提交时间、作业启动时间、作 业完成时间等信息。 开启历史服务 sbin/mr-jobhistory-daemon.sh start historyserver web页面查看地址http://br-apm-001:19888/ 历史服务器的Web端口默认是19888,可以查看Web界面。 但是在上面所显示的某一个Job任务页面的最下面,Map和Reduce个数的链接上,点击进入Map的详细信息页 面,再查看某一个Map或者Reduce的详细日志是看不到的,是因为没有开启日志聚集服务。
8、查看进程
jps |
---|
#注意:如果使用hostname访问 ,需要配置宿主机的 hostname:C:\Windows\System32\drivers\etc**下的hosts文件,添加下面两行 br-apm-001 10.241.80.123 br-apm-002 10.241.80.124 br-apm-003 10.241.80.125 |
---|