3步在Linux虚拟机搭建Hadoop

1.虚拟机环境准备

(1)克隆虚拟机;
(2)配置mac:
在这里插入图片描述
配置mac:

vim /etc/udev/rules.d/70-persistent-net.rules 
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:21:7F:7E", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

删除 /etc/udev/rules.d/70-persistent-net.rules,重启,若还是不可以正常使用,则可以把70-persistent-net.rules和70-persistent-cd.rules一同删除,重启之后系统会重新生成文件,就可以使用新克隆的虚拟机了。

配置网卡:

vim /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE="eth0"
BOOTPROTO="dhcp"
ONBOOT="yes"

重启网卡服务:

service network restart

(3)修改主机名;
①临时有效:无需重启

hostname NEW_NAME   

②永久有效

[root@liupeng ~]# vim /etc/hosts
...  hadoop 

(4)关闭防火墙;
①重启后生效
开启: chkconfig iptables on
关闭: chkconfig iptables off
② 即时生效,重启后失效
开启: service iptables start
关闭: service iptables stop

(5)创建hadoop用户;

# 创建用户
adduser hadoop
passwd hadoop
输入2次密码

(6)配置hadoop用户具有root权限:

方法1,去井号,赋予root组权限

vim /etc/sudoers
## Allows people in group wheel to run all commands
 %wheel	ALL=(ALL)	ALL

usermod -g root hadoop

修改完毕,现在可以用hadoop帐号登录,然后用命令 su – ,即可获得root权限进行操作。

方法2:加一行

vim /etc/sudoers
## Allow root to run any commands anywhere 
root	ALL=(ALL) 	ALL
hadoop ALL=(ALL) ALL

修改完毕,现在可以用hadoop帐号登录,然后用命令 sudo – ,即可获得root权限进行操作。

方法3:修改 /etc/passwd 文件

hadoop:x:0:501::/home/hadoop:/bin/bash

(7)用hadoop用户,在/opt目录下创建文件夹 module、software;

sudo mkdir module
sudo mkdir software

修改module、software目录的所有者:

sudo chown hadoop:hadoop module/ software/

2.安装jdk1.8

(1)卸载当前低于1.7的jdk
判断jdk是否安装(显示版本号等信息,说明已经安装)

which java(查看JDK的安装路径) 

卸载:

rm -rf JDK地址(卸载JDK) 

查看是否卸载完毕:

java -version
java
javac

删除配置的环境变量,至此JDK卸载完毕:

vi /etc/profile
删除JAVA_HOME=...

(2)安装jdk:
从官网下载:jdk-8u251-linux-x64.tar.gz,上传到/opt/software目录;
解压到/opt/module:

tar -xzvf jdk-8u251-linux-x64.tar.gz -C /opt/module/

配置JDK环境变量:
①获取JDK路径:

[hadoop@hadoop jdk1.8.0_251]$ pwd
/opt/module/jdk1.8.0_251

②配置/etc/profile,添加:

[hadoop@hadoop jdk1.8.0_251]$ sudo vim /etc/profile
export JAVA_HOME=/opt/module/jdk1.8.0_251
export PATH=$PATH:$JAVA_HOME/bin   

③让修改后的文件生效(即加载环境变量):

[hadoop@hadoop jdk1.8.0_251]$ source /etc/profile

④验证是否安装成功:

[hadoop@hadoop jdk1.8.0_251]$ java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
[hadoop@hadoop jdk1.8.0_251]$ 

3.安装Hadoop

(1)官网下载:hadoop-2.7.2.tar.gz,并上传到虚拟机的/opt/software;
(2)解压到/opt/software:

[hadoop@hadoop software]$ tar -xzvf hadoop-2.7.2.tar.gz -C /opt/module/

(3)将Hadoop添加到环境变量:

[hadoop@hadoop hadoop-2.7.2]$ pwd
/opt/module/hadoop-2.7.2
[hadoop@hadoop hadoop-2.7.2]$ sudo vim /etc/profile
 #HADOOP_HOME                        
export HADOOP_HOME=/opt/module/hadoop-2.7.2
export PATH=$PATH:$HADOOP_HOME/bin  
export PATH=$PATH:$HADOOP_HOME/sbin  

(4)让修改后的文件生效(即加载环境变量):

[hadoop@hadoop hadoop-2.7.2]$ source /etc/profile

(5)测试安装是否成功:

[hadoop@hadoop hadoop-2.7.2]$ hadoop version
Hadoop 2.7.2
Subversion https://git-wip-us.apache.org/repos/asf/hadoop.git -r b165c4fe8a74265c792ce23f546c64604acf0e41
Compiled by jenkins on 2016-01-26T00:08Z
Compiled with protoc 2.5.0
From source with checksum d0fda26633fa762bff87ec759ebe689c
This command was run using /opt/module/hadoop-2.7.2/share/hadoop/common/hadoop-common-2.7.2.jar
[hadoop@hadoop hadoop-2.7.2]$ 

注:hadoop version执行不对的话,重启虚拟机即可。

posted @ 2020-05-22 15:40  斯言甚善  阅读(703)  评论(0编辑  收藏  举报