Hadoop部署方式-本地模式(Local (Standalone) Mode)
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
Hadoop总共有三种运行方式。本地模式(Local (Standalone) Mode),伪分布式(Pseudo-Distributed Mode),分布式(Fully-Distributed Mode)。本篇博客主要讲解第一种运行方式,即本地运行方式,想要查看伪分布式的小伙伴请参考:https://www.cnblogs.com/yinzhengjie/p/9058415.html,想要查看完全分布式的小伙伴请参考:https://www.cnblogs.com/yinzhengjie/p/9065191.html。
需要注意的是,本地运行模式,实际上就是用Linux操作系统,会直接把文件存储在Linux路径上,我们在上传文件的时候要注意权限哟,比如你在搭建好Hadoop本地模式后,直接就提交一个文件到根下的话,可能会报权限错误哟,但是,如果你是root用户的话就另当别论了。
一.下载相应的jdk和Hadoop安装包
jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Hadoop:http://hadoop.apache.org/releases.html
注意,Hadoop官方虽然没有windows版本,但是可用通过“visual studio”编译工具将Linux的运行伪分布式迁移到windows中,建议安装2015版本,网上的教程有很多。遗憾的是,这个工具的使用并不是本篇博客的重点。
二.安装Java环境
1>.创建软件解压目录并授权给普通用户
[yinzhengjie@yinzhengjie ~]$ ll
total
-rw-rw-r--. yinzhengjie yinzhengjie Aug hadoop-2.7..tar.gz
-rw-rw-r--. yinzhengjie yinzhengjie May jdk-8u131-linux-x64.tar.gz
[yinzhengjie@yinzhengjie ~]$ sudo mkdir /soft
[sudo] password for yinzhengjie:
[yinzhengjie@yinzhengjie ~]$ sudo chown yinzhengjie:yinzhengjie /soft/
[yinzhengjie@yinzhengjie ~]$ ll /soft/ -d
drwxr-xr-x. yinzhengjie yinzhengjie May : /soft/
[yinzhengjie@yinzhengjie ~]$
2>.解压jdk并配置软连接路径
[yinzhengjie@yinzhengjie ~]$ tar zxf jdk-8u131-linux-x64.tar.gz -C /soft/
[yinzhengjie@yinzhengjie ~]$ cd /soft/
[yinzhengjie@yinzhengjie soft]$ ll
total
drwxr-xr-x. yinzhengjie yinzhengjie Mar jdk1..0_131
[yinzhengjie@yinzhengjie soft]$ ln -s jdk1..0_131/ jdk
[yinzhengjie@yinzhengjie soft]$ ll
total
lrwxrwxrwx. yinzhengjie yinzhengjie May : jdk -> jdk1..0_131/
drwxr-xr-x. yinzhengjie yinzhengjie Mar jdk1..0_131
[yinzhengjie@yinzhengjie soft]$
3>.设置Java环境变量
[yinzhengjie@yinzhengjie soft]$ sudo vi /etc/profile
[yinzhengjie@yinzhengjie soft]$ tail - /etc/profile
#Add by yinzhengjie
JAVA_HOME=/soft/jdk/
PATH=$PATH:$JAVA_HOME/bin
[yinzhengjie@yinzhengjie soft]$ . /etc/profile
[yinzhengjie@yinzhengjie soft]$
[yinzhengjie@yinzhengjie soft]$ java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) -Bit Server VM (build 25.131-b11, mixed mode)
[yinzhengjie@yinzhengjie soft]$
三.安装Hadoop
1>.解压jdk并配置软连接路径
[yinzhengjie@yinzhengjie ~]$ ll
total
-rw-rw-r--. yinzhengjie yinzhengjie Aug hadoop-2.7..tar.gz
-rw-rw-r--. yinzhengjie yinzhengjie May jdk-8u131-linux-x64.tar.gz
[yinzhengjie@yinzhengjie ~]$ tar zxf hadoop-2.7..tar.gz -C /soft/
[yinzhengjie@yinzhengjie ~]$ ln -s /soft/hadoop-2.7./ /soft/hadoop
[yinzhengjie@yinzhengjie ~]$ ll /soft/
total
lrwxrwxrwx. yinzhengjie yinzhengjie May : hadoop -> /soft/hadoop-2.7./
drwxr-xr-x. yinzhengjie yinzhengjie Aug hadoop-2.7.
lrwxrwxrwx. yinzhengjie yinzhengjie May : jdk -> jdk1..0_131/
drwxr-xr-x. yinzhengjie yinzhengjie Mar jdk1..0_131
[yinzhengjie@yinzhengjie ~]$
2>.设置Hadoop的环境变量
[yinzhengjie@yinzhengjie ~]$ sudo vi /etc/profile
[sudo] password for yinzhengjie:
[yinzhengjie@yinzhengjie ~]$ tail - /etc/profile
#Add by yinzhengjie
JAVA_HOME=/soft/jdk/
PATH=$PATH:$JAVA_HOME/bin #Add HADOOP_HOME
HADOOP_HOME=/soft/hadoop/
PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
[yinzhengjie@yinzhengjie ~]$
[yinzhengjie@yinzhengjie ~]$ source /etc/profile
[yinzhengjie@yinzhengjie ~]$ grep JAVA_HOME /soft/hadoop/etc/hadoop/hadoop-env.sh | grep -v ^#
export JAVA_HOME=/soft/jdk/
[yinzhengjie@yinzhengjie ~]$
3>.验证是否安装完毕(注意,提交的目录当前用户需要有权限,因为本地部署不需要启动服务,它用的就是Linux操作系统,如果普通用户把文件直接提交到根的话肯定会报异常的哟!)
[yinzhengjie@yinzhengjie ~]$ ll
total
-rw-rw-r--. yinzhengjie yinzhengjie Aug hadoop-2.7..tar.gz
-rw-rw-r--. yinzhengjie yinzhengjie May jdk-8u131-linux-x64.tar.gz
-rw-r--r--. yinzhengjie yinzhengjie May : test
[yinzhengjie@yinzhengjie ~]$ rm -rf test
[yinzhengjie@yinzhengjie ~]$
[yinzhengjie@yinzhengjie ~]$
[yinzhengjie@yinzhengjie ~]$ ll
total
-rw-rw-r--. yinzhengjie yinzhengjie Aug hadoop-2.7..tar.gz
-rw-rw-r--. yinzhengjie yinzhengjie May jdk-8u131-linux-x64.tar.gz
[yinzhengjie@yinzhengjie ~]$
[yinzhengjie@yinzhengjie ~]$ hdfs dfs -put hadoop-2.7..tar.gz /home/yinzhengjie/test
[yinzhengjie@yinzhengjie ~]$ tar zxf test
[yinzhengjie@yinzhengjie ~]$ ll
total
drwxr-xr-x. yinzhengjie yinzhengjie Aug hadoop-2.7.
-rw-rw-r--. yinzhengjie yinzhengjie Aug hadoop-2.7..tar.gz
-rw-rw-r--. yinzhengjie yinzhengjie May jdk-8u131-linux-x64.tar.gz
-rw-r--r--. yinzhengjie yinzhengjie May : test
[yinzhengjie@yinzhengjie ~]$