hadoop安装全过程

1.下载hadoop-0.20.2,下载地址:http://www.apache.org/dist/hadoop/common/hadoop-0.20.2/
2.下载jdk-6u20-linux-i586.bin,下载地址:http://autosetup1.googlecode.com/files/jdk-6u20-linux-i586.bin
3.安装jdk:./jdk-6u20-linux-i586.bin
4.设置环境变量:在/etc/profile中加入如下语句:
JAVA_HOME=java安装路径(如/usr/java)
 CLASSPATH=.:$JAVA_HOME/lib
 PATH=$JAVA_HOME/bin:$PATH
 
 export JAVA_HOME CLASSPATH PATH

然后重新加载环境变量 source /etc/profile
5.解压缩hadoop-0.20.2,修改hadoop配置,配置文件如下:
1.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>hadoop.tmp.dir</name>
  <value>/hadoopdata</value>(这个是一个文件夹,相当于分布式文件系统的硬盘主目录)
  <description>A base for other temporary directories.</description>
</property>
<property>
  <name>fs.default.name</name>
  <value>hdfs://192.168.1.217:9000</value>(这是namenode的主机名和端口,连接hdfs时需要用到)
  <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>
<property>
  <name>dfs.hosts.exclude</name>
  <value>/root/jz/hadoop-0.20.2/excludes</value>(这是一个文件,现在还不知道是干啥用的)
</property>
</configuration>
2.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>1</value>
    </property>
    <property>
        <name>dfs.name.dir</name>
        <value>/root/jz/hadoop-0.20.2/hdfs/name</value>
    </property>
    <property>
        <name>dfs.data.dir</name>
        <value>/root/jz/hadoop-0.20.2/hdfs/data</value>
    </property>
</configuration>
3.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>m:9001</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>
</configuration>

     master中填写master主机IP地址
     slave中填写slave主机IP地址
 
遇到问题:hadoop环境变量配置,除了配置系统的环境变量/etc/profile外,还要配置hadoop/conf/hadoop-env.sh,因为hadoop启动时会先通过这个脚本重新加载环境变量,具体调用在hadoop-daemon.sh中
hadoop启动过程如下:先加载配置文件(hadoop-config.sh),启动hdfs(start-dfs.sh),启动mapreduce(start-mapred.sh)
使用jps查看正在运行的服务,namenode,jobtracker,SecondaryNameNode一定要起来
如果出现哪一个没起,就去日志里面查看原因,这次出现的两个错误有:namenode没有format,用命令hadoop namenode -format即可解决;excludes文件不存在,建立一下就好
注意:conf中的每一个配置对应的路径和文件都必须存在,否则就会出错。
第二个问题:如果没把集群配起,hdfs不能使用,配集群要设置SSH,使master不输入口令就可以连接到slave,配置方法如下:
第一步:生成密匙对,我用的是rsa的密钥。使用命令 "ssh-keygen -t rsa"


[user1@rh user1]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory '/home/user1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
e0:f0:3b:d3:0a:3d:da:42:01:6a:61:2f:6c:a0:c6:e7 user1@rh.test.com
[user1@rh user1]$

生成的过程中提示输入密钥对保存位置,直接回车,接受默认值就行了。接着会提示输入一

个不同于你的password的密码,直接回车,让它空着。当然,也可以输入一个。(我比较懒

,不想每次都要输入密码。) 这样,密钥对就生成完了。

其中公共密钥保存在 ~/.ssh/id_rsa.pub
私有密钥保存在 ~/.ssh/id_rsa


之后把这个密钥对中的公共密钥复制到你要访问的机器上去,并保存为 

~/.ssh/authorized_keys.