Hadoop的运行模式可分为单机模式、伪分布模式和分布模式。首先无论哪种模式都需要安装JDK的,这一步之前的随笔Ubuntu 14.04 LTS下安装JDK 1.8中已经做了(见 )。这里就不多说了。
其次是安装SSH。安装SSH是为了每次可以免密码登陆数据节点服务器。因为集群的环境下,每次登陆到数据节点服务器不可能每次都输入密码。这一步在前面的随笔Ubuntu 14.04 LTS下配置SSH免密码登录中已经做了(见 )。这里也不多说了。
伪分布模式安装:
首先下载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="https://www.linuxidc.com/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="https://www.linuxidc.com/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的地址和端口