美文网首页
Hadoop伪分布式安装

Hadoop伪分布式安装

作者: 小左伯爵 | 来源:发表于2020-11-22 19:26 被阅读0次

    Hadoop也可以以伪分布式模式在单节点上运行,其中每个Hadoop守护程序都在单独的Java进程中运行。
    hadoop简介
    https://www.cnblogs.com/mh20131118/p/12146993.html

    1.修改HOSTNAME

    [root@localhost ~]# vim /etc/sysconfig/network
    NETWORKING=yes
    HOSTNAME=node00
    

    2.修改/etc/hosts,追加内容

    [root@localhost ~]# vim /etc/hosts
    192.168.52.80 node00
    

    3.关闭selinux

    [root@localhost ~]# vim /etc/sysconfig/selinux
    SELINUX=disabled
    SELINUXTYPE=targeted
    

    4.配置免秘钥登录

    现在检查您是否可以在没有密码的情况下SSH到本地主机
    如果没有密码就无法SSH到localhost,请执行以下命令
    #ssh-keygen 秘钥生成器
    #-t rsa 生成的类型为rsa
    #-P 是否需要密码 ''不需要密码
    #-f 文件存放位置
    [root@localhost hadoop-3.2.1]# ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
    Generating public/private rsa key pair.
    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/id_rsa.pub.
    The key fingerprint is:
    8a:0d:c8:d4:08:1f:e1:4f:b2:b0:e5:31:f2:0b:d5:3b root@localhost.localdomain
    The key's randomart image is:
    +--[ RSA 2048]----+
    |. o.             |
    | + =             |
    |o @ +            |
    | @ O .           |
    |o * E   S        |
    | . . = .         |
    |  . . o          |
    |                 |
    |                 |
    +-----------------+
    [root@localhost hadoop-3.2.1]# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
    [root@localhost hadoop-3.2.1]# chmod 0600 ~/.ssh/authorized_keys
    

    5. 修改主节点namenode配置

    #默认值地址https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/core-default.xml
    [root@localhost hadoop-3.2.1]# vim etc/hadoop/core-site.xml
    <configuration>
    <property>
          <name>fs.defaultFS</name>
          <value>hdfs://node00:9000</value>
    </property>
    <property>
          <name>hadoop.tmp.dir</name>
          <value>/opt/hadoop/pseudo</value>
    </property>
    </configuration>
    
    

    6.修改workers

    [root@localhost hadoop]# vim /opt/hadoop/hadoop-3.2.1/etc/hadoop/workers 
    #改为
    node00
    

    7.修改从节点的配置

    [root@localhost hadoop-3.2.1]# vim etc/hadoop/hdfs-site.xml
    <configuration>
        <property>
            <name>dfs.replication</name>
            <value>1</value>
        </property>
        <property>
            <name>dfs.namenode.secondary.http-address</name>
            <value>node00:9868</value>
        </property>
    </configuration>
    

    8.格式化

    [root@localhost hadoop]# hdfs namenode -format
    #格式化后查看生成的信息
    [root@localhost current]# view /opt/hadoop/pseudo/dfs/name/current/VERSION
    #格式化时只生成namenode的信息,datanode和secondary-namenode的信息会在集群启动时生成
    
    

    9.启动

    [root@localhost pseudo]# start-dfs.sh
    WARNING: HADOOP_SECURE_DN_USER has been replaced by HDFS_DATANODE_SECURE_USER. Using value of HADOOP_SECURE_DN_USER.
    Starting namenodes on [node00]
    Starting datanodes
    Starting secondary namenodes [node00]
    [root@localhost pseudo]# jps
    67649 Jps
    67313 DataNode
    67488 SecondaryNameNode
    67146 NameNode
    

    问题

    #2.启动NameNode守护程序和DataNode守护程序
    若在启动时产生以下问题
    [root@localhost hadoop-3.2.1]# sbin/start-dfs.sh
    Starting namenodes on [localhost]
    ERROR: Attempting to operate on hdfs namenode as root
    ERROR: but there is no HDFS_NAMENODE_USER defined. Aborting operation.
    Starting datanodes
    ERROR: Attempting to operate on hdfs datanode as root
    ERROR: but there is no HDFS_DATANODE_USER defined. Aborting operation.
    Starting secondary namenodes [localhost.localdomain]
    ERROR: Attempting to operate on hdfs secondarynamenode as root
    ERROR: but there is no HDFS_SECONDARYNAMENODE_USER defined. Aborting operation.
    2020-11-22 22:25:22,882 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
    #出错,大概意思不允许root用户启动,修改启动命令
    [root@localhost hadoop-3.2.1]# vim sbin/start-dfs.sh
    #添加以下内容
    HDFS_DATANODE_USER=root
    HADOOP_SECURE_DN_USER=hdfs
    HDFS_NAMENODE_USER=root
    HDFS_SECONDARYNAMENODE_USER=root
    #对sbin/stop-dfs.sh执行同样的操作
    #重新启动
    WARNING: HADOOP_SECURE_DN_USER has been replaced by HDFS_DATANODE_SECURE_USER. Using value of HADOOP_SECURE_DN_USER.
    Starting namenodes on [localhost]
    Starting datanodes
    Starting secondary namenodes [localhost.localdomain]
    localhost.localdomain: Warning: Permanently added 'localhost.localdomain' (RSA) to the list of known hosts.
    2020-11-22 22:31:52,397 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
    #解决Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
    vim /etc/profile
    #添加
    export HADOOP_ROOT_LOGGER=DEBUG,console
    source /etc/profile
    #查看详细报错信息,有这样一条报错信息
    2020-11-22 22:51:41,027 DEBUG util.NativeCodeLoader: Failed to load native-hadoop with error: java.lang.UnsatisfiedLinkError: /opt/hadoop/hadoop-3.2.1/lib/native/libhadoop.so.1.0.0: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by /opt/hadoop/hadoop-3.2.1/lib/native/libhadoop.so.1.0.0)
    `GLIBC_2.14' not found
    #系统的glibc版本太低,查看当前系统的glibc支持的所有版本
    [root@localhost bin]# strings /lib64/libc.so.6 |grep GLIBC_
    GLIBC_2.2.5
    GLIBC_2.2.6
    GLIBC_2.3
    GLIBC_2.3.2
    GLIBC_2.3.3
    GLIBC_2.3.4
    GLIBC_2.4
    GLIBC_2.5
    GLIBC_2.6
    GLIBC_2.7
    GLIBC_2.8
    GLIBC_2.9
    GLIBC_2.10
    GLIBC_2.11
    GLIBC_2.12
    GLIBC_PRIVATE
    #下载glibc-2.17.tar.gz,地址
    http://ftp.gnu.org/gnu/glibc/glibc-2.17.tar.gz
    #安装的先决条件
    yum install gcc libffi-devel python-devel openssl-devel wget -y
    #使用默认的镜像下载会非常慢,改为阿里的镜像,下面是教程地址
    https://developer.aliyun.com/mirror/centos?spm=a2c6h.13651102.0.0.3e221b11sciRdQ
    从2020年12月以后,执行以下命令切换为阿里的源
    sed -i "s|enabled=1|enabled=0|g" /etc/yum/pluginconf.d/fastestmirror.conf
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    curl -o /etc/yum.repos.d/CentOS-Base.repo https://www.xmpan.com/Centos-6-Vault-Aliyun.repo 
    yum clean all
    yum makecache
    #解压
    [root@localhost glibc]# tar -xvf glibc-2.17.tar.gz
    [root@localhost glibc]# mkdir /opt/glibc/glibc-2.17/build
    [root@localhost glibc]# cd /opt/glibc/glibc-2.17/build/
    [root@localhost build]# ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
    [root@localhost build]# make && make install
    #先停止,再启动
    [root@localhost sbin]# ./stop-dfs.sh
    [root@localhost sbin]# ./start-dfs.sh
    [root@localhost sbin]# jps
    62514 Jps
    62355 SecondaryNameNode
    62149 DataNode
    61981 NameNode
    
    

    9.浏览器访问,默认端口9870

    http://192.168.52.80:9870/dfshealth.html#tab-overview

    2020-11-22_160416.jpg

    10.创建执行MapReduce(计算框架)的HDFS(分布式存储系统)目录

    #帮助命令
    [root@localhost hadoop-3.2.1]# ./bin/hdfs dfs --help
    #创建目录(默认)
    [root@localhost hadoop-3.2.1]# ./bin/hdfs dfs -mkdir /user
    [root@localhost hadoop-3.2.1]# ./bin/hdfs dfs -mkdir /user/root
    #在浏览器上查看创建的目录
    #删除目录
    [root@localhost hadoop-3.2.1]# ./bin/hdfs dfs -rm -r /user/root
    
    2020-11-22_163055.jpg

    11.复制输入文件到HDFS

    #默认到/user/root目录下
    [root@localhost hadoop-3.2.1]# bin/hdfs dfs -mkdir input
    [root@localhost hadoop-3.2.1]# bin/hdfs dfs -put etc/hadoop/*.xml input
    #查看
    
    2020-11-22_170253.jpg

    12.运行一些例子

    hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.2.1.jar grep input output 'dfs[a-z.]+'
    

    相关文章

      网友评论

          本文标题:Hadoop伪分布式安装

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