最新版hadoop2.7.1单机版与伪分布式安装配置

原文:http://blog.csdn.net/qq_21144531/article/details/50570355


前提:熟悉Linux系统操作,掌握基本的Linux命令

注意:安装路径中不能有任何中文字符和空格!

我安装的是ubuntu14,用户名是ubuntu,机器名是ubuntu,hadoop的版本是hadoop-2.7.1.tar.gz

一、在Ubuntu下创建hadoop用户组和用户

1、  将hadoop用户添加到系统用户

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. ubuntu@ubuntu:~$ sudo addgroup hadoop   
  2. ubuntu@ubuntu:~$ sudo adduser --ingroup hadoop hadoop   

2、 现在只是添加了一个用户hadoop,它并不具备管理员权限,我们给hadoop用户添加权限,打开/etc/sudoers文件

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. ubuntu@ubuntu:~$ sudo vim /etc/sudoers  

在root  ALL=(ALL:ALL)  ALL下添加hadoop  ALL=(ALL:ALL)  ALL

二、配置Java环境

1、 将jdk-7u80-linux-x64.tar.gz解压到相应路径(可以用命令也可以直接选中右键解压),我这里是解压/home/ubuntu/software/java,解压后文件夹为jdk1.7.0_80(所在路径为/home/ubuntu/software/java/jdk1.7.0_80)

2、 解压完之后配置环境变量

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. ubuntu@ubuntu:$ sudo vim /etc/profile  

在最后添加如下:

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. export JAVA_HOME=/home/ubuntu/software/java/jdk1.7.0_80  
  2. export JRE_HOME=/home/ubuntu/software/java/jdk1.7.0_80/jre  
  3. exportCLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib  
  4. exportPATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin  
[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. 运行java -version命令验证Java是否安装配置成功。  
[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. ubuntu@ubuntu:~$ java -version  
  2. java version "1.7.0_80"  
  3. Java(TM) SE Runtime Environment (build 1.7.0_80-b15)  
  4. Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)  


 

三、SSH安装

1、  先安装ssh。记住:从这里开始需要先从ubuntu用户切换到hadoop用户

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. ubuntu@ubuntu:~$ su - hadoop  
  2. Password:  
  3. hadoop@ubuntu:~$ sudo apt-get install openssh-server  

2、  如果ssh安装完成之后,先启动服务

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:~$ sudo /etc/init.d/ssh start  

启动后通过命令查看是否正确启动

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:~$ ps -e |grep ssh  

3、  作为一个安全通信协议(ssh生成密钥有rsa和dsa两种生成方式,默认情况下采用rsa方式),使用时需要密码,因此我们要设置成免密码登录,生成私钥和公钥:

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:~$ ssh-keygen -t rsa -P ""  

(注:回车后会在~/.ssh/下生成两个文件:id_rsa和id_rsa.pub这两个文件是成对出现的前者为私钥,后者为公钥)

进入~/.ssh/目录下,将公钥id_rsa.pub追加到authorized_keys授权文件中,开始是没有authorized_keys文件的(authorized_keys 用于保存所有允许以当前用户身份登录到ssh客户端用户的公钥内容):

hadoop@ubuntu:~$ cat ~/.ssh/id_rsa.pub>> ~/.ssh/authorized_keys

执行ssh localhost命令进行登录:

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:~$ ssh localhost  
  2. Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.19.0-43-generic x86_64)  
  3.    
  4.  * Documentation:  https://help.ubuntu.com/  
  5.    
  6. 18 packages can be updated.  
  7. 18 updates are security updates.  
  8.    
  9. Last login: Thu Jan 21 14:40:38 2016 from localhost  

出现“Welcome to Ubuntu 14.04.3 LTS。。。”则表示登录成功。

( 注:当ssh远程登录到其它机器后,现在你控制的是远程的机器,需要执行退出命令才能重新控制本地主机。)

使用命令exit可以进行退出

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:~$ exit  
  2. logout  
  3. Connection to localhost closed.  

编辑/etc/hosts文件,将

127.0.0.1      localhost127.0.1.1       ubuntu

改为

192.168.1.128       localhost192.168.1.128       ubuntu

注:192.168.1.128为虚拟机机的ip地址(用命令ifconfig可以查看ip)

四、安装hadoop-2.7.1

1、  将hadoop-2.7.gz解压到/usr/local下面

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:~$ sudo tar –xzf hadoop-2.7.gz  

重命名hadoop-2.7.1文件夹名为hadoop(为了敲命令方便)

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:~$ sudo mv hadoop-2.7.1 hadoop  

2、 要确保所有的操作都是在用户hadoop下完成的,所以将该hadoop文件夹的属主用户设为hadoop。

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:/usr/local$sudo chown –R hadoop:hadoop hadoop  

3、  配置hadoop-env.sh文件(hadoop-env.sh文件在hadoop/etc/hadoop路径下面)

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:/usr/local$ sudo vim /usr/local/hadoop/etc/hadoop/hadoop-env.sh  

在hadoop-env.sh中export JAVA_HOME后面添加以下信息(JAVA_HOME路径改为实际路径):

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. export JAVA_HOME=/home/ubuntu/software/java/jdk1.7.0_80  
  2. export HADOOP_INSTALL=/usr/local/hadoop  
  3. export PATH=$PATH:/usr/local/hadoop/bin:/usr/local/hadoop/sbin  
  4. export HADOOP_MAPRED_HOME=$HADOOP_INSTALL  
  5. export HADOOP_COMMON_HOME=$HADOOP_INSTALL  
  6. export YARN_HOME=$HADOOP_INSTALL  

保存之后运行下面命令使配置生效

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:/usr/local/hadoop/etc/hadoop$source hadoop-env.sh  


再到/etc/profile中添加HADOOP_INSTALL并修改PATH,结果为

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. export JAVA_HOME=/home/ubuntu/software/java/jdk1.7.0_80  
  2. export JRE_HOME=/home/ubuntu/software/java/jdk1.7.0_80/jre  
  3. export HADOOP_INSTALL=/usr/local/hadoop  
  4. export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib  
  5. exportPATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$HADOOP_INSTALL/bin:$HADOOP_INSTALL/sbin  

保存后重启虚拟机。

切换到hadoop用户,

运行命令

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:/usr/local/hadoop$ hadoop version  

如果看到如下hadoop版本信息则表示hadoop单机模式安装成功

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:/usr/local/hadoop$ hadoop version  
  2. Hadoop 2.7.1  
  3. Subversion https://git-wip-us.apache.org/repos/asf/hadoop.git -r15ecc87ccf4a0228f35af08fc56de536e6ce657a  
  4. Compiled by jenkins on 2015-06-29T06:04Z  
  5. Compiled with protoc 2.5.0  
  6. From source with checksum fc0a1a23fc1868e4d5ee7fa2b28a58a  
  7. This command was run using/usr/local/hadoop/share/hadoop/common/hadoop-common-2.7.1.jar  


现在运行一下hadoop自带的例子wordcount来感受以下MapReduce过程:在hadoop目录下新建input文件夹

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:/usr/local/hadoop$ sudo mkdir input   


将etc中的所有文件拷贝到input文件夹中

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:/usr/local/hadoop$ cp etc/*input   

运行wordcount程序,并将结果保存到output中(注意input所在路径、jar所在路径)

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:/usr/local/hadoop/share/hadoop/mapreduce$bin/hadoop jar hadoop-mapreduce-examples-2.7.1.jarwordcount /usr/local/hadoop/input/hadoop output  

运行

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:/usr/local/hadoop$ cat output/*  

会看到conf所有文件的单词和频数都被统计出来。 

 

 

到此单机模式已经安装成功,下面可以接着伪分布模式安装
一、在/etc/hadoop下配置一下几个文件core-site.xml、hdfs-site.xml、mapred-site.xml、yarn-site.xml在后面添加如下信息
[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. core-site.xml  

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <configuration>  
  2. <property>  
  3.        <name>hadoop.tmp.dir</name>  
  4.        <value>file:/usr/local/hadoop/tmp</value>  
  5.        <description>Abase for other temporarydirectories.</description>  
  6. </property>  
  7. <property>   
  8.        <name>fs.defaultFS</name>   
  9.        <value>hdfs://192.168.154.128:9000</value>   
  10. </property>   
  11. </configuration>  

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hdfs-site.xml  

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <configuration>  
  2.    <property>   
  3.        <name>dfs.replication</name>   
  4.        <value>1</value>   
  5.    </property>   
  6.    <property>   
  7.        <name>dfs.namenode.name.dir</name>   
  8.        <value>file:/usr/local/hadoop/tmp/dfs/name</value>   
  9.    </property>   
  10.    <property>   
  11.        <name>dfs.datanode.data.dir</name>   
  12.        <value>file:/usr/local/hadoop/tmp/dfs/data</value>   
  13.    </property>  
  14. </configuration>  

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. mapred-site.xml(没有则复制一份mapred-site.xml.template并命名为mapred-site.xml)  
[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <configuration>  
  2. <property>     
  3.        <name>mapreduce.framework.name</name>   
  4.        <value>yarn</value>      
  5. </property>  
  6. </configuration>  

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. yarn-site.xml  
[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <configuration>  
  2. <property>  
  3.        <name>yarn.nodemanager.aux-services</name>  
  4.        <value>mapreduce_shuffle</value>  
  5. </property>  
  6. <property>  
  7.        <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>  
  8.        <value>org.apache.hadoop.mapred.ShuffleHandler</value>  
  9. </property>  
  10. </configuration>  

 

二、HDFS文件系统格式化和系统启动

下面进行HDFS文件系统进行格式化:

 

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. $bin/hdfs namenode -format  

然后启用NameNode及DataNode进程:

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:/usr/local/hadoop$ sbin/start-dfs.sh  
[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1.   
[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. hadoop@ubuntu:/usr/local/hadoop$ sbin/start-yarn.sh  
 

启动进程之后用jps命令查看进程情况,出现6个进程名字说明启动成功

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. 8431 JobTracker    
  2. 8684 TaskTracker    
  3. 7821 NameNode    
  4. 7281 DataNode  
  5. 8915 Jps    
  6. 8341 SecondaryNameNode   


至此,hadoop伪分布式安装成功。


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值