你好,游客 登录 注册 搜索
背景:
阅读新闻

Ubuntu 14.04 LTS下安装Hadoop 1.2.1(伪分布模式)

[日期:2016-09-22] 来源:Linux社区  作者:Linux [字体: ]

Hadoop的运行模式可分为单机模式、伪分布模式和分布模式。首先无论哪种模式都需要安装JDK的,这一步之前的随笔Ubuntu 14.04 LTS下安装JDK 1.8中已经做了(见 http://www.linuxidc.com/Linux/2016-09/135403.htm)。这里就不多说了。

其次是安装SSH。安装SSH是为了每次可以免密码登陆数据节点服务器。因为集群的环境下,每次登陆到数据节点服务器不可能每次都输入密码。这一步在前面的随笔Ubuntu 14.04 LTS下配置SSH免密码登录中已经做了(见 http://www.linuxidc.com/Linux/2016-09/135404.htm)。这里也不多说了。

伪分布模式安装:

首先下载Hadoop 1.2.1到本机,再解压到用户目录下。

linuxidc@ubuntu:~/Downloads$ tar zxf hadoop-1.2.1.tar.gz -C ~/hadoop_1.2.1
linuxidc@ubuntu:~/Downloads$ cd ~/hadoop_1.2.1/
linuxidc@ubuntu:~/hadoop_1.2.1$ ls
hadoop-1.2.1
linuxidc@ubuntu:~/hadoop_1.2.1$ cd hadoop-1.2.1/
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1$ ls
bin          hadoop-ant-1.2.1.jar          ivy          sbin
build.xml    hadoop-client-1.2.1.jar      ivy.xml      share
c++          hadoop-core-1.2.1.jar        lib          src
CHANGES.txt  hadoop-examples-1.2.1.jar    libexec      webapps
conf        hadoop-minicluster-1.2.1.jar  LICENSE.txt
contrib      hadoop-test-1.2.1.jar        NOTICE.txt
docs        hadoop-tools-1.2.1.jar        README.txt

然后配置hadoop的几个配置文件,都是XML格式。

首先是core-default.xml。这里配置hadoop分布式文件系统的地址和端口,以及Hadoop临时文件目录(/tmp/hadoop-${user.name})。

linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ cat 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>fs.default.name</name>
        <value>hdfs://localhost:9000</value>
    </property>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/hadoop/hadooptmp</value>
    </property>
</configuration>
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$

修改hadoop系统环境配置文件,告诉hadoop安装好的jdk的主目录路径

linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1$ cd conf/
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ ls
capacity-scheduler.xml      hadoop-policy.xml      slaves
configuration.xsl          hdfs-site.xml          ssl-client.xml.example
core-site.xml              log4j.properties      ssl-server.xml.example
fair-scheduler.xml          mapred-queue-acls.xml  taskcontroller.cfg
hadoop-env.sh              mapred-site.xml        task-log4j.properties
hadoop-metrics2.properties  masters
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ sudo vim hadoop-env.sh n
[sudo] password for linuxidc:
2 files to edit
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ sudo vim hadoop-env.sh
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ tail -n 1 hadoop-env.sh
export JAVA_HOME=/usr/lib/jvm/jdk

然后是hdfs-site.xml 。修改hdfs的文件备份数量为1,dfs命名节点的主目录,dfs数据节点的目录。

linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ cat 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>
    <property>
        <name>dfs.name.dir</name>
        <value>/hadoop/hdfs/name</value>
    </property>
    <property>
        <name>dfs.data.dir</name>
        <value>/hadoop/hdfs/data</value>
    </property>
</configuration>
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$

最后配置mapreduce的job tracker的地址和端口


linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ cat 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>localhost:9001</value>
 </property>
</configuration>
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$

配置masters文件和slaves文件,这里因为我们是伪分布式,命名节点和数据节点其实都是一样。

linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ cat masters
localhost
192.168.2.100

linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ cat slaves
localhost
192.168.2.100
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$

编辑/etc/hosts文件,配置主机名和IP地址的映射关系

linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ cat /etc/hosts
127.0.0.1    localhost
127.0.1.1    ubuntu

# The following lines are desirable for IPv6 capable hosts
::1    ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
192.168.2.100 master
192.168.2.100 slave
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$

创建好core-default.xml,hdfs-site.xml,mapred-site.xml 三个配置文件里面写到的目录

linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ mkdir -p /hadoop/hadooptmp
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ mkdir -p /hadoop/hdfs/name
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ mkdir -p /hadoop/hdfs/data

格式化HDFS

linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/bin$ ./hadoop namenode -format

启动所有Hadoop服务,包括JobTracker,TaskTracker,Namenode

linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/bin$ ./start-all.sh
starting namenode, logging to /home/linuxidc/hadoop_1.2.1/hadoop-1.2.1/libexec/../logs/hadoop-linuxidc-namenode-ubuntu.out
192.168.68.130: starting datanode, logging to /home/linuxidc/hadoop_1.2.1/hadoop-1.2.1/libexec/../logs/hadoop-linuxidc-datanode-ubuntu.out
localhost: starting datanode, logging to /home/linuxidc/hadoop_1.2.1/hadoop-1.2.1/libexec/../logs/hadoop-linuxidc-datanode-ubuntu.out
localhost: ulimit -a for user linuxidc
localhost: core file size          (blocks, -c) 0
localhost: data seg size          (kbytes, -d) unlimited
localhost: scheduling priority            (-e) 0
localhost: file size              (blocks, -f) unlimited
localhost: pending signals                (-i) 7855
localhost: max locked memory      (kbytes, -l) 64
localhost: max memory size        (kbytes, -m) unlimited
localhost: open files                      (-n) 1024
localhost: pipe size            (512 bytes, -p) 8
localhost: starting secondarynamenode, logging to /home/linuxidc/hadoop_1.2.1/hadoop-1.2.1/libexec/../logs/hadoop-linuxidc-secondarynamenode-ubuntu.out
192.168.68.130: secondarynamenode running as process 10689. Stop it first.
starting jobtracker, logging to /home/linuxidc/hadoop_1.2.1/hadoop-1.2.1/libexec/../logs/hadoop-linuxidc-jobtracker-ubuntu.out
192.168.68.130: starting tasktracker, logging to /home/linuxidc/hadoop_1.2.1/hadoop-1.2.1/libexec/../logs/hadoop-linuxidc-tasktracker-ubuntu.out
localhost: starting tasktracker, logging to /home/linuxidc/hadoop_1.2.1/hadoop-1.2.1/libexec/../logs/hadoop-linuxidc-tasktracker-ubuntu.out
localhost: ulimit -a for user linuxidc
localhost: core file size          (blocks, -c) 0
localhost: data seg size          (kbytes, -d) unlimited
localhost: scheduling priority            (-e) 0
localhost: file size              (blocks, -f) unlimited
localhost: pending signals                (-i) 7855
localhost: max locked memory      (kbytes, -l) 64
localhost: max memory size        (kbytes, -m) unlimited
localhost: open files                      (-n) 1024
localhost: pipe size            (512 bytes, -p) 8
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/bin$

查看Hadoop服务是否启动成功


linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$ jps
3472 JobTracker
3604 TaskTracker
3084 NameNode
5550 Jps
3247 DataNode
3391 SecondaryNameNode
linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/conf$

查看hadoop群集的状态

linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/bin$ ./hadoop dfsadmin -report
Configured Capacity: 41083600896 (38.26 GB)
Present Capacity: 32723169280 (30.48 GB)
DFS Remaining: 32723128320 (30.48 GB)
DFS Used: 40960 (40 KB)
DFS Used%: 0%
Under replicated blocks: 0
Blocks with corrupt replicas: 0
Missing blocks: 0

-------------------------------------------------
Datanodes available: 1 (1 total, 0 dead)

Name: 127.0.0.1:50010
Decommission Status : Normal
Configured Capacity: 41083600896 (38.26 GB)
DFS Used: 40960 (40 KB)
Non DFS Used: 8360431616 (7.79 GB)
DFS Remaining: 32723128320(30.48 GB)
DFS Used%: 0%
DFS Remaining%: 79.65%
Last contact: Sat Dec 26 12:22:07 PST 2015

linuxidc@ubuntu:~/hadoop_1.2.1/hadoop-1.2.1/bin$

下面关于Hadoop的文章您也可能喜欢,不妨看看:

Ubuntu14.04下Hadoop2.4.1单机/伪分布式安装配置教程  http://www.linuxidc.com/Linux/2015-02/113487.htm

CentOS安装和配置Hadoop2.2.0  http://www.linuxidc.com/Linux/2014-01/94685.htm

Ubuntu 13.04上搭建Hadoop环境 http://www.linuxidc.com/Linux/2013-06/86106.htm

Ubuntu 12.10 +Hadoop 1.2.1版本集群配置 http://www.linuxidc.com/Linux/2013-09/90600.htm

Ubuntu上搭建Hadoop环境(单机模式+伪分布模式) http://www.linuxidc.com/Linux/2013-01/77681.htm

Ubuntu下Hadoop环境的配置 http://www.linuxidc.com/Linux/2012-11/74539.htm

单机版搭建Hadoop环境图文教程详解 http://www.linuxidc.com/Linux/2012-02/53927.htm

更多Hadoop相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-09/135406.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款