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 hadoop@hadoop1。必定要設置免密登陸,我的理解和各個機器之間互信同樣的道理。java
[hadoop@hadoop1 ~]$ ssh-keygen -t rsa # 三次回車 [hadoop@hadoop1 ~]$ ssh-copy-id hadoop@hadoop1 # 輸入密碼
[root@hadoop1 ~]# vim /etc/hosts
在第一行添加: 本機IP hadoop1 的映射,以下:node
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
添加以下內容:python
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>
如圖所示:
linux
[hadoop@hadoop1 hadoop]$ vim hdfs-site.xml
添加以下配置:git
<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>
如圖所示:
web
[hadoop@hadoop1 hadoop]$ cp mapred-site.xml.template mapred-site.xml [hadoop@hadoop1 hadoop]$ vim mapred-site.xml
添加以下配置:apache
<property> <name>mapreduce.framework.name</name> <value>yarn</value> </property>
[hadoop@hadoop1 hadoop]$ vim yarn-site.xml
添加以下配置:vim
<property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> <description>YARN 集羣爲 MapReduce 程序提供的 shuffle 服務</description> </property>
如圖所示:
centos
[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