在Ubuntu上安装Hadoop(集群模式)

网络
配置SSH
安装Hadoop
master机器上的配置项
所有机器上都需要的配置项

在安装好单机模式的hadoop之后,我们就可以着手来在集群模式下安装hadoop了。在安装了单机版hadoop的机器上将hadoop转成集群模式是很容易的。首先来设置网络。

网络
首先,我们需要在同一个网络的几台机器(这里用的是192.168.0.0/24网段)。然后为了操作方便,我们需要给它们配上域名,直接在 /etc/hosts 文件里面加入以下内容。

192.168.0.1    master
192.168.0.2    slave

配置SSH

为了能让hadoop运行,需要让master机器能够登录到slave机器上,这就要配置SSH密钥。跟配置单机模式的时候相似,把 ~/.ssh/authorized_key 文件拷贝slave机器的 ~/.ssh/ 路径下。在完成后试试是否能够用运行hadoop的帐号登录slave机器,能的话这一步就算完成了。

安装hadoop
master机器上的配置项
HADOOP_HOME/conf/master 这个文件定义了在多机器模式下在那台机器上运行 namenode , secondary namenode和jobtracker。我们可以通过运行 HADOOP_HOME/bin/start-all.sh 来启动多机器模式的hadoop。在master机器上,我们需要在 HADOOP_HOME/conf/master添加以下内容。

master

HADOOP_HOME/conf/slave  这个文件定义在多机器模式的hadoop里面在那些机器上运行datanode和tasktracker。需要在这个文件里面添加一下配置。

master
slave

所有机器上都需要的配置项

在 HADOOP_HOME/conf/core-site.xml 文件里面添加一下配置

<property>
  <name>fs.default.name</name>
  <value>hdfs://master:54310</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>

在HADOOP_HOME/conf/mapred-site.xml 文件里面添加以下配置:

<property>
  <name>mapred.job.tracker</name>
  <value>master:54311</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>

在 HADOOP_HOME/conf/hdfs-site.xml 文件添加以下配置:

<property>
  <name>dfs.replication</name>
  <value>2</value>
  <description>Default block replication.
  The actual number of replications can be specified when the file is created.
  The default is used if replication is not specified in create time.
  </description>
</property>

接下来把HDFS文件系统来格式化一下

$ /usr/local/hadoop$ bin/hadoop namenode -format

然后运行 /usr/local/hasoop/bin/start-all.sh ,如果执行成功,多机器模式的hadoop就安装完成了。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/c26be0f4488b002e1c406f16c23e2e25.html