Hadoopz安装与配置-配置实例(3)

为了方便阐述,这里只搭建一个有三台主机的小集群。相信读者还没有忘记Hadoop 对主机的三种定位方式, 分别为master 和slave,JobTracker 和TaskTracker,NameNode 和DataNode。为了方便,在分配IP 地址时顺便规定一下角色。下面是为这三台机器分配的IP 地址及相应的角色:
10.37.128.2-master,NamoNode,jobtracker-master(主机名)
10.37.128.3-slave,DataNode,tasktracker-slave1(主机名)
10.37.128.4-slave,DataNode,tasktracker-slave2(主机名)
首先在三台主机上创建相同的用户(这是Hadoop 的基本要求):
1)在三台主机上安装JDK 1.6,并设置环境变量。
2)在这三台主机上安装OpenSSH,并配置SSH 可以无密码登录。
安装方式不再赘述,建立~/.ssh 文件夹,如已存在,则无须创建。“~”代表Ubuntu 的

当前用户文件夹。
生成密钥并配置SSH 无密码登录本机,输入命令:
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
将文件拷贝到两台slave 主机相同的文件夹内,输入命令:
scp authorized_keys slave1:~/.ssh/
scp authorized_keys slave2:~/.ssh/
查看是否可以从master 主机无密码登录slave,输入命令:
ssh slave1
ssh slave2
3)在三台主机上分别设置/etc/hosts 及/etc/hostname。
hosts 这个文件用于定义主机名与IP 地址之间的对应关系。
/etc/hosts:
127.0.0.1 localhost
10.37.128.2 master
10.37.128.3 slave1
10.37.128.4 slave2
hostname 这个文件用于定义Ubuntu 的主机名。
/etc/hostname:
你的主机名(如master,slave1 等)
4)配置三台主机的Hadoop 文件,内容如下:
conf/Hadoop-env.sh:
export JAVA_HOME=“你的Java 安装地址”
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>fs.default.name</name>
<value>hdfs://master:9000</value>
</property>
<property>
<name>Hadoop.tmp.dir</name>
<value> 你希望Hadoop 存储数据块的位置</value> // 此文件夹需手动创建
</property>

</configuration>
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>2</value>
</property>
</configuration>
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>master:9001</value>
</property>
</configuration>
conf/masters:
master
conf/slaves:
slave1
slave2
5)启动Hadoop。
bin/Hadoop NameNode -format
bin/start-all.sh
你可以通过命令:
Hadoop dfsadmin -report
查看集群状态,或者通过http://master:50070http://master:50030 查看集群状态。

posted on 2012-09-16 23:54  Stephen_init  阅读(186)  评论(0编辑  收藏  举报