root@localhost ~]# lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: CentOS
Description: CentOS Linux release 7.5.1804 (Core)
Release: 7.5.1804
Codename: Core
[root@localhost ~]# hostnamectl set-hostname hadoop1
[root@localhost ~]# hostnamectl
Static hostname: hadoop1
Icon name: computer-vm
Chassis: vm
Machine ID: a34d80dce9364980962f9d85ffb5e9c8
Boot ID: d624e2a84dc34619bfa2fe90e88eb058
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-862.11.6.el7.x86_64
Architecture: x86-64
[root@localhost ~]# hostnamectl --static
hadoop1
[root@hadoop1 ~]# sudo useradd -m hadoop -s /bin/bash
[root@hadoop1 ~]# sudo passwd hadoop
[root@hadoop1 ~]# ssh hadoop@hadoop1
# 输入密码登陆成功
[hadoop@hadoop1 ~]$ ssh-keygen -t rsa # 三次回车
[hadoop@hadoop1 ~]$ ssh-copy-id hadoop@hadoop1 # 输入密码
[root@hadoop1 ~]# vim /etc/hosts
在第一行添加: 本机IP hadoop1 的映射,如下:
172.16.142.129 hadoop1
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[hadoop@hadoop1 ~]$ ssh hadoop@hadoop1
Warning: Permanently added the ECDSA host key for IP address '172.16.142.129' to the list of known hosts.
Last login: Sun Jul 21 16:45:14 2019 from 172.16.142.129
[root@hadoop1 ~]# wget https://dl.cactifans.com/jdk/jdk-8u101-linux-x64.tar.gz
[root@hadoop1 ~]# tar -zxvf jdk-8u101-linux-x64.tar.gz -C /usr/local/
[root@hadoop1 ~]# vim /etc/profile
添加如下内容:
export JAVA_HOME=/usr/local/jdk1.8.0_101
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin
[root@hadoop1 ~]# source /etc/profile
[root@hadoop1 ~]# java -version
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
[hadoop@hadoop1 ~]$ wget http://apache.fayea.com/hadoop/common/hadoop-2.7.6/hadoop-2.7.6.tar.gz
[hadoop@hadoop1 ~]$ mkdir -p ~/apps
[hadoop@hadoop1 ~]$ tar -zxvf hadoop-2.7.6.tar.gz -C /home/hadoop/apps
[hadoop@hadoop1 ~]$ cd /home/hadoop/apps/hadoop-2.7.6/etc/hadoop
[hadoop@hadoop1 hadoop]$ vim hadoop-env.sh
export JAVA_HOME=/usr/local/jdk1.8.0_101
[hadoop@hadoop1 hadoop]$ vim core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop1:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/hadoop/data/hadoopdata</value>
</property>
</configuration>
如图所示:
[hadoop@hadoop1 hadoop]$ vim hdfs-site.xml
添加如下配置:
<property>
<name>dfs.namenode.name.dir</name>
<value>/home/hadoop/data/hadoopdata/name</value>
<description>为了保证元数据的安全一般配置多个不同目录</description>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/home/hadoop/data/hadoopdata/data</value>
<description>datanode 的数据存储目录</description>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
<description>HDFS 的数据块的副本存储个数, 默认是3</description>
</property>
如图所示:
[hadoop@hadoop1 hadoop]$ cp mapred-site.xml.template mapred-site.xml
[hadoop@hadoop1 hadoop]$ vim mapred-site.xml
添加如下配置:
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
[hadoop@hadoop1 hadoop]$ vim yarn-site.xml
添加如下配置:
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
<description>YARN 集群为 MapReduce 程序提供的 shuffle 服务</description>
</property>
如图所示:
[hadoop@hadoop1 hadoop]$ vim ~/.bashrc
# HADOOP_HOME
export HADOOP_HOME=/home/hadoop/apps/hadoop-2.7.6
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:
[hadoop@hadoop1 hadoop]$ source ~/.bashrc
[hadoop@hadoop1 hadoop]$ hadoop version
Hadoop 2.7.6
Subversion https://shv@git-wip-us.apache.org/repos/asf/hadoop.git -r 085099c66cf28be31604560c376fa282e69282b8
Compiled by kshvachk on 2018-04-18T01:33Z
Compiled with protoc 2.5.0
From source with checksum 71e2695531cb3360ab74598755d036
This command was run using /home/hadoop/apps/hadoop-2.7.6/share/hadoop/common/hadoop-common-2.7.6.jar
[hadoop@hadoop1 hadoop]$ mkdir -p /home/hadoop/data/hadoopdata/name
[hadoop@hadoop1 hadoop]$ mkdir -p /home/hadoop/data/hadoopdata/data
[hadoop@hadoop1 hadoop]$ hadoop namenode -format
[hadoop@hadoop1 hadoop]$ cd /home/hadoop/apps/hadoop-2.7.6
[hadoop@hadoop1 hadoop-2.7.6]$ sbin/start-dfs.sh
[hadoop@hadoop1 hadoop-2.7.6]$ sbin/start-yarn.sh
# 访问之前关闭防火墙
[root@hadoop1 ~]# systemctl stop firewalld
[root@hadoop1 ~]# wget https://downloads.lightbend.com/scala/2.12.0/scala-2.12.0.tgz
[root@hadoop1 ~]# tar -zxvf scala-2.12.0.tgz -C /usr/local/
[root@hadoop1 ~]# vim /etc/profile
# Scala env
export SCALA_HOME=/usr/local/scala-2.12.0
export PATH=$SCALA_HOME/bin:$PATH
[root@hadoop1 ~]# source /etc/profile
[root@hadoop1 ~]# scala -version
[hadoop@hadoop1 ~]$ wget http://apache.claz.org/spark/spark-2.4.3/spark-2.4.3-bin-hadoop2.7.tgz
[hadoop@hadoop1 ~]$ tar -zxvf spark-2.4.3-bin-hadoop2.7.tgz -C ~/apps/
[hadoop@hadoop1 ~]$ cd ~/apps/
[hadoop@hadoop1 apps]$ ln -s spark-2.4.3-bin-hadoop2.7 spark
[hadoop@hadoop1 apps]$ cd spark/conf
[hadoop@hadoop1 conf]$ cp spark-env.sh.template spark-env.sh
[hadoop@hadoop1 conf]$ vim spark-env.sh
export JAVA_HOME=/usr/local/jdk1.8.0_101
export SCALA_HOME=/usr/local/scala-2.12.0
export HADOOP_HOME=/home/hadoop/apps/hadoop-2.7.6
export HADOOP_CONF_DIR=/home/hadoop/apps/hadoop-2.7.6/etc/hadoop
export SPARK_MASTER_IP=hadoop1
export SPARK_MASTER_PORT=7077
[hadoop@hadoop1 conf]$ vim ~/.bashrc
#SPARK_HOME
export SPARK_HOME=/home/hadoop/apps/spark
export PATH=$PATH:$SPARK_HOME/bin
[hadoop@hadoop1 conf]$ source ~/.bashrc
[hadoop@hadoop1 conf]$ ~/apps/spark/sbin/start-all.sh