下载和安装Java Development Kit (JDK) 8
- 大多数环境使用jdk8较为合适除非有特殊需求
#下载JDK 8
wget https://download.java.net/java/GA/jdk8/8u301-b09/jdk-8u301-linux-x64.tar.gz
#解压JDK安装包
tar -zxvf jdk-8u301-linux-x64.tar.gz -C /usr/local
#环境变量
vi /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0_301
export PATH=$PATH:$JAVA_HOME/bin
#保存并关闭文件
source /etc/profile
下载和安装Hadoop 3.3.5
wget https://downloads.apache.org/hadoop/common/hadoop-3.3.5/hadoop-3.3.5.tar.gz
tar -zxvf hadoop-3.3.5.tar.gz -C /usr/local/
#配置Hadoop环境变量
vi /etc/profile
export HADOOP_HOME=/usr/local/hadoop-3.3.5
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
source /etc/profile
- 配置Hadoop
cd /usr/local/hadoop-3.3.5/etc/hadoop/
vi hadoop-env.sh
export JAVA_HOME=/usr/local/jdk1.8.0_301
vi core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
vi hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
vi mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
vi yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce_shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>localhost</value>
</property>
</configuration>
格式化Hadoop文件系统:
- 使用以下命令格式 - HDFS:hdfs namenode -format
启动Hadoop:
- 使用以下命令启动Hadoop服务:start-all.sh
- 使用以下命令验证Hadoop是否正常运行:
- 查看HDFS状态:hdfs dfsadmin -report
- 查看YARN状态:yarn node -list
hadoop集群(environment:五台centos7.9)
# 配置hosts文件:
sudo vim /etc/hosts
192.168.2.110 hadoop001
192.168.2.111 hadoop002
192.168.2.112 hadoop003
192.168.2.113 hadoop004
192.168.2.114 hadoop005
# 创建用户名
sudo useradd bigdata
sudo passwd bigdata
#解压JDK到/opt/module目录下:
tar -zxvf jdk-8u144-linux-x64.tar.gz -C /opt/module/
cd /opt/module/
配置JDK环境变量:
sudo vim /etc/profile
#JAVA_HOME
export JAVA_HOME=/opt/module/jdk1.8.0_144
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
java -version
下载Hadoop并解压到/opt目录下:
wget http://mirror.bit.edu.cn/apache/hadoop/common/hadoop-2.7.5/hadoop-2.7.5.tar.gz
tar -zxvf hadoop-2.7.5.tar.gz -C /opt/
```
配置Hadoop环境变量:
sudo vim /etc/profile
export HADOOP_HOME=/opt/hadoop-2.7.5
export PATH=$PATH:$HADOOP_HOME/bin
```
source /etc/profile
配置hadoop-env.sh文件:
sudo vim /opt/hadoop-2.7.5/etc/hadoop/hadoop-env.sh
export JAVA_HOME=/opt/jdk1.8.0_45
后面的全部重复
- 在第一台机器上配置好Hadoop,并确保它正常运行。
- 将Hadoop配置文件复制到其他四台机器上。您可以使用SSH或其他文件传输工具来复制文件。
```shell
# 假设第一台机器的IP地址是10.0.0.1,其他四台机器的IP地址分别是10.0.0.2、10.0.0.3、10.0.0.4、10.0.0.5
# 假设Hadoop配置文件的路径是/opt/hadoop/etc/hadoop
# 将第一台机器的Hadoop配置文件复制到其他四台机器上
scp -r /opt/hadoop/etc/hadoop/* 10.0.0.2:/opt/hadoop/etc/hadoop/
scp -r /opt/hadoop/etc/hadoop/* 10.0.0.3:/opt/hadoop/etc/hadoop/
scp -r /opt/hadoop/etc/hadoop/* 10.0.0.4:/opt/hadoop/etc/hadoop/
scp -r /opt/hadoop/etc/hadoop/* 10.0.0.5:/opt/hadoop/etc/hadoop/