转载请注明出处:http://hanlaiming.freetzi.com/?p=77 java
1.实验环境 node
Ubuntu12.04 linux
Hadoop1.2.1 ubuntu
Java1.6.0_13 vim
2.实验准备 浏览器
1.在全部机器上安装ubuntu12.04,过程不赘述。 bash
在安装过程当中命名全部的用户名是hadoop,机器名分别为minglaihan,node1,node2,其中minglaihan做为主节点,其余两个是从节点。 ssh
2.在全部机器上执行: oop
sudo gedit etc/hosts 测试
添加以下地址:
192.168.1.104 minglaihan
192.168.1.109 node1
192.168.1.110 node2
3.保证你的用户拥有root级别
用gedit或者vim,
sudo gedit etc/sudoers
在root ALL=(ALL:ALL) ALL下添加hadoop ALL=(ALL:ALL) ALL。
3.安装过程
三台机器上都执行:
指令:cd ~/java
unzip jdk-6u13-linux-i586.zip
chmod +x jdk-6u13-linux-i586.bin
sudo ./ jdk-6u13-linux-i586.bin
接下来按Enter以及yes就能够了
Java安装好以后,在bash.bashrc里添加java路径
sudo gedit etc/bash.bashrc
添加:export JAVA_HOME=/home/hadoop/java/jdk1.6.0_13
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
而后就能够查看java –version。
三台机器上都执行:
sudo apt-get install ssh
安装完成后执行ssh localhost便可登陆自身的ssh,
exit退出
Ssh的一个重要特色就是能够远程访问,接下来咱们实现相互访问不须要密码。
在全部机器上执行:
cd ~/.ssh
ssh-keygen -t rsa -P “”以后一直按回车,而后能够看见提示生成密钥。
将id_rsa.pub追加到authorized_keys受权文件中
cat id_rsa.pub >> authorized_keys
而后在主节点minglaihan上执行:
进入/home/hadoop/.ssh目录中,复制authorized_keys到node1的.ssh文件夹中
scp authorized_keys hadoop@node1:/home/hadoop/.ssh
scp authorized_keys hadoop@node2:/home/hadoop/.ssh
接下来使用ssh node1和ssh node2就能够无密码访问了
首先在全部机器上执行解压缩操做
tar zxvf hadoop-1.2.1.tar.gz
而后开始修改hadoop/conf里面的配置文件
① core-sie.xml
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/hadoop/hadoop-1.2.1/tmp</value>
<description>A base for other temporary directories.</description>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://minglaihan:9000</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>
</configuration>
② hadoop-env.sh
添加:export JAVA_HOME=/home/hadoop/java/jdk1.6.0_13
③ hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>3</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>
<property>
<name>dfs.name.dir</name>
<value>/home/hadoop/hadoop-1.2.1/hdfs/name</value>
<description>
</description>
</property>
<property>
<name>dfs.data.dir</name>
<value>/home/hadoop/hadoop-1.2.1/hdfs/data</value>
<description>
</description>
</property>
</configuration>
④ mapred-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>3</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>
<property>
<name>dfs.name.dir</name>
<value>/home/hadoop/hadoop-1.2.1/hdfs/name</value>
<description>
</description>
</property>
<property>
<name>dfs.data.dir</name>
<value>/home/hadoop/hadoop-1.2.1/hdfs/data</value>
<description>
</description>
</property>
</configuration>
⑤ master
minglaihan
⑥ slaves
node1
node2
cd ~/hadoop-1.2.1
首先格式化namenode
bin/hadoop namenode –format
而后启动全部节点
bin/start-all.sh
用jps查看当前hadoop启动的进程
jps
若是若是有Namenode,SecondaryNameNode,TaskTracker,DataNode,JobTracker,Jps六个进程表示已经启动成功。
固然我在这一步卡了好久,始终有各类各样的问题,在这个过程当中也会学到不少,因此遇到有namenode或者datanode没启动,主要的处理方法就是清除tmp和logs文件夹,而后每次格式化后查看logs,根据报错查找问题。
stop-all.sh中止全部进程
此时在浏览器中查看minglaihan:50030,能够看到hadoop的mapreduce管理界面
在home主目录下建立一个装有无数单词的文本,例如test.txt
将test.txt传输到hdfs系统的input里,
bin/hadoop fs -copyFromLocal home/hadoop/test.txt input
在hadoop文件夹下执行:
hadoop jar hadoop-examples-1.2.1.jar wordcount input output
将输出结果传到output里
此时mapreduce会显示执行信息,执行完毕后,用指令查看
hadoop fs –cat output/part-r-00000
显示计算单词结果
至此,hadoop环境基本安装,期间遇到各类问题不要放弃。。。