-
上传、解压,删掉暂时无用的share/doc文件。
-
配置环境变量。注意改完要:source .bashrc
export HADOOP_HOME=/usr/java/hadoop-3.3.1
export HADOOP_MAPRED_HOME=/usr/java/hadoop-3.3.1
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
-
其他配置:位置$HADOOP_HOME/etc/hadoop/
hadoop-3.2.0/etc/hadoop/core-site.xml
hadoop-3.2.0/etc/hadoop/hdfs-site.xml
hadoop-3.2.0/etc/hadoop/mapred-site.xml
hadoop-3.2.0/etc/hadoop/yarn-site.xml
参考:https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/ClusterSetup.html
-
core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://master-yh:9000</value>
</property>
</configuration>
-
hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/opt/hdfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/opt/hdfs/data</value>
</property>
</configuration>
-
mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.application.classpath</name>
<value>$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/*:$HADOOP_MAPRED_HOME/share/hadoop/mapreduce/lib/*</value>
</property>
</configuration>
-
yarn-site.xml
<configuration>
<!-- Reducer获取数据的方式 -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.env-whitelist</name>
<value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_HOME,PATH,LANG,TZ,HADOOP_MAPRED_HOME</value>
</property>
<!-- 指定启动YARN的ResourceManager的主机地址 -->
<property>
<name>yarn.resourcemanager.hostname</name>
<value>master-yh</value>
</property>
</configuration>
-
需要的目录/opt/hdfs/name 和/opt/hdfs/data 两个目录需要手动创建,并赋予权限。 配置 HDFS 需要 name 目录和 data 目录。
[hyidol@master-yh hadoop]$ cd /opt/
[hyidol@master-yh opt]$ sudo mkdir hdfs
[sudo] hyidol 的密码:
[hyidol@master-yh opt]$ ll
总用量 0
drwxr-xr-x. 2 root root 6 9月 29 07:43 hdfs
[hyidol@master-yh opt]$ su
密码:
[root@master-yh opt]# chmod -R 777 hdfs/
[root@master-yh opt]# exit
exit
[hyidol@master-yh opt]$ cd hdfs
[hyidol@master-yh hdfs]$ mkdir name
[hyidol@master-yh hdfs]$ mkdir data
[hyidol@master-yh hdfs]$ ll
总用量 0
drwxrwxr-x. 2 hyidol hyidol 6 9月 29 07:45 data
drwxrwxr-x. 2 hyidol hyidol 6 9月 29 07:45 name
每一台主机,都需要操作!!比如slave1-yh:
[hyidol@master-yh hdfs]$ ssh slave1-yh
Last login: Wed Sep 29 04:04:39 2021 from master-yh
[hyidol@slave1-yh ~]$ cd /opt/
[hyidol@slave1-yh opt]$ sudo mkdir hdfs
[sudo] hyidol 的密码:
[hyidol@slave1-yh opt]$ su
密码:
[root@slave1-yh opt]# chmod -R 777 hdfs/
[root@slave1-yh opt]# exit
exit
[hyidol@slave1-yh opt]$ cd hdfs
[hyidol@slave1-yh hdfs]$ mkdir name
[hyidol@slave1-yh hdfs]$ mkdir data
汇总下:
cd /opt/
sudo mkdir hdfs (密码是hyidol)
su (密码是root)
chmod -R 777 hdfs/
exit
cd hdfs
mkdir name
mkdir data
-
配置worker。注意worker 是设置DataNode节点的,所以不用把master加上。
[hyidol@master-yh hadoop]$ vi /usr/java/hadoop-3.3.1/etc/hadoop/workers
slave1-yh
slave2-yh
-
把 hadoop-3.3.1 目录传送到其他三台主机。
[hyidol@master-yh java]$ scp -r /usr/java/hadoop-3.3.1/ hyidol@slave1-yh:/usr/java/
-
(已解决)出现如下权限问题的时候,有可能不是说源文件的权限不够,而是需要复制的位置没有权限,不能写入文件:
[root@master-yh java]# scp -r hadoop-3.3.1/ hyidol@slave1-yh:/usr/java/
scp: /usr/java//hadoop-3.3.1: Permission denied
[hyidol@master-yh java]$ ssh slave1-yh
[hyidol@slave1-yh usr]$ su
[root@slave1-yh usr]# chmod -R 777 java
[root@slave1-yh usr]# exit
-
环境变量配置也要传送。
[hyidol@master-yh java]$ cd
[hyidol@master-yh ~]$ scp .bashrc hyidol@slave1-yh:~/
[hyidol@master-yh ~]$ scp .bashrc hyidol@slave2-yh:~/
-
格式 HDFS。
[hyidol@master-yh ~]$ cd /usr/java/hadoop-3.3.1/
[hyidol@master-yh hadoop-3.3.1]$ bin/hdfs namenode -format
-
启动 hadoop 所有服务。这里的没日志警告不用管,再启动就会发现它自己给创建了,没创的话给个权限就行。
[hyidol@master-yh ~]$ start-all.sh
WARNING: Attempting to start all Apache Hadoop daemons as hyidol in 10 seconds.
WARNING: This is not a recommended production deployment configuration.
WARNING: Use CTRL-C to abort.
Starting namenodes on [master-yh]
Starting datanodes
slave1-yh: WARNING: /usr/java/hadoop-3.3.1/logs does not exist. Creating.
slave2-yh: WARNING: /usr/java/hadoop-3.3.1/logs does not exist. Creating.
Starting secondary namenodes [master-yh]
Starting resourcemanager
Starting nodemanagers
-
master
[hyidol@master-yh hadoop-3.3.1]$ jps
15249 SecondaryNameNode
15060 NameNode
15492 ResourceManager
15789 Jps
-
slave1
[hyidol@slave1-yh hadoop-3.3.1]$ jps
18497 DataNode
18594 NodeManager
18710 Jps
-
slave2
[hyidol@slave2-yh hadoop-3.3.1]$ jps
3015 DataNode
3112 NodeManager
3228 Jps