在安装好单机模式的hadoop以后,咱们就能够着手来在集群模式下安装hadoop了。在安装了单机版hadoop的机器上将hadoop转成集群模式是很容易的。首先来设置网络。 node
首先,咱们须要在同一个网络的几台机器(这里用的是192.168.0.0/24网段)。而后为了操做方便,咱们须要给它们配上域名,直接在 /etc/hosts 文件里面加入如下内容。 shell
192.168.0.1 master 192.168.0.2 slave
为了能让hadoop运行,须要让master机器可以登陆到slave机器上,这就要配置SSH密钥。跟配置单机模式的时候类似,把 ~/.ssh/authorized_key 文件拷贝slave机器的 ~/.ssh/ 路径下。在完成后试试是否可以用运行hadoop的账号登陆slave机器,能的话这一步就算完成了。 网络
HADOOP_HOME/conf/master 这个文件定义了在多机器模式下在那台机器上运行 namenode , secondary namenode和jobtracker。咱们能够经过运行 HADOOP_HOME/bin/start-all.sh 来启动多机器模式的hadoop。在master机器上,咱们须要在 HADOOP_HOME/conf/master添加如下内容。 ssh
masterHADOOP_HOME/conf/slave 这个文件定义在多机器模式的hadoop里面在那些机器上运行datanode和tasktracker。须要在这个文件里面添加一下配置。
master slave
在 HADOOP_HOME/conf/core-site.xml 文件里面添加一下配置 oop
<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就安装完成了。