手动部署Hadoop2分布式集群和YARN集群管理命令

2019-03-30  本文已影响0人  任总

一、手动部署集群

实验环境

1、所有节点编辑名称解析

~]# vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.60 node60.hehe.com node60 master
192.168.1.61 node61.hehe.com node61
192.168.1.62 node62.hehe.com node62
192.168.1.63 node63.hehe.com node63

2、所有节点安装jdk-devel并配置java环境

~]# yum install java-1.8.0-openjdk-devel -y

#设置环境变量
 ~]# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

~]# . /etc/profile.d/java.sh

#验证版本
 ~]# java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

3、所有节点创建hadoop用户和组

~]# useradd hadoop
~]# echo '12345' | passwd --stdin hadoop

4、master主节点生成秘钥

[root@node-60 ~]# su - hadoop
[hadoop@node-60 ~]$ ssh-keygen -t rsa -P ''
.........
+---[RSA 2048]----+
| oo+oo.oo.       |
|  o.. +.o+       |
| .  . ooo.o      |
|  .. = X +.      |
| .. + = S.o      |
|++   . oo=.E     |
|=.  . . .*+      |
|     . .= .o     |
|      .ooo.      |
+----[SHA256]-----+

#同步到其他节点,别忘了给自己分发
[hadoop@node-60 ~]$ ssh-copy-id -i /home/hadoop/.ssh/id_rsa.pub hadoop@node60
[hadoop@node-60 ~]$ ssh-copy-id -i /home/hadoop/.ssh/id_rsa.pub hadoop@node61
[hadoop@node-60 ~]$ ssh-copy-id -i /home/hadoop/.ssh/id_rsa.pub hadoop@node62
[hadoop@node-60 ~]$ ssh-copy-id -i /home/hadoop/.ssh/id_rsa.pub hadoop@node63

#测试是否成功
[hadoop@node-60 ~]$ ssh node61 'date'
Fri Mar 15 22:17:31 CST 2019

5、master主节点创建目录

[root@node-60 ~]# mkdir -pv /bdapps /data/hadoop/hdfs/{nn,snn,dn}
[root@node-60 ~]# chown -R hadoop:hadoop /data/

6、master下载安装hadoop-2.7.7

[root@node-60 ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/hadoop-2.7.7/hadoop-2.7.7.tar.gz
#解压
[root@node-60 ~]# tar xf hadoop-2.7.7.tar.gz -C /bdapps/
[root@node-60 ~]# ln -sv /bdapps/hadoop-2.7.7/ /bdapps/hadoop
‘/bdapps/hadoop’ -> ‘/bdapps/hadoop-2.7.7/’
#配置环境变量,注意hadoop3.x版本HADOOP_PREFIX全部改为HADOOP_HOME
[root@node-60 ~]# vim /etc/profile.d/hadoop.sh
export HADOOP_PREFIX=/bdapps/hadoop
export PATH=$PATH:${HADOOP_PREFIX}/bin:${HADOOP_PREFIX}/sbin
export HADOOP_YARN_HOME=${HADOOP_PRFIX}
export HADOOP_MAPPERD_HOME=${HADOOP_PRFIX}
export HADOOP_COMMON_HOME=${HADOOP_PRFIX}
export HADOOP_HDFS_HOME=${HADOOP_PRFIX}
#创建日志目录
[root@node-60 ~]# mkdir /bdapps/hadoop/logs
[root@node-60 ~]# chmod g+w /bdapps/hadoop/logs
[root@node-60 ~]# chown -R hadoop:hadoop /bdapps/hadoop/*

7、maser主节点配置hadoop

#修改core-site文件
[root@node-60 ~]# vim /bdapps/hadoop/etc/hadoop/core-site.xml 
...........
<configuration>
      <property>
                <name>fs.defaultFS</name>
                <value>hdfs://master:8020</value>   #这里填写master主机名
                <final>true</final>
      </property>
</configuration>

#修改yarn-site文件
[root@node-60 ~]# vim /bdapps/hadoop/etc/hadoop/yarn-site.xml 
.............
<configuration>
                    <property>
                        <name>yarn.resourcemanager.address</name>
                        <value>master:8032</value> 
                    </property>
                    <property>
                        <name>yarn.resourcemanager.scheduler.address</name>
                        <value>master:8030</value> 
                    </property>
                    <property>
                        <name>yarn.resourcemanager.resource-tracker.address</name>
                        <value>master:8031</value>
                    </property>
                    <property>
                        <name>yarn.resourcemanager.admin.address</name>
                        <value>master:8033</value>
                    </property>
                    <property>
                        <name>yarn.resourcemanager.webapp.address</name>
                        <value>master:8088</value> 
                    </property>
                    <property>
                        <name>yarn.nodemanager.aux-services</name>
                        <value>mapreduce_shuffle</value>
                    </property>
                    <property>
                        <name>yarn.nodemanager.auxservices.mapreduce_shuffle.class</name>
                  </property>
    </configuration>
#修改hdfs-site文件
[root@node-60 ~]# vim /bdapps/hadoop/etc/hadoop/hdfs-site.xml 
............
<configuration>
                    <property>
                        <name>dfs.replication</name>
                        <value>2</value> #副本数量2
                    </property>
                    <property>
                        <name>dfs.namenode.name.dir</name>
                        <value>file:///data/hadoop/hdfs/nn</value>
                    </property>
                    <property>
                        <name>dfs.datanode.data.dir</name>
                        <value>file:///data/hadoop/hdfs/dn</value>
                    </property>
                    <property>
                        <name>fs.checkpoint.dir</name>
                        <value>file:///data/hadoop/hdfs/snn</value>
                    </property>
                    <property>
                        <name>fs.checkpoint.edits.dir</name>
                        <value>file:///data/hadoop/hdfs/snn</value>
                    </property>
                </configuration>

#修改mapred-site文件
[root@node-60 ~]# vim /bdapps/hadoop/etc/hadoop/mapred-site.xml
..........
<configuration>
                 <property>
                        <name>mapreduce.framework.name</name>
                        <value>yarn</value>
                    </property>

</configuration>

#修改slaves文件定义从节点 ,如果是hadoop3.X版本改名叫worker文件
 ~]# vim /bdapps/hadoop/etc/hadoop/slaves 

node61
node62
node63

8、三个node从节点创建目录

 ~]# mkdir -pv /bdapps /data/hadoop/hdfs/{nn,snn,dn}
 ~]# chown -R hadoop:hadoop /data/

9、三个node从节点下载安装hadoop

 ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/hadoop-2.7.7/hadoop-2.7.7.tar.gz
#解压
~]# tar xf hadoop-2.7.7.tar.gz -C /bdapps/
 ~]# ln -sv /bdapps/hadoop-2.7.7/ /bdapps/hadoop
‘/bdapps/hadoop’ -> ‘/bdapps/hadoop-2.7.7/’

#配置环境变量,注意hadoop3.x版本HADOOP_PREFIX全部改为HADOOP_HOME
 ~]# vim /etc/profile.d/hadoop.sh
export HADOOP_PREFIX=/bdapps/hadoop
export PATH=$PATH:${HADOOP_PREFIX}/bin:${HADOOP_PREFIX}/sbin
export HADOOP_YARN_HOME=${HADOOP_PRFIX}
export HADOOP_MAPPERD_HOME=${HADOOP_PRFIX}
export HADOOP_COMMON_HOME=${HADOOP_PRFIX}
export HADOOP_HDFS_HOME=${HADOOP_PRFIX}

#创建日志目录
~]# mkdir /bdapps/hadoop/logs
 ~]# chmod g+w /bdapps/hadoop/logs
 ~]# chown -R hadoop:hadoop /bdapps/hadoop/*

10、master节点上使用hadoop用户,同步配置到三个node从节点上

[root@node-60 ~]# su - hadoop
[hadoop@node-60 ~]$ scp /bdapps/hadoop/etc/hadoop/* node61:/bdapps/hadoop/etc/hadoop/
[hadoop@node-60 ~]$ scp /bdapps/hadoop/etc/hadoop/* node62:/bdapps/hadoop/etc/hadoop/
[hadoop@node-60 ~]$ scp /bdapps/hadoop/etc/hadoop/* node63:/bdapps/hadoop/etc/hadoop/

11、格式化文件系统

[root@node-60 ~]# hdfs namenode -format
#数据目录下将会生成文件
[root@node-60 ~]# ls /data/hadoop/hdfs/nn/
current

12、启动集群

[root@node-60 ~]# su - hadoop
[hadoop@node-60 ~]$ start-dfs.sh
Starting namenodes on [master]   #首先启动主节点
hadoop@master's password: 
master: starting namenode, logging to /bdapps/hadoop/logs/hadoop-hadoop-namenodenode-60.out
node61: starting datanode, logging to /bdapps/hadoop/logs/hadoop-hadoop-datanodenode-61.out
node62: starting datanode, logging to /bdapps/hadoop/logs/hadoop-hadoop-datanodenode-62.out
node63: starting datanode, logging to /bdapps/hadoop/logs/hadoop-hadoop-datanodenode-63.out
Starting secondary namenodes [0.0.0.0]
hadoop@0.0.0.0's password: 
0.0.0.0: starting secondarynamenode, logging to /bdapps/hadoop/logs/hadoop-hadoop-secondarynamenode-node-60.out

#启动yarn集群
[hadoop@node-60 ~]$ start-yarn.sh
starting yarn daemons
starting resourcemanager, logging to /bdapps/hadoop/logs/yarn-hadoop-resourcemanager-node-60.out
node63: starting nodemanager, logging to /bdapps/hadoop/logs/yarn-hadoop-nodemanager-node-63.out
node62: starting nodemanager, logging to /bdapps/hadoop/logs/yarn-hadoop-nodemanager-node-62.out
node61: starting nodemanager, logging to /bdapps/hadoop/logs/yarn-hadoop-nodemanager-node-61.out

[hadoop@node-60 ~]$ jps #查询进程是否启动
7875 Jps
7077 NameNode
7274 SecondaryNameNode
7611 ResourceManager     #出现  ResourceManager进程证明yarn集群启用成功


13、检查三个node节点是否启动

 ~]# su - hadoop
[hadoop@node-61 ~]$ jps
8898 DataNode      #出现DataNode进程证明节点启用成功
9042 NodeManager  #出现 NodeManager进程证明yarn集群启用成功
8972 Jps

14、上传文档测试

[hadoop@node-60 ~]$ hdfs dfs -mkdir /test      #创建目录
[hadoop@node-60 ~]$ hdfs dfs -put /etc/fstab /test/fstab  #上传文件
[hadoop@node-60 ~]$ hdfs dfs -ls -R /test     #查询
-rw-r--r--   2 hadoop supergroup        465 2019-03-29 22:57 /test/fstab
#数据存储节点一
[hadoop@node-61 ~]$ cat  /data/hadoop/hdfs/dn/current/BP-2007480771-192.168.1.60-1553870591051/current/finalized/subdir0/subdir0/blk_1073741825
# /etc/fstab
.............
#数据存储节点二
[hadoop@node-62 ~]$ cat  /data/hadoop/hdfs/dn/current/BP-2007480771-192.168.1.60-1553870591051/current/finalized/subdir0/subdir0/blk_1073741825
# /etc/fstab
.............

集群的web界面访问

存储web

15、执行任务测试

#使用示例程序统计fstab文件
[hadoop@node-60 ~]$ yarn jar /bdapps/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.7.jar wordcount /test/fstab /test/wc   

任务web

二、YARN集群管理命令

[hadoop@node-60 ~]$ yarn
格式: yarn [--config confdir] [COMMAND | CLASSNAME]

#管理命令
  resourcemanager -format-state-store   删除RM的存储
  resourcemanager                      运行 ResourceManager
  nodemanager                          运行一个 nodemanager 在每个从节点上
  timelineserver                       运行时间线服务,任务编排时候用
  rmadmin                              管理工具
  sharedcachemanager                    run the SharedCacheManager daemon
  scmadmin                              SharedCacheManager admin tools
  daemonlog                             get/set the log level for each
                                        daemon
#用户命令
  version                               显示版本号
  jar <jar>                            运行jar文件
  application                           显示应用相关信息
                                        report/kill application
  applicationattempt                显示应用相关报告
  container                             显示容器的相关信息
  node                                  显示node节点信息
  queue                                 显示队列信息
  logs                                  显示日志
  classpath                        显示java程序运行时的类加载路径或类搜索路径
  cluster                               prints cluster information

1、用户命令

用户命令为Hadoop-YARN客户端命令。这些客户端根据yarn-site.xml中的配置参数连接至YARN服务,并按需运行指定的命令。

(1)、jar命令
 ~]$ yarn jar /bdapps/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.7.jar wordcount /test/fstab /test/wc

(2)、application命令

[hadoop@node-60 ~]$ yarn application -list -appStates=all
19/03/30 21:26:53 INFO client.RMProxy: Connecting to ResourceManager at master/192.168.1.60:8032
Total number of applications (application-types: [] and states: [NEW, NEW_SAVING, SUBMITTED, ACCEPTED, RUNNING, FINISHED, FAILED, KILLED]):1
                Application-Id      Application-Name        Application-Type          User       Queue               State         Final-State         Progress                       Tracking-URL
application_1553872144720_0001            word count               MAPREDUCE        hadoop     default            ACCEPTED           UNDEFINED               0%                                N/A

[hadoop@node-60 ~]$ yarn application -status application_1553872144720_0001
19/03/30 21:29:16 INFO client.RMProxy: Connecting to ResourceManager at master/192.168.1.60:8032
Application Report : 
    Application-Id : application_1553872144720_0001
    Application-Name : word count
    Application-Type : MAPREDUCE
    User : hadoop
    Queue : default
    Start-Time : 1553873531484
    Finish-Time : 0
    Progress : 0%           #进度
    State : ACCEPTED
    Final-State : UNDEFINED
    Tracking-URL : N/A
    RPC Port : -1
    AM Host : N/A
    Aggregate Resource Allocation : 161842915 MB-seconds, 79024 vcore-seconds
    Diagnostics : 

#删除指定application
[hadoop@node-60 ~]$ yarn application -kill  application_1553872144720_0001
19/03/30 21:40:11 INFO client.RMProxy: Connecting to ResourceManager at master/192.168.1.60:8032
Killing application application_1553872144720_0001
19/03/30 21:40:12 INFO impl.YarnClientImpl: Killed application application_1553872144720_0001

#再次查询
[hadoop@node-60 ~]$ yarn application -list -appStates=all
19/03/30 21:40:21 INFO client.RMProxy: Connecting to ResourceManager at master/192.168.1.60:8032
Total number of applications (application-types: [] and states: [NEW, NEW_SAVING, SUBMITTED, ACCEPTED, RUNNING, FINISHED, FAILED, KILLED]):1
                Application-Id      Application-Name        Application-Type          User       Queue               State         Final-State         Progress                       Tracking-URL
application_1553872144720_0001            word count               MAPREDUCE        hadoop     default              KILLED              KILLED               0%http://master:8088/cluster/app/application_1553872144720_0001

(3)、node命令

[hadoop@node-60 ~]$ yarn node -list
19/03/30 21:50:27 INFO client.RMProxy: Connecting to ResourceManager at master/192.168.1.60:8032
Total Nodes:3
         Node-Id         Node-State Node-Http-Address   Number-of-Running-Containers
   node-63:34547            RUNNING      node-63:8042                              0
   node-61:40811            RUNNING      node-61:8042                              0
   node-62:40608            RUNNING      node-62:8042                              0

[hadoop@node-60 ~]$ yarn node -status  node-63:34547
19/03/30 21:56:46 INFO client.RMProxy: Connecting to ResourceManager at master/192.168.1.60:8032
Node Report : 
    Node-Id : node-63:34547
    Rack : /default-rack
    Node-State : RUNNING
    Node-Http-Address : node-63:8042
    Last-Health-Update : Sat 30/Mar/19 09:55:11:112CST
    Health-Report : 
    Containers : 0
    Memory-Used : 0MB
    Memory-Capacity : 8192MB
    CPU-Used : 0 vcores
    CPU-Capacity : 8 vcores
    Node-Labels : 
(4)、logs命令
[hadoop@node-60 ~]$ yarn logs -applicationId application_1553872144720_0001

(5)、classpath命令
hadoop@node-60 ~]$ yarn classpath
(6)、version命令
[hadoop@node-60 ~]$ yarn version
Hadoop 2.7.7
.........

2、管理命令

这几个管理命令主要用于在节点上启动相应的服务
(1)、RMAdmin命令

常用选项:
-refreshQueues:重载队列的acl、状态及调用器队列;它会根据文件中的配置信息重新初始化调用器;
-refreshNodes:为RM刷新主机信息,通过读取RM节点的include和exclude文件来更新集群所需要包含或排除的节点列表;
-refreshUserToGroupsMappings:根据配置Hadoop安全组映射,通过刷新组缓存中的信息来更新用户和组之间的映射关系;
-refreshSuperUserGroupsConfiguration:刷新超级用户代理组映射,以及更新代理主机和core-site.xml配置文件中hadoop.proxyuser属性定义的代理组;
-refreshAdminAcls:根据yarn站点配置文件或默认配置文件中的yarn.admin.acl属性刷新RM的管理ACL;
-refreshServiceAcl:重载服务级别授权策略文件,而后RM将重载授权策略文件;它会检查Hadoop安全授权是否启用并为IPC Server、ApplicationMaster、Client和Resource tracker刷新ACL;

[hadoop@node-60 ~]$ yarn rmadmin -refreshNodes
(2)、DaemonLog命令

常用选项:
-getLevel host:port name :显示指定守护进程日志级别
-getLevel host:port name level: 设置守护进程的日志级别

三、运行YARN Application过程

阶段一、Application初始化及提交;
阶段二、分配内存并启动AM;
阶段三、AM注册及资源分配;
阶段四、启动并监控容器;
阶段五、Application进度报告;
阶段六、Application运行完成;

四、利用admbari部署hadoop集群简介

1、 Ambari项目

2、Ambari主要特点:

提供Hadoop集群
管理Hadoop集群
监控Hadoop集群

五、hadoop3.x安装遇到的问题

 ~]# vim /etc/profile.d/hadoop.sh
export HADOOP_HOME=/bdapps/hadoop
export PATH=$PATH:${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin
export HADOOP_YARN_HOME=${HADOOP_HOME}
export HADOOP_MAPPERD_HOME=${HADOOP_HOME}
export HADOOP_COMMON_HOME=${HADOOP_HOME}
export HADOOP_HDFS_HOME=${HADOOP_HOME}

~]# unset HADOOP_PREFIX     #删除HADOOP_PREFIX变量
~]# source /etc/profile               #设置生效
~]# evn | grep -i hadoop            #查询
 ~]# vim /bdapps/hadoop/etc/hadoop/worker 

官网地址:http://ambari.apache.org/
安装部署参考文档地址:https://cwiki.apache.org/confluence/display/AMBARI/Installation+Guide+for+Ambari+2.7.3

上一篇下一篇

猜你喜欢

热点阅读