一、准备工作
1、安装 VMware,已安装的,跳过此步骤即可
官方正版VMware下载(16 pro):https://www.aliyundrive.com/s/wF66w8kW9ac
安装:选一下安装地址,一直下一步即可。(可能会要求重启电脑,重启即可)
2、安装CentOS7.5
下载Linux系统镜像(阿里云盘不限速):https://www.aliyundrive.com/s/UQMBPEovxNg
(系统镜像下载后,把后缀mp4改成iso即可正常使用)
参考VMware虚拟机安装(非常详细)从零基础入门到精通,看完这一篇就够了
3、安装JDK1.8
3.1官网下载安装包,上传至服务器,解压tar包
tar -zxvf jdk-8u221-linux-x64.tar.gz -C /opt/module/
备注:这里的-C不能省略
3.2配置java环境变量、生效
vi /etc/profile
export JAVA_HOME=/opt/module/jdk1.8.0_221
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
把上述环境变量添加到/etc/profile中并生效
source /etc/profile
3.3检测Java版本:
[root@hadoop1 ~]# java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
备注:每台机器上都需要 j d k 环境 \color{Salmon}备注:每台机器上都需要jdk环境 备注:每台机器上都需要jdk环境
4、Hadoop环境准备
根据自己的网段,规划出4个IP
192.168.80.5 hadoop1
192.168.80.6 hadoop2
192.168.80.7 hadoop3
4.1修改主机名
hostnamectl set-hostname hadoop1
hostname #查看一下
ls
4.2 hosts修改域名:(三个节点上都配一遍)
vi /etc/hosts
添加内容为
192.168.80.5 hadoop1
192.168.80.6 hadoop2
192.168.80.7 hadoop3
4.3配置SSH免密码登录
有什么作用?当用一台计算机用户登录另一台计算机时,每次登录都必须输入密码,在hadoop中,需要成千上万次登录,那么如果每次都需要输入密码的话,速度太慢了,而且折磨人
进入.ssh目录:cd /root/.ssh/
生成ssh秘钥:ssh-keygen -t rsa 一直回车,只需要第一台计算机这样生成秘钥即可
[root@hadoop1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Gx/StcC/VVyzkMoT15+ErqQDqZPt3RyfuImkdFh+9HA root@hadoop1
The key's randomart image is:
+---[RSA 2048]----+
| .+..|
| . . +.++|
| . + * ..=|
| o . O o o.|
| + S.=o=E. |
| + .+B.++o |
| ooo+=.=.. |
| ..+.o+.o |
| . . o. |
+----[SHA256]-----+
到此生成了两个文件:id_rsa和id_rsa.pub
在第一台计算机上执行:cp id_rsa.pub authorized_keys 生成副本
修改文件权限:
chmod 644 authorized_keys
测试一下本机无密码登录
service sshd restart
测试第一台计算机与其他计算机无密码登录
[root@hadoop1 .ssh]# ssh hadoop1
Last login: Wed Nov 29 20:13:24 2023 from 192.168.80.1
[root@hadoop1 ~]# exit
logout
Connection to hadoop1 closed.
以下情况则代表登录成功:
向其他几台计算机发送秘钥:
scp /root/.ssh/authorized_keys 目的机用户名@目的机名称:/root/.ssh
scp /root/.ssh/authorized_keys root@hadoop2:/root/.ssh
测试能否无密码登录其他计算机
[root@hadoop1 ~]# ssh hadoop2
Last failed login: Wed Nov 29 20:18:43 EST 2023 from hadoop1 on ssh:notty
There was 1 failed login attempt since the last successful login.
Last login: Wed Nov 29 20:02:00 2023 from 192.168.80.1
ok,到此成功配置SSH免密码登录
二、安装Hadoop
[root@hadoop1 ~]# cd /opt/software/
[root@hadoop1 software]# ls
hadoop-3.3.6.tar.gz jdk-8u221-linux-x64.tar.gz
[root@hadoop1 software]# scp /opt/software/hadoop-3.3.6.tar.gz root@hadoop2:/opt/module/
[root@hadoop1 software]# scp /opt/software/hadoop-3.3.6.tar.gz root@hadoop3:/opt/module/
[root@hadoop1 software]# tar -zxvf hadoop-3.3.6.tar.gz -C /opt/module/
vi /etc/profile #配置hadoop的环境变量
添加配置路径
HADOOP_HOME=/opt/module/hadoop-3.3.6
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
生效查看是否成功
[root@hadoop1 ~]# source /etc/profile #让其配置生效
[root@hadoop1 ~]# hadoop version #查看是否成功
Hadoop 3.3.6
Source code repository https://github.com/apache/hadoop.git -r 1be78238728da9266a4f88195058f08fd012bf9c
Compiled by ubuntu on 2023-06-18T08:22Z
Compiled on platform linux-x86_64
Compiled with protoc 3.7.1
From source with checksum 5652179ad55f76cb287d9c633bb53bbd
This command was run using /opt/module/hadoop-3.3.6/share/hadoop/common/hadoop-common-3.3.6.jar
配置文件修改、./sbin/start-dfs.sh
启动Hadoop