配置java环境
下载JDK
下载地址:jdk下载地址
解压安装命令:tar -zxvf jdk-8u211-linux-x64.tar.gz
配置JDK
在usr/lib目录下创建一个jdk文件夹,将解压出来文件夹移进去
cd /usr/lib
mkdir jdk
mv jdk-8u211-linux-x64 /usr/lib/jdk
配置环境变量vim /etc/profile打开后在末尾加上
#set java env
export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_211
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
执行立即生效source /etc/profile
检查是否配置成功
root@iZwz9d1cy0175pjnvgalocZ:~# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
root@iZwz9d1cy0175pjnvgalocZ:~#
安装ssh-server实现免密码登陆
下载ssh-server
sudo apt-get install openssh-server
启动ssh
sudo /etc/init.d/ssh start
查看ssh服务是否启动
ps -ef|grep ssh
设置免密码登陆
安装SSH
$ yum install openssh-server
使用以下命令,狂按回车,生产rsa(所有需要输入的地方都按下回车!)
ssh-keygen -t rsa
出现下面的情况就表明成功
The key's randomart image is:
+---[RSA 2048]----+
| .... +o.|
| . .. o o.|
| . oo.. .. |
| . . o+ . .|
| .S. .=. . |
| .o+.=. .|
| .o.E+oo+.|
| +o* =. +B|
| o+*o+ o++*|
+----[SHA256]-----+
接下来将密钥写入ssh中
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
/etc/init.d/ssh reload
再次启动hadoop就没有密码输入的要求了。
关闭防火墙
ufw disable
安装Hadoop伪分布式模式
下载hadoop
下载地址:hadoop下载地址
将文件解压:
sudo tar zxvf hadoop-2.7.4.tar.gz -C /usr/local
在usr/local/目录下,将文件hadoop-2.7.4重命名为hadoop,并且给/usr/local/hadoop设置访问权限
cd /usr/local
sudo mv hadoop-2.7.4 hadoop
sudo chmod 777 -R /usr/local/Hadoop
配置.bashc文件
进入.bshrc 文件
sudo vim ~/.bashrc
在文件的末尾加上以下内容(注意jdk的路径):
#HADOOP VARIABLES START
export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_211
export HADOOP_INSTALL=/usr/local/hadoop
export PATH=$PATH:$HADOOP_INSTALL/bin
export PATH=$PATH:$HADOOP_INSTALL/sbin
export HADOOP_MAPRED_HOME=$HADOOP_INSTALL
export HADOOP_COMMON_HOME=$HADOOP_INSTALL
export HADOOP_HDFS_HOME=$HADOOP_INSTALL
export YARN_HOME=$HADOOP_INSTALL
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_INSTALL/lib"
#HADOOP VARIABLES END
执行以下命令,使添加的环境变量生效
source ~/.bashrc
Hadoop伪分布式搭建
配置hadoop—env.sh:
sudo vim /usr/local/hadoop/etc/hadoop/hadoop-env.sh
在末尾添加以下内容(注意jdk的路径):
# The java implementation to use.
export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_211
export HADOOP=/usr/local/hadoop
export PATH=$PATH:/usr/local/hadoop/bin
配置yarn-env.sh:
sudo vim /usr/local/hadoop/etc/hadoop/yarn-env.sh
在末尾添加以下内容(注意jdk路径):
# export JAVA_HOME=/usr/java/jdk1.8.0_144
JAVA_HOME=/usr/lib/jdk/jdk1.8.0_211
配置core-site.xml:
sudo vim /usr/local/hadoop/etc/hadoop/core-site.xml
在末尾插上以下内容(注意删除原有的configuration> < /configuration >):
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/usr/local/hadoop/tmp</value>
<description>Abase for other temporary directories.</description>
</property>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
配置hdfs-site.xml文件:
sudo vim /usr/local/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:/usr/local/hadoop/tmp/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/usr/local/hadoop/tmp/dfs/data</value>
</property>
</configuration>
配置yarn-site.xml文件:
sudo vim /usr/local/hadoop/etc/hadoop/yarn-site.xml
插入以下内容:
<configuration>
<!-- Site specific YARN configuration properties -->
<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>
<property>
<name>yarn.resourcemanager.address</name>
<value>127.0.0.1:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>127.0.0.1:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>127.0.0.1:8031</value>
</property>
</configuration>
关机重启虚拟机。
验证Hadoop是否已经配置完成
hadoop version