ubuntu系统
2.所需要的软件包
ubuntu系统安装包
JDK安装包(这里以jdk-6u30-linux-i586为例)
hadoop-0.20.203.0包(下载地址:http://apache.etoak.com//hadoop/core/hadoop-0.20.203.0/)
eclipse安装包
3.配置环境的步骤
3.1安装Ubuntu
安装Ubuntu这里就不说了,其实很简单和安装一般的软件没多大区别
3.2安装配置jdk
(1)在 /usr/local 下建立 java 文件夹
命令:sudo mkdir /usr/local/java
(2)将自己的jdk软件包拷贝到刚才建立的java文件夹下
命令:sudo cp jdk的路径 /usr/local/java
(3)在java文件夹下安装JDK
切换到java目录;
命令: cd /usr/local/java;
(4)给文件权限
命令:sudo chmod u+x jdk-6u30-linux-i586.bin
(5)安装jdk-6u30-linux-i586.bin
命令:sudo ./jdk-6u30-linux-i586.bin
(6)配置jdk环境
命令:sudo gedit /etc/profile
在配置文件尾添加如下代码
#set java environment
export JAVA_HOME=/ usr/local/java/jdk1.6.0_30
export JRE_HOME=/ usr/local/java/jdk1.6.0_30 /jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
(7)测试JDK是否安装成功
命令:java -version
java version "1.6.0_23"
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) Server VM (build 19.0-b09, mixed mode)
3.3安装配置ssh
(1)安装openssh_server
命令:sudo apt-get install openssh-server
(2)创建ssh-key,为rsa
命令:ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
(3)验证配置成功与否
命令:ssh localhost
Welcome to Ubuntu 11.10 (GNU/Linux 3.0.0-14-generic i686)
* Documentation: https://help.ubuntu.com/
108 packages can be updated.38 updates are security updates.
Last login: Sun Feb 5 10:45:19 2012 from localhost
3.4安装配置hadoop
(1)将hadoop压缩文件复制到local文件目录下;
命令:cp hadoop路径 /usr/local
(2)解压hadoop文件;
命令:sudo tar -xzf hadoop-0.20.203.0rc1.tar
(3)将解压后的文件夹更名为hadoop
s命令:sudo mv hadoop-0.20.203.0 hadoop
(4)建立hadoop用户组(建立一个名为hadoop的用户组和hadoop用户)
命令:sudo addgroup hadoop
(5)建立hadoop用户并归到hadoop用户组下
命令:sudo adduser -ingroup hadoop hadoop
(6)给hadoop权限
打开sudoers文件
命令:sudo gedit /etc/sudoers;
在root ALL =(ALL) ALL 下面添加如下代码;
hadoop ALL =(ALL) ALL;
4.配置hadoop
(1)打开conf/hadoop-env.sh
命令:cd /usr/local/hadoop
sudo gedit conf/hadoop-env.sh
配置conf/hadoop-env.sh(找到#export JAVA_HOME=...,去掉#,然后加上本机jdk的路径),如图15
(2)打开conf/core-site.xml
命令:cd /usr/local/hadoop
sudo gedit conf/core-site.xml
配置,如下内容:
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/hadoop/tmp</value>
</property>
</configuration>
(3)打开conf目录下的mapred-site.xml
命令:cd /usr/local/hadoop
sudo gedit conf/mapred-site.xml
配置如下内容:
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>localhost:9001</value>
</property>
</configuration>
5.hadoop测试
(1)改变用户,格式化namenode
命令:cd /usr/local/hadoop
./bin/hadoop hadoop namenode -format
(2)启动hadoop
命令:sudo chown -r /usr/local/hadoop
./bin start-all.sh
(3)测试是否启动成功
命令:jps命令
如果同时打印出:NameNode,JobTracker,SecondaryNameNode,jps,tasktracker,DataNode则表示安装成功;hadoop是否成功启动
(4)运行自带wordcount例子
首先准备两个本地文档;
sudo gedit /testin/test1.txt
sudo gedit /testin/test2.txt
写点单词
在hdfs中新建目录
./bin/hadoop dfs -mkdir test-in
上传本地文件到hdfs中指定的目录;
./bin/hadoop copyFromLocal /tmp/test*.txt test-in
运行wordcount;
./bin/hadoop jar hadoop-examples-0.20.203.0.jar wordcount file-in file-out
查看运行结果
./bin/hadoop dfs -cat file-out/part-r-00000
linux系统(这里以ubuntu11.10为例)