文章转自:http://hi.baidu.com/lvmajia/blog/item/34239486e58ffe3466096eea.html
Linux下的Hadoop--分布式模式的部署
选用软件版本:
1. jdk 1.6.0.10
2. hadoop-0.19.1
1. 准备Host环境和配置ssh
主节点IP是192.168.1.247,子节点1是192.168.1.36,修改两个节点的/etc/hosts文件:
# /etc/hosts (for master AND slave)
192.168.1.247 master
192.168.1.36 slave
分别在两台机器上添加用户hadoop
①在master上:
groupadd -g 2000 hadoop
useradd -u 2000 -g hadoop hadoop
su - hadoop
ssh-keygen -t dsa -P '' -f ~/.ssh/identity
Generating public/private dsa key pair.
Created directory '/home/hadoop/.ssh'.
Your identification has been saved in /home/hadoop/.ssh/identity.
Your public key has been saved in /home/hadoop/.ssh/identity.pub.
The key fingerprint is:
44:e5:05:16:a2:33:95:23:3e:54:f8:c7:f1:e5:bc:24 [email protected]
mv .ssh/identity.pub .ssh/authorized_keys
ssh master输入yes接受自己的公钥,看能否自动登录,然后
ssh slave输入yes接受36的公钥。
The authenticity of host 'slave (192.168.1.36)' can't be established.
RSA key fingerprint is 40:39:05:3d:3e:6c:9d:1f:8c:d1:40:68:67:65:86:41.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'slave,192.168.1.36' (RSA) to the list of known hosts.
hadoop@slave's password:
cat .ssh/authorized_keys
ssh-dss AAAAB3NzaC1kc3MAAACBAM4FxFo0oXwj04yyOYQsFe4IeNU/ClXOVxXtTQyQlZHse/Cl9tzKzz
rDxfKkM8K/wjRH3o2gppk2L2VO7SAd8ZYarCKQzCQjQzMa7UcsjQBth9bzde/rafDO2izHyN5d
M9oHMD3p4H9f672pPO0n8oYShrA48ndBn0N8TucrT0t9AAAAFQCy+pU9QOOD4lvp/qipQbJI2J
X7kQAAAIB4lwMLhjcJmtTiQqxUruTm4WgdOhlVz9HJPqv1FipZEhAVIk5xG9X93wUee3zVN+6v
2mOuJlXAiOAbFeY5ba7EgSaL8RAAhUhzFiTNar6jtZJgy36TzOoECL99leX+F9EpYnCyN7zMHj
uOE5nFPV6NgsDJDjt2EPEdoEvyeMz3iAAAAIEAsoGk1TxRN12zq5HjFsPUiwVCKKoi4NKlwCHz
UGNwE875je1ZHOm32SNUzpfwKGT8PR+d530aVzUGTmT7On5mUlD5ZIHPgjn9zXPFZ/ZMV9XAox
hHBNbkCrQlwLgEE7C3nK3xlEGLymdLxGRZpiCctdlromNqNhr33mzJnWWnVPI= [email protected]
复制备用
②在slave上:
groupadd -g 2000 hadoop
useradd -u 2000 -g hadoop hadoop
su - hadoop
mkdir .ssh
chmod 700 .ssh
vi .ssh/authorized_keys
把从master机器上拷贝的authorized_keys文件内容粘贴上。
chmod 644 .ssh/authorized_keys
③在master上:
ssh slave 看是否能自动登录
这样host和ssh环境就配好了。
有人会觉得slave上的操作很麻烦,这是因为这里只添加了用户,而没有给用户密码,这样导致hadoop用户只能用证书登陆,不能用密码方式登录,会更安全。
2. 配置hadoop和jdk1.6
这里下载的jdk是jdk-6u10-rc-bin-b28-linux-i586-21_jul_2008.bin;执行后安装到/usr/java/jdk1.6.0_10
①在master上:
su - hadoop
wget http://apache.freelamp.com/hadoop/core/hadoop-0.19.1/hadoop-0.19.1.tar.gz
tar zxvf hadoop-0.19.1.tar.gz
cd hadoop-0.19.1
vi conf/masters
# 把其中的localhost改成master
master
vi conf/slaves
# 把其中的localhost改成两个节点,如果要布两台以上,就依次把剩下的子节点加上。
master
slave
vi conf/hadoop-env.sh
#在文件最前面加两行
export JAVA_HOME=/usr/java/jdk1.6.0_10
export PATH=$JAVA_HOME/bin:$PATH
vi conf/hadoop-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://master:9000</value>
</property>
<property>
<name>mapred.job.tracker</name>
<value>master:9001</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
</configuration>
# 格式化namenode
bin/hadoop namenode -format
09/05/18 14:34:02 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = localhost.localdomain/127.0.0.1
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 0.19.1
STARTUP_MSG: build = https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.19 -r 745977; compiled by 'ndaley' on Fri Feb 20 00:16:34 UTC 2009
************************************************************/
09/05/18 14:34:02 INFO namenode.FSNamesystem: fsOwner=hadoop,hadoop
09/05/18 14:34:02 INFO namenode.FSNamesystem: supergroup=supergroup
09/05/18 14:34:02 INFO namenode.FSNamesystem: isPermissionEnabled=true
09/05/18 14:34:02 INFO common.Storage: Image file of size 96 saved in 0 seconds.
09/05/18 14:34:02 INFO common.Storage: Storage directory /tmp/hadoop-hadoop/dfs/name has been successfully formatted.
09/05/18 14:34:02 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at localhost.localdomain/127.0.0.1
************************************************************/
②在slave上:
vi conf/hadoop-env.sh
在文件最前面加两行
export JAVA_HOME=/usr/java/jdk1.6.0_10
export PATH=$JAVA_HOME/bin:$PATH
vi conf/hadoop-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://master:9000</value>
</property>
<property>
<name>mapred.job.tracker</name>
<value>master:9001</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
</configuration>
③在master上:
bin/start-all.sh
starting namenode, logging to /home/hadoop/hadoop-0.19.1/bin/../logs/hadoop-hadoop-namenode-localhost.localdomain.out
master: starting datanode, logging to /home/hadoop/hadoop-0.19.1/bin/../logs/hadoop-hadoop-datanode-localhost.localdomain.out
slave: starting datanode, logging to /home/hadoop/hadoop-0.19.1/bin/../logs/hadoop-hadoop-datanode-wangyin3.out
master: starting secondarynamenode, logging to /home/hadoop/hadoop-0.19.1/bin/../logs/hadoop-hadoop-secondarynamenode-localhost.localdomain.out
starting jobtracker, logging to /home/hadoop/hadoop-0.19.1/bin/../logs/hadoop-hadoop-jobtracker-localhost.localdomain.out
slave: starting tasktracker, logging to /home/hadoop/hadoop-0.19.1/bin/../logs/hadoop-hadoop-tasktracker-wangyin3.out
master: starting tasktracker, logging to /home/hadoop/hadoop-0.19.1/bin/../logs/hadoop-hadoop-tasktracker-localhost.localdomain.out
export JAVA_HOME=/usr/java/jdk1.6.0_10
export PATH=$JAVA_HOME/bin:$PATH
jps
9208 SecondaryNameNode
9426 TaskTracker
8995 NameNode
9302 JobTracker
9095 DataNode
9536 Jps
看到运行了5个进程,OK
④在slave上:
export JAVA_HOME=/usr/java/jdk1.6.0_10
export PATH=$JAVA_HOME/bin:$PATH
jps
30693 DataNode
30768 TaskTracker
30814 Jps
看到运行了2个进程,Ok
4. 运行hadoop
拷贝conf目录到hdfs文件系统中
$ bin/hadoop dfs -copyFromLocal conf 111
查看一下是否已经拷过去了
$ bin/hadoop dfs -ls
Found 1 items
drwxr-xr-x - hadoop supergroup 0 2009-05-18 15:27 /user/hadoop/111
在伪分布系统上运行MapReduce,wordcount
$ bin/hadoop jar hadoop-0.19.1-examples.jar wordcount 111 111-out
09/05/14 10:08:19 INFO mapred.FileInputFormat: Total input paths to process : 12
09/05/14 10:08:21 INFO mapred.JobClient: Running job: job_200905181001_0002
09/05/14 10:08:22 INFO mapred.JobClient: map 0% reduce 0%
09/05/14 10:08:48 INFO mapred.JobClient: map 7% reduce 0%
09/05/14 10:08:54 INFO mapred.JobClient: map 15% reduce 0%
09/05/14 10:09:06 INFO mapred.JobClient: map 15% reduce 5%
09/05/14 10:09:12 INFO mapred.JobClient: map 23% reduce 5%
09/05/14 10:09:13 INFO mapred.JobClient: map 30% reduce 5%
09/05/14 10:09:25 INFO mapred.JobClient: map 38% reduce 10%
09/05/14 10:09:27 INFO mapred.JobClient: map 46% reduce 10%
09/05/14 10:09:35 INFO mapred.JobClient: map 53% reduce 15%
09/05/14 10:09:40 INFO mapred.JobClient: map 61% reduce 15%
09/05/14 10:09:45 INFO mapred.JobClient: map 69% reduce 15%
09/05/14 10:09:50 INFO mapred.JobClient: map 76% reduce 20%
09/05/14 10:09:57 INFO mapred.JobClient: map 84% reduce 20%
09/05/14 10:10:01 INFO mapred.JobClient: map 92% reduce 20%
09/05/14 10:10:06 INFO mapred.JobClient: map 100% reduce 28%
09/05/14 10:10:11 INFO mapred.JobClient: map 100% reduce 30%
09/05/14 10:10:14 INFO mapred.JobClient: map 100% reduce 100%
09/05/14 10:10:20 INFO mapred.JobClient: Job complete: job_200905181001_0002
09/05/14 10:10:20 INFO mapred.JobClient: Counters: 16
09/05/14 10:10:20 INFO mapred.JobClient: File Systems
09/05/14 10:10:20 INFO mapred.JobClient: HDFS bytes read=64223
09/05/14 10:10:20 INFO mapred.JobClient: HDFS bytes written=30615
09/05/14 10:10:20 INFO mapred.JobClient: Local bytes read=47194
09/05/14 10:10:20 INFO mapred.JobClient: Local bytes written=94824
09/05/14 10:10:20 INFO mapred.JobClient: Job Counters
09/05/14 10:10:20 INFO mapred.JobClient: Launched reduce tasks=1
09/05/14 10:10:20 INFO mapred.JobClient: Launched map tasks=13
09/05/14 10:10:20 INFO mapred.JobClient: Data-local map tasks=13
09/05/14 10:10:20 INFO mapred.JobClient: Map-Reduce Framework
09/05/14 10:10:20 INFO mapred.JobClient: Reduce input groups=1780
09/05/14 10:10:20 INFO mapred.JobClient: Combine output records=2425
09/05/14 10:10:20 INFO mapred.JobClient: Map input records=1939
09/05/14 10:10:20 INFO mapred.JobClient: Reduce output records=1780
09/05/14 10:10:20 INFO mapred.JobClient: Map output bytes=84749
09/05/14 10:10:20 INFO mapred.JobClient: Map input bytes=62908
09/05/14 10:10:20 INFO mapred.JobClient: Combine input records=6370
09/05/14 10:10:20 INFO mapred.JobClient: Map output records=6370
09/05/14 10:10:20 INFO mapred.JobClient: Reduce input records=2425
OK,一切搞定了。