1、环境准备
两台linux服务器:
10.88.248.138 prodjiance Master主节点
10.88.248.92 prodjiancedsb 从节点
2、免密码登录配置
hadoop需要通过SSH登录到各个节点进行操作,
每台服务器都生成公钥,再合并到authorized_keys,我这里用的是root用户
(1)linux默认没有启动ssh无密登录,去掉/etc/ssh/sshd_config其中2行的注释,每台服务器都要设置,
#RSAAuthentication yes
#PubkeyAuthentication yes
#RSAAuthentication yes
#PubkeyAuthentication yes
(2)输入命令,ssh-keygen -t rsa,生成key,都不输入密码,一直回车,/root就会生成.ssh文件夹,每台服务器都要设置,
(3)
在Master服务器上把主节点和从节点的所有公钥
合并到authorized_keys文件,在Master服务器,进入/root/.ssh目录,通过SSH命令合并,
cat id_rsa.pub>> authorized_keys
ssh root@10.88.248.92
cat ~/.ssh/id_rsa.pub>> authorized_keys
(4)把Master服务器的authorized_keys、known_hosts复制到Slave服务器的/root/.ssh目录
scp authorized_keys root@10.88.248.92:~/.ssh/
(5)完成后,通过ssh root@10.88.248.92测试,如果能够不需要密码切换到从节点就成功了
3、设置hostname ip地址和机器名字的映射
hadoop中主从节点是通过机器名字设置的,所以需要在hosts中进行设置
vi /etc/hosts
添加:
10.88.248.138 prodjiance
10.88.248.92 prodjiancedsb
4、安装JDK
注意Hadoop2.7需要的JDK最低版本是7,直接解压下载的JDK并配置变量即可
(1)下载“jdk-8u101-linux-x64.tar.gz”,放到/usr/java目录下
(2)解压,输入命令,tar -zxvf jdk-8u101-linux-x64.tar.gz
(3)编辑/etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_101
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME=/usr/java/jdk1.8.0_101
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
(4)使配置生效,输入命令,source /etc/profile
(5)输入命令:java -version,检测是否成功
5、安装Hadoop2.7.2
只在Master服务器解压,再复制到Slave服务器
(1)下载“hadoop-2.7.2.tar.gz”,放到/usr/hadoop目录下
(2)解压,输入命令,tar -xzvf hadoop-2.7.2.tar.gz
(3)在/opt/hadoop目录下创建数据存放的文件夹,tmp、hdfs、hdfs/data、hdfs/name
6、配置/opt/hadoop/hadoop-2.7.0/etc/hadoop目录下的core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://10.88.248.138:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/home/hadoop/tmp</value>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131702</value>
</property>
</configuration>
7、配置/opt/hadoop/hadoop-2.7.0/etc/hadoop目录下的hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/home/hadoop/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/home/hadoop/dfs/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>10.88.248.138:9001</value>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
</configuration>
8、配置/opt/hadoop/hadoop-2.7.0/etc/hadoop目录下的mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>10.88.248.138:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>10.88.248.138:19888</value>
</property>
</configuration>
9、配置/opt/hadoop/hadoop-2.7.0/etc/hadoop目录下的yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>10.88.248.138:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>10.88.248.138:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>10.88.248.138:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>10.88.248.138:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>10.88.248.138:8088</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>768</value>
</property>
<!-- Site specific YARN configuration properties -->
</configuration>
10、配置/opt/hadoop/hadoop-2.7.2/etc/hadoop目录下hadoop-env.sh、yarn-env.sh的JAVA_HOME
export JAVA_HOME=/usr/java/jdk1.8.0_101
11、配置/opt/hadoop/hadoop-2.7.2/etc/hadoop目录下的slaves,删除默认的localhost,增加从节点
10.88.248.92
12、将配置好的Hadoop复制到各个节点对应位置上,通过scp传送
scp -r /opt/hadoop 10.88.248.92:/opt/
13、在Master服务器启动hadoop,从节点会自动启动,进入/opt/hadoop/hadoop-2.7.2目录
(1)初始化,输入命令,bin/hdfs namenode -format
(2)全部启动sbin/start-all.sh,也可以分开sbin/start-dfs.sh、sbin/start-yarn.sh
(3)停止的话,输入命令,sbin/stop-all.sh
(4)输入命令,jps,可以看到相关信息
(2)全部启动sbin/start-all.sh,也可以分开sbin/start-dfs.sh、sbin/start-yarn.sh
(3)停止的话,输入命令,sbin/stop-all.sh
(4)输入命令,jps,可以看到相关信息
14、Web访问,要先开放端口或者直接关闭防火墙
(1)输入命令,systemctl stop firewalld.service
(2)浏览器打开http://10.88.248.138:8088/
(3)浏览器打开http://10.88.248.138:50070/
页面正常打开,安装成功!