首页 > 代码库 > hadoop2.4.1 伪分布

hadoop2.4.1 伪分布

        最终的 /etc/profile :#在文件最后添加

       # /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

# It‘s NOT a good idea to change this file unless you know what you
# are doing. It‘s much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

pathmunge () {
    case ":${PATH}:" in
        *:"$1":*)
            ;;
        *)
            if [ "$2" = "after" ] ; then
                PATH=$PATH:$1
            else
                PATH=$1:$PATH
            fi
    esac
}


if [ -x /usr/bin/id ]; then
    if [ -z "$EUID" ]; then
        # ksh workaround
        EUID=`id -u`
        UID=`id -ru`
    fi
    USER="`id -un`"
    LOGNAME=$USER
    MAIL="/var/spool/mail/$USER"
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
    pathmunge /sbin
    pathmunge /usr/sbin
    pathmunge /usr/local/sbin
else
    pathmunge /usr/local/sbin after
    pathmunge /usr/sbin after
    pathmunge /sbin after
fi

HOSTNAME=`/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
    export HISTCONTROL=ignoreboth
else
    export HISTCONTROL=ignoredups
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
    umask 002
else
    umask 022
fi

for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        if [ "${-#*i}" != "$-" ]; then
            . "$i"
        else
            . "$i" >/dev/null 2>&1
        fi
    fi
done



        
        #在文件最后添加
        export JAVA_HOME=/usr/java/jdk1.7.0_79
        export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
        export HADOOP_HOME=/usr/local/hadoop-2.4.1  
        export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
        export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib/native/"
        export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HADOOP_HOME/lib



unset i
unset -f pathmunge



ulimit -n 65535



1.准备Linux环境
    1.0点击VMware快捷方式,右键打开文件所在位置 -> 双击vmnetcfg.exe -> VMnet1 host-only ->修改subnet ip

设置网段:192.168.8.0 子网掩码:255.255.255.0 -> apply -> ok
        回到windows --> 打开网络和共享中心 -> 更改适配器设置 -> 右键VMnet1 -> 属性 -> 双击IPv4 -> 设

置windows的IP:192.168.8.100 子网掩码:255.255.255.0 -> 点击确定
        在虚拟软件上 --My Computer -> 选中虚拟机 -> 右键 -> settings -> network adapter -> host only

-> ok    
    1.1修改主机名
        vim /etc/sysconfig/network
        
        NETWORKING=yes
        HOSTNAME=itcast01    ###
 
    1.2修改IP
        两种方式:
        第一种:通过Linux图形界面进行修改(强烈推荐)
            进入Linux图形界面 -> 右键点击右上方的两个小电脑 -> 点击Edit connections -> 选中当前

网络System eth0 -> 点击edit按钮 -> 选择IPv4 -> method选择为manual -> 点击add按钮 -> 添加IP:192.168.8.118 子

网掩码:255.255.255.0 网关:192.168.1.1 -> apply
    
        第二种:修改配置文件方式(屌丝程序猿专用)
            vim /etc/sysconfig/network-scripts/ifcfg-eth0
            
            DEVICE="eth0"
            BOOTPROTO="static"               ###
            HWADDR="00:0C:29:3C:BF:E7"
            IPV6INIT="yes"
            NM_CONTROLLED="yes"
            ONBOOT="yes"
            TYPE="Ethernet"
            UUID="ce22eeca-ecde-4536-8cc2-ef0dc36d4a8c"
            IPADDR="192.168.8.118"           ###
            NETMASK="255.255.255.0"          ###
            GATEWAY="192.168.8.1"            ###
            
    1.3修改主机名和IP的映射关系
        vim /etc/hosts
         127.0.0.1   localhost
        192.168.8.118    itcast01




    
    1.4关闭防火墙
        #查看防火墙状态
        service iptables status
        #关闭防火墙
        service iptables stop
        #查看防火墙开机启动状态
        chkconfig iptables --list
        #关闭防火墙开机启动
        chkconfig iptables off
    
    1.5重启Linux
        reboot

2.安装JDK
    2.1上传
    
    2.2解压jdk
        #创建文件夹
        mkdir /usr/java
        #解压
        tar -zxvf jdk-7u55-linux-i586.tar.gz -C /usr/java/
        
    2.3将java添加到环境变量中
        vim /etc/profile
        #在文件最后添加
        export JAVA_HOME=/usr/java/jdk1.7.0_55
        export PATH=$PATH:$JAVA_HOME/bin
    
        #刷新配置
        source /etc/profile
        
3.安装hadoop2.4.1
    注意:hadoop2.x的配置文件$HADOOP_HOME/etc/hadoop
    伪分布式需要修改5个配置文件
    3.1配置hadoop
    第一个:hadoop-env.sh
        vim hadoop-env.sh
        #第27行
        export JAVA_HOME=/usr/java/jdk1.7.0_65
        
    第二个:core-site.xml
        <!-- 制定HDFS的老大(NameNode)的地址 -->
        <property>
            <name>fs.defaultFS</name>
            <value>hdfs://itcast01:9000</value>
        </property>
        <!-- 指定hadoop运行时产生文件的存储目录 -->
        <property>
            <name>hadoop.tmp.dir</name>
            <value>/itcast/hadoop-2.4.1/tmp</value>
                </property>

===============ok=================
<configuration>
<!-- 制定HDFS的老大(NameNode)的地址 -->
                <property>
                        <name>fs.defaultFS</name>
                        <value>hdfs://itcast01:9000</value>
                </property>
                <!-- 指定hadoop运行时产生文件的存储目录 -->
                <property>
                        <name>hadoop.tmp.dir</name>
                        <value>/home/tempData</value>
                </property>
</configuration>
===================================

        
    第三个:hdfs-site.xml
        <!-- 指定HDFS副本的数量 -->
        <property>
            <name>dfs.replication</name>
            <value>1</value>
        </property>
        
    第四个:mapred-site.xml (mv mapred-site.xml.template mapred-site.xml)
        mv mapred-site.xml.template mapred-site.xml
        vim mapred-site.xml
        <!-- 指定mr运行在yarn上 -->
        <property>
            <name>mapreduce.framework.name</name>
            <value>yarn</value>
        </property>
        
    第五个:yarn-site.xml
        <!-- 指定YARN的老大(ResourceManager)的地址 -->
        <property>
            <name>yarn.resourcemanager.hostname</name>
            <value>itcast01</value>
        </property>
        <!-- reducer获取数据的方式 -->
        <property>
            <name>yarn.nodemanager.aux-services</name>
            <value>mapreduce_shuffle</value>
        </property>
    
    3.2将hadoop添加到环境变量
    
    vim /etc/proflie
        export JAVA_HOME=/usr/java/jdk1.7.0_65
        export HADOOP_HOME=/itcast/hadoop-2.4.1
        export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin

    source /etc/profile
    
    3.3格式化namenode(是对namenode进行初始化)
        hdfs namenode -format (hadoop namenode -format)

   17/05/16 17:13:12 INFO common.Storage: Storage directory
     
        /usr/local/hadoop-2.4.1/tmp/dfs/name    has been successfully formatted.


[root@itcast01 dfs]# cd name
[root@itcast01 name]# ll
total 4
drwxr-xr-x. 2 root root 4096 May 16 17:13 current
[root@itcast01 name]# cd current/
[root@itcast01 current]# ll
total 16
-rw-r--r--. 1 root root 351 May 16 17:13 fsimage_0000000000000000000
-rw-r--r--. 1 root root  62 May 16 17:13 fsimage_0000000000000000000.md5
-rw-r--r--. 1 root root   2 May 16 17:13 seen_txid
-rw-r--r--. 1 root root 207 May 16 17:13 VERSION


    3.4启动hadoop  cd /usr/local/hadoop-2.4.1/sbin

        先启动HDFS
        sbin/start-dfs.sh
        
        再启动YARN
        sbin/start-yarn.sh
        
    3.5验证是否启动成功
        使用jps命令验证
        27408 NameNode
        28218 Jps
        27643 SecondaryNameNode
    

       28066 NodeManager
       27803 ResourceManager
        27512 DataNode
    

  http://192.168.233.128:50070 (HDFS管理界面)
        http://192.168.233.128:8088 (MR管理界面)

                http://192.168.30.128:50070 (HDFS管理界面)
        http://192.168.30.128:8088 (MR管理界面)
*****************************************************************************************************************************************************

从日志中可以看出hadoop库不在java.library.path所配置的目录下,应该是java.library.path配置的路径有问题。在

hadoop-env.sh中重新配置:

export HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_HOME}/lib/native

export HADOOP_OPTS="-Djava.library.path=${HADOOP_HOME}/lib/native/"

执行start-dfs.sh,告警信息不再显示。经测试,其实只需export HADOOP_OPTS即可解决问题。

验证本地库是否加载成功:hadoop checknative


        
4.配置ssh免登陆
    #生成ssh免登陆密钥
    #进入到我的home目录
    cd ~/.ssh

    ssh-keygen -t rsa (四个回车)
    执行完这个命令后,会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)
    将公钥拷贝到要免登陆的机器上
    ssh-copy-id localhost

login as: rootroot@192.168.233.128s password:Access deniedroot@192.168.233.128s password:Last login: Tue May 16 17:38:14 2017 from 192.168.233.7[root@itcast01 ~]# lltotal 72-rw-------. 1 root root 1377 Jul 17 2013 anaconda-ks.cfg-rw-r--r--. 1 root root 49350 Jul 17 2013 install.log-rw-r--r--. 1 root root 10033 Jul 17 2013 install.log.syslog[root@itcast01 ~]# cd /home[root@itcast01 home]# lltotal 8drwx------. 29 hadoop hadoop 4096 May 16 19:01 hadoopdrwxr-xr-x. 4 root root 4096 May 16 17:49 tempData[root@itcast01 home]# cd tempData/[root@itcast01 tempData]# lltotal 8drwxr-xr-x. 5 root root 4096 May 16 17:46 dfsdrwxr-xr-x. 6 root root 4096 May 16 18:21 nm-local-dir[root@itcast01 tempData]# cd dfs[root@itcast01 dfs]# l-bash: l: command not found[root@itcast01 dfs]# lltotal 12drwx------. 3 root root 4096 May 16 18:21 datadrwxr-xr-x. 3 root root 4096 May 16 18:21 namedrwxr-xr-x. 3 root root 4096 May 16 18:21 namesecondary[root@itcast01 dfs]# cd name[root@itcast01 name]# lltotal 4drwxr-xr-x. 2 root root 4096 May 16 18:20 current[root@itcast01 name]# cd current/1-bash: cd: current/1: No such file or directory[root@itcast01 name]# cd current/[root@itcast01 current]# lltotal 2080-rw-r--r--. 1 root root 42 May 16 17:49 edits_0000000000000000001-0000000000000000002-rw-r--r--. 1 root root 1048576 May 16 17:49 edits_0000000000000000003-0000000000000000003-rw-r--r--. 1 root root 42 May 16 18:20 edits_0000000000000000004-0000000000000000005-rw-r--r--. 1 root root 1048576 May 16 18:20 edits_inprogress_0000000000000000006-rw-r--r--. 1 root root 351 May 16 17:49 fsimage_0000000000000000002-rw-r--r--. 1 root root 62 May 16 17:49 fsimage_0000000000000000002.md5-rw-r--r--. 1 root root 351 May 16 18:20 fsimage_0000000000000000005-rw-r--r--. 1 root root 62 May 16 18:20 fsimage_0000000000000000005.md5-rw-r--r--. 1 root root 2 May 16 18:20 seen_txid-rw-r--r--. 1 root root 207 May 16 17:46 VERSION[root@itcast01 current]# jps2395 Jps[root@itcast01 current]# cd /usr[root@itcast01 usr]# lltotal 289524dr-xr-xr-x. 2 root root 40960 May 15 09:57 bindrwxr-xr-x. 2 root root 4096 Sep 23 2011 etcdrwxr-xr-x. 2 root root 4096 Sep 23 2011 games-rw-r--r--. 1 root root 138656756 Aug 14 2014 hadoop-2.4.1.tar.gz-rw-r--r--. 1 root root 4130304 May 15 23:17 hadoop-native-64-2.4.1.tardrwxr-xr-x. 3 root root 4096 Jul 17 2013 includedrwxr-xr-x. 3 root root 4096 May 15 10:49 java-rw-r--r--. 1 root root 153512879 May 15 04:26 jdk-7u79-linux-x64.tar.gzdr-xr-xr-x. 27 root root 4096 Jul 17 2013 libdr-xr-xr-x. 106 root root 61440 May 4 04:34 lib64drwxr-xr-x. 25 root root 12288 May 4 04:34 libexecdrwxr-xr-x. 13 root root 4096 May 15 09:37 localdr-xr-xr-x. 2 root root 12288 May 4 04:34 sbindrwxr-xr-x. 219 root root 4096 May 15 09:58 sharedrwxr-xr-x. 4 root root 4096 Jul 17 2013 srclrwxrwxrwx. 1 root root 10 Jul 17 2013 tmp -> ../var/tmp[root@itcast01 usr]# cd local/[root@itcast01 local]# lltotal 44drwxr-xr-x. 2 root root 4096 Sep 23 2011 bindrwxr-xr-x. 2 root root 4096 Sep 23 2011 etcdrwxr-xr-x. 2 root root 4096 Sep 23 2011 gamesdrwxr-xr-x. 11 67974 users 4096 May 15 14:37 hadoop-2.4.1drwxr-xr-x. 2 root root 4096 Sep 23 2011 includedrwxr-xr-x. 2 root root 4096 Sep 23 2011 libdrwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexecdrwxr-xr-x. 2 root root 4096 Sep 23 2011 sbindrwxr-xr-x. 5 root root 4096 Jul 17 2013 sharedrwxr-xr-x. 2 root root 4096 Sep 23 2011 src[root@itcast01 local]# cd hadoop-2.4.1/[root@itcast01 hadoop-2.4.1]# lltotal 60drwxr-xr-x. 2 67974 users 4096 Jun 21 2014 bindrwxr-xr-x. 3 67974 users 4096 Jun 21 2014 etcdrwxr-xr-x. 2 67974 users 4096 Jun 21 2014 includedrwxr-xr-x. 3 501 games 4096 Jun 30 2014 libdrwxr-xr-x. 2 67974 users 4096 Jun 21 2014 libexec-rw-r--r--. 1 67974 users 15458 Jun 21 2014 LICENSE.txtdrwxr-xr-x. 3 root root 4096 May 16 18:20 logs-rw-r--r--. 1 67974 users 101 Jun 21 2014 NOTICE.txt-rw-r--r--. 1 67974 users 1366 Jun 21 2014 README.txtdrwxr-xr-x. 2 67974 users 4096 Jun 21 2014 sbindrwxr-xr-x. 4 67974 users 4096 Jun 21 2014 sharedrwxr-xr-x. 4 root root 4096 May 15 14:45 tmp[root@itcast01 hadoop-2.4.1]# cd sbin/[root@itcast01 sbin]# lltotal 116-rwxr-xr-x. 1 67974 users 2752 Jun 21 2014 distribute-exclude.sh-rwxr-xr-x. 1 67974 users 5814 Jun 21 2014 hadoop-daemon.sh-rwxr-xr-x. 1 67974 users 1360 Jun 21 2014 hadoop-daemons.sh-rwxr-xr-x. 1 67974 users 1597 Jun 21 2014 hdfs-config.cmd-rwxr-xr-x. 1 67974 users 1427 Jun 21 2014 hdfs-config.sh-rwxr-xr-x. 1 67974 users 2291 Jun 21 2014 httpfs.sh-rwxr-xr-x. 1 67974 users 4063 Jun 21 2014 mr-jobhistory-daemon.sh-rwxr-xr-x. 1 67974 users 1648 Jun 21 2014 refresh-namenodes.sh-rwxr-xr-x. 1 67974 users 2145 Jun 21 2014 slaves.sh-rwxr-xr-x. 1 67974 users 1727 Jun 21 2014 start-all.cmd-rwxr-xr-x. 1 67974 users 1471 Jun 21 2014 start-all.sh-rwxr-xr-x. 1 67974 users 1128 Jun 21 2014 start-balancer.sh-rwxr-xr-x. 1 67974 users 1360 Jun 21 2014 start-dfs.cmd-rwxr-xr-x. 1 67974 users 3705 Jun 21 2014 start-dfs.sh-rwxr-xr-x. 1 67974 users 1357 Jun 21 2014 start-secure-dns.sh-rwxr-xr-x. 1 67974 users 1524 Jun 21 2014 start-yarn.cmd-rwxr-xr-x. 1 67974 users 1347 Jun 21 2014 start-yarn.sh-rwxr-xr-x. 1 67974 users 1718 Jun 21 2014 stop-all.cmd-rwxr-xr-x. 1 67974 users 1462 Jun 21 2014 stop-all.sh-rwxr-xr-x. 1 67974 users 1179 Jun 21 2014 stop-balancer.sh-rwxr-xr-x. 1 67974 users 1414 Jun 21 2014 stop-dfs.cmd-rwxr-xr-x. 1 67974 users 3206 Jun 21 2014 stop-dfs.sh-rwxr-xr-x. 1 67974 users 1340 Jun 21 2014 stop-secure-dns.sh-rwxr-xr-x. 1 67974 users 1595 Jun 21 2014 stop-yarn.cmd-rwxr-xr-x. 1 67974 users 1340 Jun 21 2014 stop-yarn.sh-rwxr-xr-x. 1 67974 users 4278 Jun 21 2014 yarn-daemon.sh-rwxr-xr-x. 1 67974 users 1353 Jun 21 2014 yarn-daemons.sh[root@itcast01 sbin]# start-dfs.shStarting namenodes on [itcast01]root@itcast01s password:root@itcast01s password: itcast01: Permission denied, please try again.itcast01: starting namenode, logging to /usr/local/hadoop-2.4.1/logs/hadoop-root-namenode-itcast01.outroot@localhosts password:root@localhosts password: localhost: Permission denied, please try again.localhost: starting datanode, logging to /usr/local/hadoop-2.4.1/logs/hadoop-root-datanode-itcast01.outStarting secondary namenodes [0.0.0.0]root@0.0.0.0s password:0.0.0.0: starting secondarynamenode, logging to /usr/local/hadoop-2.4.1/logs/hadoop-root-secondarynamenode-itcast01.out[root@itcast01 sbin]# jps2636 DataNode2514 NameNode2790 SecondaryNameNode2892 Jps[root@itcast01 sbin]# start-yarn.shstarting yarn daemonsstarting resourcemanager, logging to /usr/local/hadoop-2.4.1/logs/yarn-root-resourcemanager-itcast01.outroot@localhosts password:localhost: starting nodemanager, logging to /usr/local/hadoop-2.4.1/logs/yarn-root-nodemanager-itcast01.out[root@itcast01 sbin]# jps3048 NodeManager3268 Jps2636 DataNode2514 NameNode2946 ResourceManager2790 SecondaryNameNode[root@itcast01 sbin]#

 

hadoop2.4.1 伪分布