美文网首页
hadoop2.6.0-cdh5.7伪分布式安装(2018-12

hadoop2.6.0-cdh5.7伪分布式安装(2018-12

作者: 程序猿TT | 来源:发表于2019-04-16 09:33 被阅读0次

    1、安装jdk

    • 解压 : tar -zxvf jdk-8u191-linux-x64.tar.gz -C /home/hadoop/app/
    • 配置环境变量 : vim ~/.bash_profile
      添加:
    export JAVA_HOME=/home/hadoop/app/jdk1.8.0_191
    export PATH=$JAVA_HOME/bin:$PATH
    
    • 使环境变量生效 : source ~/.bash_profile
    • 验证java : java -version

    2、安装ssh

    • yum 安装: yum install ssh
    • 免密登录ssh : ssh-keygen -t rsa
    • 拷贝文件: cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys

    3、下载并解压hadoop

    • 下载 : 直接去cdh网站下载
    • 解压 : tar -zxvf hadoop-2.6.0-cdh5.7.0.tar.gz -C ../app/

    4、hadoop 配置文件的修改(hadoop_home/etc/hadoop)

    vim hadoop-env.sh
    // -----------------------------------------------------------------------(修改)
    export JAVA_HOME=/home/hadoop/app/jdk1.8.0_191
    
    // =========================================
    vim core-site.xml 
    // ------------------------------------------------------------------------
    <configuration>
        <property>
            <name>fs.defaultFS</name>
            <value>hdfs://hadoop:8020</value>
        </property>
        <property>
            <name>hadoop.tmp.dir</name>
            <value>/home/hadoop/app/tmp</value>
        </property>
    </configuration>
    // =========================================
    vim hdfs-site.xml 
    // ------------------------  副本节点 由于是伪分布式 节点只有一个,所以指定节点为1  -------------------
    <configuration>
        <property>
            <name>dfs.replication</name>
            <value>1</value>
        </property>
    </configuration>
    
    // ------------------------  配置slaves -------------------
    slaves
    

    5、启动hdfs

    • 格式化文件系统(仅第一次执行即可,不要重复执行): hdfs namenode -format
    • 启动hdfs : sbin/start-dfs.sh
    • 验证是否成功:
    # jps
    7796 SecondaryNameNode
    7529 NameNode
    7615 DataNode
    

    浏览器访问方式: http://192.168.80.83:50070

    6、 停止hdfs

    • sbin/stop-dfs.sh

    7、 Java API 操作HDFS文件

    public void listFiles() throws Exception {
            Path filePath = new Path("/hdfsapi/test/");
            FileStatus[] fileStaStatus = fileSystem.listStatus(filePath);
            for (FileStatus fileStatus : fileStaStatus) {
                boolean isDir = fileStatus.isDirectory();
                String status = isDir ? "文件夹" : "文件";
                short replication = fileStatus.getReplication();
                Long len = fileStatus.getLen();
                String path = fileStatus.getPath().toString();
                // 打印文件信息
                System.out.println(status + "\t" + replication + "\t" + len + "\t" + path);
            }
        }
    

    文件 3 243793920 hdfs://192.168.80.83:8020/hdfsapi/test/MySQL-5.6.tar
    文件 3 12 hdfs://192.168.80.83:8020/hdfsapi/test/b.txt
    文件 3 983911 hdfs://192.168.80.83:8020/hdfsapi/test/mysql-connector-java-5.1.38.jar

    • 问题 : 我们已经在hdfs-site.xml 中设置了副本系数为1,为什么此时查询文件看到的是3呢?
        public void listFiles() throws Exception {
            Path filePath = new Path("/");
            FileStatus[] fileStaStatus = fileSystem.listStatus(filePath);
            for (FileStatus fileStatus : fileStaStatus) {
                boolean isDir = fileStatus.isDirectory();
                String status = isDir ? "文件夹" : "文件";
                short replication = fileStatus.getReplication();
                Long len = fileStatus.getLen();
                String path = fileStatus.getPath().toString();
    
                System.out.println(status + "\t" + replication + "\t" + len + "\t" + path);
            }
        }
    

    文件 1 311585484 hdfs://192.168.80.83:8020/hadoop-2.6.0-cdh5.7.0.tar.gz
    文件夹 0 0 hdfs://192.168.80.83:8020/hdfsapi
    文件 1 51 hdfs://192.168.80.83:8020/hello.txt

    • 解释 : 如果是通过hdfs shell的方式put上去的,那么才会采用默认的副本系数1,如果用java api上传上去的,在本地我们并没有手工设置副本系数,所以采用的是hadoop默认的3

    8、Hadoop1.x 时:

    • MapReduce : Master/Slave 架构,一个JobTracker带多个TaskTracker
    • JobTracker : 负责资源管理和作业调度
    • TaskTracker : 定期向JT汇报本届点的健康状况,资源使用情况,作业执行情况;接受来自JT的命令: 启动/杀死任务
    • YARN(Yet Another Resource Negotiator) : 不同计算机框架可以共享同一个HDFS集群上的数据,享受整体的资源调度
    • XXX on YARN 好处 :与其他计算框架共享集群资源,按资源需要分配,进而提高集群资源的利用率
    • XXX : Spark/MapReduce/Storm/Flink

    9、YARN 架构

    • 1、ResourceManager(RM):
      整个集群同一时间提供服务的RM只有一个,负责集群资源的统一管理和调度;
      处理客户端的请求:提交一个作业,杀死一个作业;
      监控我们的NM,一旦某个NM挂了,那么该NM上运行的任务需要告诉我们的AM来如何进行处理

    • 2、NodeManager(NM):
      整个集群中有多个,负责自己本身节点资源管理和使用;
      定时向RM汇报本节点的资源使用情况;
      接收并处理来自RM各种命令:启动/关闭Container
      处理来自AM的命令
      单个节点的资源管理

    • 3、ApplicationMasger(AM)
      每个应用程序对应一个:MR、Spark,负责应用程序的管理
      为应用程序向RM申请资源(core、memory),分配给内部task
      需要与NM通信:启动/停止task,task是运行在container里面,AM也是运行在container里面

    • 4、Container
      封装了CPU、Memory等资源的一个容器
      是一个任务运行环境的抽象

    • 5、Client
      提交作业
      查询作业的进度
      杀死作业

    10 、YARN 环境搭建

    • mapred-site.xml
    <configuration>
        <property>
            <name>mapreduce.framework.name</name>
            <value>yarn</value>
        </property>
    </configuration>
    
    • yarn-site.xml
    <configuration>
        <property>
            <name>yarn.nodemanager.aux-services</name>
            <value>mapreduce_shuffle</value>
        </property>
    </configuration>
    
    • 启动YARN相关进程:sbin/start-yarn.sh
    • 验证
      jps : ResourceManager NodeManager
      http://localhost:8088/
    • 停止yarm相关的进程:sbin/stop-yarn.sh

    11、测试yarn

    • 提交作业到YARN上运行:/home/hadoop/app/hadoop-2.6.0-cdh5.7.0/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.0-cdh5.7.0.jar
    • 使用 (hadoop jar): hadoop jar hadoop-mapreduce-examples-2.6.0-cdh5.7.0.jar pi 2 3

    相关文章

      网友评论

          本文标题:hadoop2.6.0-cdh5.7伪分布式安装(2018-12

          本文链接:https://www.haomeiwen.com/subject/sjcthqtx.html