在经历了几天的Windows下用Cygwin搭建Hadoop开发环境的痛苦后,终于放弃,转而投向Linux环境。
现在依旧不明白,为什么OpenSSH5.6下有了证书(Certificate)机制后,在Cygwin里配置ssh服务器就那么艰难,过几天再搞它了。在Ubuntu下直接运行:
$sudo apt-get install openssh-server
装上OpenSSH5.1版, 再运行个
$ssh localhost
测试登陆本机成功,在Cygwin上终究也没等到成功的一次……再建立无密码登陆方式
$ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
执行后在~/.ssh下生成两个文件:id_rsa和id_rsa.pub,一个是私钥一个是公钥。再把id_rsa.pub(公钥)增加到授权的key里
$cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
然后测试本机无密码登陆:
$ssh localhost
下面是我用的软件的版本:
1. jdk 6u21
2. hadoop-0.21.0
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 hadoop@localhost.localdomain
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= hadoop@localhost.localdomain
复制备用
②在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
# 格式化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
③在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,一切搞定了。