现在的位置: 首页 > 综合 > 正文

Hadoop分布式安装

2013年10月20日 ⁄ 综合 ⁄ 共 4390字 ⁄ 字号 评论关闭

一、安装准备

        1、下载hadoop,地址:http://hadoop.apache.org/,下载相应版本
        2、下载JDK版本:Hadoop只支持1.6以上,地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html
        3、操作系统:Linux
        4、四台机器,192.168.1.211(master), 192.168.1.212(slave),192.168.1.213(slave),192.168.1.214(slave)

二、安装操作
        1、在所有机器安装jdk
        
        2、在所有机器创建Hadoop用户及用户组
                groupadd -g 55 hadoop
                useradd -g 55 hadoop
        
        3、上传解压Hadoop包,对Hadoop文件的拥有者改为hadoop用户和组
                tar -zxvf hadoop-1.0.1.tar.gz
                sudo chown -R hadoop:hadoop hadoop-1.0.1
        4、配置SSH无密码登陆
                ssh-keygen  -t  rsa
                生成的密钥对id_rsa,id_rsa.pub,默认存储在.ssh目录下
                然后将id_rsa.pub的内容复制到每个机器(也包括本机)的.ssh/authorized_keys文件中,
                如果机器上已经有authorized_keys这个文件了,就在文件末尾加上id_rsa.pub中的内容,
                如果没有authorized_keys这个文件,直接cp或者scp就好了,
                下面的操作假设各个机器上都没有authorized_keys文件。
                scp hadoop@192.168.1.211:/home/hadoop/.ssh/authorized_keys ./
        5、修改conf/目录下的master文件,内容如下:
                        192.168.1.211
        6、修改conf/目录下的slaves文件,内容如下:
                        192.168.1.212
                        192.168.1.213
                        192.168.1.214
        
        7、修改$HADOOP_HOME/conf/hadoop-env.sh文件的环境变量:
                        # The java implementation to use.  Required.
                        export JAVA_HOME=/usr/java/jdk1.6.0_27
        8、修改$HADOOP_HOME/conf/core-site.xml配置文件,内容如下:
                        <?xml version="1.0"?>
                        <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
                        <!-- Put site-specific property overrides in this file. -->
                        <configuration>
                                <property>
                                  <name>hadoop.tmp.dir</name>
                                  <value>/hadoopdata</value>
                                  <description>A base for other temporary directories.</description>
                                </property>
                                
                                <property>
                                  <name>fs.default.name</name>
                                  <value>hdfs://192.168.1.211:9000</value>
                                  <description>The name of the default file system.  A URI whose
                                  scheme and authority determine the FileSystem implementation.  The
                                  uri's scheme determines the config property (fs.SCHEME.impl) naming
                                  the FileSystem implementation class.  The uri's authority is used to
                                  determine the host, port, etc. for a filesystem.</description>
                                </property>
                                
                                <property>
                                  <name>dfs.hosts.exclude</name>
                                  <value>excludes</value>
                                </property>
                        </configuration>
        9、修改$HADOOP_HOME/conf/hdfs-site.xml配置文件,内容如下:
                        <?xml version="1.0"?>
                        <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
                        <!-- Put site-specific property overrides in this file. -->
                        <configuration>
                                <property>
                                <name>dfs.replication</name>
                                <value>1</value>
                                </property>
                        </configuration>
        10、修改$HADOOP_HOME/conf/mapred-site.xml配置文件,内容如下:
                        <?xml version="1.0"?>
                        <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
                        <!-- Put site-specific property overrides in this file. -->
                        <configuration>
                        <property>
                          <name>mapred.job.tracker</name>
                          <value>192.168.1.211:9001</value>
                          <description>The host and port that the MapReduce job tracker runs
                          at.  If "local", then jobs are run in-process as a single map
                          and reduce task.
                          </description>
                        </property>
                        </configuration>
        11、修改/ect/profile配置文件,在末尾追加以下内容,并输入source/etc/profile使之生效:
                export JAVA_HOME=/usr/java/jdk1.6.0_27
                export JRE_HOME=/usr/java/jdk1.6.0_27/jre
                export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
                export PATH=$JAVA_HOME/bin:$PATH
                export HADOOP_HOME=/home/hadoop/hadoop-1.0.1
                export PATH=$HADOOP_HOME/bin:$PATH
                export PATH=$PATH:$HIVE_HOME/bin
        12、将主控机器上Hadoop分别给节点机器复制一份。
                将/ect/profile拷贝到132、133和134机器上。注意profile需要做生效操作。

三、启动/停止hadoop
                1、通过shell脚本启动hadoop,可以通过jps命令查看是否启动NameNode、DataNode、secondaryNameNode、JobTracker、TaskTracher
                   注意:先要进行格式化HDFS文件系统,才能启动NameNode
                        $HADOOP_HOME/bin/start-all.sh
                2、停止hadoop
                        $HADOOP_HOME/bin/stop-all.sh
四、初始配置
                1、格式化HDFS文件系统。进入$HADOOP_HOME/bin目录。执行:hadoop namenode –format
                2、在$HADOOP_HOME/bin目录下,执行:hadoop fs -ls /
                                如果控制台返回结果,表示初始化成功。可以向里面录入数据。
                3、通过WEB查看hadoop
                                查看集群状态 http://192.168.1.211:50070/dfshealth.jsp 
                                查看JOB状态 http://192.168.1.211:50030/jobtracker.jsp 

抱歉!评论已关闭.