【hadoop】centos7.6+hadoop3.1.1搭建分布式hadoop环境——包含各类问题解决方案
发布人:shili8
发布时间:2025-01-10 06:43
阅读次数:0
**Hadoop环境搭建指南**
本文将指导您如何在CentOS7.6上安装并配置Hadoop3.1.1,建立一个分布式Hadoop环境。
### 一、准备工作####1. 安装JDK首先,我们需要安装Java Development Kit(JDK)。可以使用以下命令安装:
bashsudo yum install -y java-1.8.0-openjdk-devel
####2. 下载Hadoop下载Hadoop3.1.1的压缩包:
bashwget /> ### 二、配置环境变量####1. 配置JDK环境变量编辑`~/.bashrc`文件,添加以下内容:bashexport JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64export PATH=$PATH:$JAVA_HOME/bin
####2. 配置Hadoop环境变量编辑`/etc/hosts`文件,添加以下内容(如果没有,则新建一个):bash127.0.0.1 hadoop-master127.0.0.1 hadoop-slave1127.0.0.1 hadoop-slave2
编辑`~/.bashrc`文件,添加以下内容:bashexport HADOOP_HOME=/usr/local/hadoop-3.1.1export PATH=$PATH:$HADOOP_HOME/bin
### 三、配置Hadoop####1. 配置core-site.xml编辑`$HADOOP_HOME/etc/hadoop/core-site.xml`文件,添加以下内容:xml
####2. 配置hdfs-site.xml编辑`$HADOOP_HOME/etc/hadoop/hdfs-site.xml`文件,添加以下内容:xml
####3. 配置mapred-site.xml编辑`$HADOOP_HOME/etc/hadoop/mapred-site.xml`文件,添加以下内容:xml
### 四、启动Hadoop####1. 启动NameNode和DataNodebashstart-dfs.sh
####2. 启动ResourceManager和NodeManagerbashstart-yarn.sh
####3. 检查Hadoop状态bashjps -l
### 五、测试Hadoop####1. 创建一个WordCount程序javaimport org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class WordCount {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "wordcount");
job.setJarByClass(WordCount.class);
job.setMapperClass(Map.class);
job.setCombinerClass(Reduce.class);
job.setReducerClass(Reduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path("/tmp/input"));
FileOutputFormat.setOutputPath(job, new Path("/tmp/output"));
System.exit(job.waitForCompletion(true) ?0 :1);
}
public static class Map extends Mapper