Hadoop官网地址
下载
wget https://mirrors.bfsu.edu.cn/apache/hadoop/common/hadoop-3.1.4/hadoop-3.1.4.tar.gz
解压
tar xf hadoop-3.1.4.tar.gz
配置环境变量
配置jdk教程
vim ~/.bash_profile
新增以下内容(路径修改为自己的解压路径):
export JAVA_HOME=/usr/java/jdk1.8.0_111
export PATH=$JAVA_HOME/bin:$PATH
export HADOOP_HOME=/home/hadoop/app/hadoop-3.1.4
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
执行命令(使配置生效)
source ~/.bash_profile
验证
hadoop version
出现版本号则成功
Hadoop 3.1.4
Source code repository https://github.com/apache/hadoop.git -r 1e877761e8dadd71effef30e592368f7fe66a61b
Compiled by gabota on 2020-07-21T08:05Z
Compiled with protoc 2.5.0
From source with checksum 38405c63945c88fdf7a6fe391494799b
This command was run using /home/hadoop/app/common/hadoop-3.1.4/share/hadoop/common/hadoop-common-3.1.4.jar
配置
core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://test-hadoop-a:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/modules/hadoopstandalone/data</value>
</property>
</configuration>
hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>ipc.maximum.data.length</name>
<value>134217728</value>
</property>
</configuration>
mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>test-hadoop-a</value>
</property>
<property>
<name>yarn.nodemanager.env-whitelist</name>
<value>JAVA_HOME,HADOOP_HDFS_HOME,HADOOP_COMMON_HOME,
HADOOP_CONF_DIR,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME,CLASSPATH_HOME</value>
</property>
</configuration>
初始化
hdfs namenode -format
启动
sbin/start-all.sh
访问
http://ip:8088
下载
hadoop-3.1.4.tar.gz 官网下载链接
配置环境变量
在系统变量中增加
HADOOP_HOME = 安装路径
path 增加 %HADOOP_HOME %\bin
修改配置文件
文件1:D:\hadoop\etc\hadoop\hadoop-env.cmd
set JAVA_HOME=D:\jdk
文件2:D:\hadoop\etc\hadoop\core-site.xml
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
文件3:D:\hadoop\etc\hadoop\hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/hadoop/data/dfs/namenode</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/hadoop/data/dfs/datanode</value>
</property>
</configuration>
文件4:D:\hadoop\etc\hadoop\mapred-site.xml mapred-site.xml是复制mapred-site.xml.template,去掉template
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
文件5:D:\hadoop\etc\hadoop\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>
</configuration>
启动
双击 sbin\start-all.cmd
访问
访问hadoop
http://ip:8088
访问hdfs的文件目录
http://ip:9870/explorer.html#/
hdfs的命令
访问文件
hdfs dfs -cat /sqoopdata/test/aa.txt
浏览目录
hdfs dfs -ls /sqoopdata/test
下载文件到本地
hdfs dfs -get
本地上传
hdfs dfs -put
删除文件
hdfs dfs -rm
创建目录
hdfs dfs -mkdir
其他问题
写入文件权限不足时,可以执行
hadoop fs -chmod 777 /user/hadoop