操作系统:centos7.2
hadoop2.7.6
jdk1.8_144
首先将下载的压缩包解压到对应的目录,使用命令:
tar -zxvf [文件名] -C [解压位置]
1.配置java环境变量
gedit /etc/profile
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_144
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
source /etc/profile
1.配置hadoop环境变量
gedit /etc/profile
export HADOOP_HOME=/opt/hadoop-2.7.6
export PATH=$PATH:$HADOOP_HOME/bin
source /etc/profile
2.修改配置文件,注意:所有配置中的路径和主机名根据自己实际情况更改
一、
gedit /opt/hadoop-2.7.6/etc/hadoop/slaves
清空文件,加入节点,这里以两个举例,如果想让master也作为DataNode节点,可以加进去
slave1
slave2
二、
gedit /opt/hadoop-2.7.6/etc/hadoop/hadoop-env.sh
# The java implementation to use
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_144
三、
gedit /opt/hadoop-2.7.6/etc/hadoop/core-site.xml
<configuration>
<property>
<name>hadoop.tmp.dirname>
<value>file:///opt/hadoop-2.7.6value>
<description>Abase for other temporary directories.description>
property>
<property>
<name>fs.defaultFSname>
<value>hdfs://master:8888value>
property>
configuration>
四、
gedit /opt/hadoop-2.7.6/etc/hadoop/hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.secondary.http-addressname>
<value>master:50090value>
property>
<property>
<name>dfs.replicationname>
<value>2value>
property>
<property>
<name>dfs.namenode.name.dirname>
<value>file:///opt/hadoop-2.7.6/tmp/dfs/namevalue>
property>
<property>
<name>dfs.datanode.data.dirname>
<value>file:///opt/hadoop-2.7.6/tmp/dfs/datavalue>
property>
configuration>
五、
gedit /opt/hadoop-2.7.6/etc/hadoop/yarn-site.xml
<configuration>
<property>
<name>yarn.resourcemanager.hostnamename>
<value>mastervalue>
property>
<property>
<name>yarn.nodemanager.aux-servicesname>
<value>mapreduce_shufflevalue>
property>
configuration>
六、
cd /opt/hadoop-2.7.6/etc/hadoop/
cp mapred-site.xml.template mapred-site.xml
gedit mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.namename>
<value>yarnvalue>
property>
configuration>
gedit /etc/hosts
192.168.164.139 master
192.168.164.142 slave1
192.168.164.143 slave2
systemctl status firewalld.service
systemctl stop firewalld.service
systemctl disable firewalld.service
由于前面的配置在每个机器上都是一样的,所以先配好一台,然后克隆虚拟机。如果提前已经安装好了虚拟机,可以通过发送的方式将文件复制到其他机器上。
1.在每台机器上执行如下命令,并且一直回车即可
ssh-keygen -t rsa
一、在master上
cd ~/.ssh
cat id_rsa.pub>>authorized_keys
scp -r authorized_keys root@slave1:~/.ssh
二、在slave1上
cd ~/.ssh
cat id_rsa.pub>>authorized_keys
scp -r authorized_keys root@slave2:~/.ssh
三、在slave2上
cd ~/.ssh
cat id_rsa.pub>>authorized_keys
scp -r authorized_keys root@master:~/.ssh
scp -r authorized_keys root@slave1:~/.ssh
总的目的就是将所有机器上的公钥导入认证文件authorized_keys中,然后再拷贝到各个机器上。完成之后在每台机器上进行验证:
ssh master
ssh slave1
ssh slave2
如果不能免密登陆,可能是文件权限不对,尝试如下命令:
chmod 710 authorized_keys
cd /opt/hadoop-2.7.6
./bin/hdfs namenode -format
./sbin/start-dfs.sh
浏览器输入地址验证:http://192.168.164.139:50070
./sbin/stop-dfs.sh