centos 6.5怎么搭建hadoop2.7.3

2025-04-04 05:14:32
推荐回答(1个)
回答1:

总体思路,准备主从服务器,配置主服务器可以无密码SSH登录从服务器,解压安装JDK,解压安装Hadoop,配置hdfs、mapreduce等主从关系。

1、环境,3台CentOS6.5,64位,Hadoop2.7.3需要64位Linux,操作系统十几分钟就可以安装完成,
Master 192.168.0.182
Slave1 192.168.0.183
Slave2 192.168.0.184

2、SSH免密码登录,因为Hadoop需要通过SSH登录到各个节点进行操作,我用的是root用户,每台服务器都生成公钥,再合并到authorized_keys
(1)CentOS默认没有启动ssh无密登录,去掉/etc/ssh/sshd_config其中2行的注释,每台服务器都要设置,
#RSAAuthentication yes
#PubkeyAuthentication yes
(2)输入命令,ssh-keygen -t rsa,生成key,都不输入密码,一直回车,/root就会生成.ssh文件夹,每台服务器都要设置,
(3)合并公钥到authorized_keys文件,在Master服务器,进入/root/.ssh目录,通过SSH命令合并,
cat id_rsa.pub>> authorized_keys
ssh root@192.168.0.183 cat ~/.ssh/id_rsa.pub>> authorized_keys
ssh root@192.168.0.184 cat ~/.ssh/id_rsa.pub>> authorized_keys
(4)把Master服务器的authorized_keys、known_hosts复制到Slave服务器的/root/.ssh目录
(5)完成,ssh root@192.168.0.183、ssh root@192.168.0.184就不需要输入密码了

3、安装JDK,Hadoop2.7需要JDK7,由于我的CentOS是最小化安装,所以没有OpenJDK,直接解压下载的JDK并配置变量即可
(1)下载“jdk-7u79-linux-x64.gz”,放到/home/java目录下
(2)解压,输入命令,tar -zxvf jdk-7u79-linux-x64.gz
(3)编辑/etc/profile
export JAVA_HOME=/home/java/jdk1.7.0_79
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,完成

4、安装Hadoop2.7,只在Master服务器解压,再复制到Slave服务器
(1)下载“hadoop-2.7.0.tar.gz”,放到/home/hadoop目录下
(2)解压,输入命令,tar -xzvf hadoop-2.7.0.tar.gz
(3)在/home/hadoop目录下创建数据存放的文件夹,tmp、hdfs、hdfs/data、hdfs/name

5、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目录下的core-site.xml


fs.defaultFS
hdfs://192.168.0.182:9000


hadoop.tmp.dir
file:/home/hadoop/tmp


io.file.buffer.size
131702



6、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目录下的hdfs-site.xml


dfs.namenode.name.dir
file:/home/hadoop/dfs/name


dfs.datanode.data.dir
file:/home/hadoop/dfs/data


dfs.replication
2


dfs.namenode.secondary.http-address
192.168.0.182:9001


dfs.webhdfs.enabled
true



7、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目录下的mapred-site.xml


mapreduce.framework.name
yarn


mapreduce.jobhistory.address
192.168.0.182:10020


mapreduce.jobhistory.webapp.address
192.168.0.182:19888



8、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目录下的mapred-site.xml


yarn.nodemanager.aux-services
mapreduce_shuffle


yarn.nodemanager.auxservices.mapreduce.shuffle.class
org.apache.hadoop.mapred.ShuffleHandler


yarn.resourcemanager.address
192.168.0.182:8032


yarn.resourcemanager.scheduler.address
192.168.0.182:8030


yarn.resourcemanager.resource-tracker.address
192.168.0.182:8031


yarn.resourcemanager.admin.address
192.168.0.182:8033


yarn.resourcemanager.webapp.address
192.168.0.182:8088


yarn.nodemanager.resource.memory-mb
768



9、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目录下hadoop-env.sh、yarn-env.sh的JAVA_HOME,不设置的话,启动不了,
export JAVA_HOME=/home/java/jdk1.7.0_79

10、配置/home/hadoop/hadoop-2.7.0/etc/hadoop目录下的slaves,删除默认的localhost,增加2个从节点,
192.168.0.183
192.168.0.184

11、将配置好的Hadoop复制到各个节点对应位置上,通过scp传送,
scp -r /home/hadoop 192.168.0.183:/home/
scp -r /home/hadoop 192.168.0.184:/home/

12、在Master服务器启动hadoop,从节点会自动启动,进入/home/hadoop/hadoop-2.7.0目录
(1)初始化,输入命令,bin/hdfs namenode -format
注意:执行这步的时候可能会报一个错误:
java.net.UnknownHostException: tiancunPC: tiancunPC: unknown error
at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
at org.apache.hadoop.net.DNS.resolveLocalHostname(DNS.java:264)
at org.apache.hadoop.net.DNS.(DNS.java:57)
at org.apache.hadoop.hdfs.server.namenode.NNStorage.newBlockPoolID(NNStorage.java:982)
at org.apache.hadoop.hdfs.server.namenode.NNStorage.newNamespaceInfo(NNStorage.java:591)
at org.apache.hadoop.hdfs.server.namenode.FSImage.format(FSImage.java:157)
at org.apache.hadoop.hdfs.server.namenode.NameNode.format(NameNode.java:992)
at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1434)
at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1559)
Caused by: java.net.UnknownHostException: tiancunPC: unknown error
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
... 8 more
16/11/11 19:15:23 WARN net.DNS: Unable to determine address of the host-falling back to "localhost" address
java.net.UnknownHostException: tiancunPC: tiancunPC: unknown error
at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
at org.apache.hadoop.net.DNS.resolveLocalHostIPAddress(DNS.java:287)
at org.apache.hadoop.net.DNS.(DNS.java:58)
at org.apache.hadoop.hdfs.server.namenode.NNStorage.newBlockPoolID(NNStorage.java:982)
at org.apache.hadoop.hdfs.server.namenode.NNStorage.newNamespaceInfo(NNStorage.java:591)
at org.apache.hadoop.hdfs.server.namenode.FSImage.format(FSImage.java:157)
at org.apache.hadoop.hdfs.server.namenode.NameNode.format(NameNode.java:992)
at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1434)
at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1559)
Caused by: java.net.UnknownHostException: tiancunPC: unknown error
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
... 8 more
linux中使用hostname查看为:
[root@tiancunPC hadoop-2.7.3]# hostname
tiancunPC
查看/etc/hosts为:
[root@tiancunPC hadoop-2.7.3]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
难怪会映射不到,修改/etc/hosts
[root@tiancunPC hadoop-2.7.3]# cat /etc/hosts
127.0.0.1 tiancunPC localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
对应修改另外两个机器的主机名,在执行那个命令就可以了

(2)全部启动sbin/start-all.sh,也可以分开sbin/start-dfs.sh、sbin/start-yarn.sh
执行sbin/start-all.sh 可能会有错误提示:
maps to localhost(IP), but this does not map back to the address
解决办法:

修改 /etc/ssh/ssh_config
vim /etc/ssh/ssh_config
GSSAPIAuthentication no
这个时候可能还会出现这个错误提示:

hadoop出现namenode running as process 18472. Stop it first.,hadoopnamenode
解决办法:重新启动一下hadoop

(3)停止的话,输入命令,sbin/stop-all.sh
(4)输入命令,jps,可以看到相关信息