1. 安裝jdk和ssh
1.1 下載jdk
jdk下載地址:https://www.oracle.com/java/technologies/javase-jdk14-downloads.html
1.2 安裝jdk
下載jdk完成後,將其解壓在以下目錄:
1.3 設置環境變量
在/etc/profile
中添加如下環境變量:
保存後執行如下命令,驗證java,可以看到,jdk已經安裝成功:
source /etc/profile
1.4 安裝並運行ssh
sudo apt-get install openssh-server
啓動ssh
sudo service ssh start
2. 安裝hadoop
2.1 下載hadoop
hadoop下載地址:http://apache.communilink.net/hadoop/common/
2.2 安裝hadoop
下載hadoop完成後,將其解壓在如下目錄:
2.3 配置環境變量
在/etc/profile
中添加如下環境變量:
設置好路徑後,使用如下命令使之生效:
source /etc/profile
2.4 配置文件hadoop-env.sh
修改/usr/hadoop/hadoop-2.7.7/etc/hadoop/hadoop-env.sh
文件,在export JAVA_HOME=${JAVA_HOME}
行前面插入如下內容:
export JAVA_HOME=/usr/java/jdk/jdk-14.0.1
export HADOOP_CONF_DIR=/usr/hadoop/hadoop-2.7.7/etc/hadoop
3. 配置僞分佈式
在/usr/hadoop/hadoop-2.7.7
目錄下新建一個temp的文件夾:
以下配置文件均在/usr/hadoop/hadoop-2.7.7/etc/hadoop/
目錄下。
3.1 配置 core-site.xml
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/usr/hadoop/hadoop-2.7.7/tmp</value>
<description>Abase for other temporary directories.</description>
</property>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
3.2 配置 hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/usr/hadoop/hadoop-2.7.7/tmp/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/usr/hadoop/hadoop-2.7.7/tmp/dfs/data</value>
</property>
</configuration>
關於Hadoop配置項的一點說明:
雖然只需要配置 fs.defaultFS 和 dfs.replication 就可以運行,不過若沒有配置 hadoop.tmp.dir 參數,則默認使用的臨時目錄爲 /tmp/hadoo-hadoop,而這個目錄在重啓時有可能被系統清理掉,導致必須重新執行 format 纔行。所以我們進行了設置,同時也指定 dfs.namenode.name.dir 和 dfs.datanode.data.dir,否則在接下來的步驟中可能會出錯。
3.3 配置 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>
3.4 配置mapred-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. See accompanying LICENSE file.
-->
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>localhost:9001</value>
</property>
</configuration>
3.5 執行格式化
hdfs namenode -format
完成後是這樣的界面:
3.6 啓動 hadoop
在/usr/hadoop/hadoop-2.7.2/sbin
目錄下使用如下命令:
./start-all.sh
在瀏覽器中輸入地址http://localhost:8088/
,查看Hadoop 管理介面:
在瀏覽器中輸入地址http://localhost:50070/
,查看 Hadoop DFS 狀態: