本帖最后由 PeersLee 于 2016-4-16 11:01 编辑
问题导读:
1.搭建hadoop 2.x 的需要做哪些准备?
2.如何进行hadoop 2.x 的集群搭建?
3.如何解决搭建时出现的问题?
解决方案:
环境:centos6.5(x64) + jdk 8 + hadoop2.4.1
准备:
# 3台机器(一主二从)
192.168.191.60 master
192.168.191.61 slave01
192.168.191.62 slave02
# 1.准备linxu环境
1.1 修改主机名
# 这样做的目的是让主机名和IP关联(在搭建时这个步骤忘记了,结果datanode没起来)
[mw_shl_code=applescript,true] master:
[root@localhost ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=master
slave01:
HOSTNAME=slave01
slave02:
HOSTNAME=slave02[/mw_shl_code]
1.2 配置ip
[mw_shl_code=applescript,true]master:
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:30:B0:66
TYPE=Ethernet
UUID=e00c9bc7-e8cb-4cdb-a5e7-baae4765b9b3
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.191.60
NETMASK=255.255.255.0
GATEWAY=192.168.191.1
DNS1=192.168.191.1
slave01:
IPADDR=192.168.191.61
slave02:
IPADDR=192.168.191.62
[/mw_shl_code] 1.3 修改hosts(主机和ip的映射关系)
[mw_shl_code=applescript,true][root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.191.60 master
192.168.191.61 slave01
192.168.191.62 slave02[/mw_shl_code]
三台机器一样的操作
1.4 关闭防火墙
[mw_shl_code=applescript,true] #查看防火墙状态
service iptables status
#关闭防火墙
service iptables stop
#查看防火墙开机启动状态
chkconfig iptables --list
#关闭防火墙开机启动
chkconfig iptables off[/mw_shl_code]
[mw_shl_code=applescript,true]master:
[root@localhost ~]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
[root@localhost ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@localhost ~]# service iptables status
iptables: Firewall is not running.
You have mail in /var/spool/mail/root
[root@localhost ~]# chkconfig iptables --list
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost ~]# chkconfig iptables off
You have mail in /var/spool/mail/root
[root@localhost ~]# chkconfig iptables --list
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[/mw_shl_code] 1.5 重启linux
[mw_shl_code=applescript,true] reboot [/mw_shl_code]
# 2.配置ssh 免登陆
2.1 安装ssh
[mw_shl_code=applescript,true] yum install openssh-server
yum install openssh-clients[/mw_shl_code]
2.2 生成ssh 秘钥
[mw_shl_code=applescript,true] ssh-keygen -t rsa
【4个回车】[/mw_shl_code]
2.3 将所有机子的公钥 cat 到master的 ~/.ssh/authorized_keys 中
(1)在master ~/.ssh/下创建 authorized_keys,并修改权限为 600
[mw_shl_code=applescript,true][root@master .ssh]# touch authorized_keys
[root@master .ssh]# chmod 600 authorized_keys
[root@master .ssh]# cat id_rsa.pub >> authorized_keys [/mw_shl_code] (2)分别将其他机子中的公钥scp 到master中(注意名字,因为会覆盖)
[mw_shl_code=applescript,true] scp ~/.ssh/id_rsa.pub root@master:/root/.ssh/slave01_id_rsa.pub
scp ~/.ssh/id_rsa.pub root@master:/root/.ssh/slave02_id_rsa.pub[/mw_shl_code]
(3)将这两个公钥cat 到 authorized_keys 中
[mw_shl_code=applescript,true] [root@master .ssh]# cat slave01_id_rsa.pub >> authorized_keys
[root@master .ssh]# cat slave02_id_rsa.pub >> authorized_keys [/mw_shl_code]
(4)将master 上的 authorized_keys scp 到 slaves 中
[mw_shl_code=applescript,true] scp authorized_keys root@slave01:/root/.ssh/
scp authorized_keys root@slave02:/root/.ssh/[/mw_shl_code]
(5)测试
[mw_shl_code=applescript,true]ssh slave01
exit
...
...[/mw_shl_code]
# 3.安装jdk(master)
3.1 下载jdk
[mw_shl_code=applescript,true] # 安装wget
yum install wget
# 下载jdk x64(注意版本)
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-p ... 73-linux-x64.tar.gz
[/mw_shl_code]
3.2 解压jdk
3.2.1 创建文件夹
[mw_shl_code=applescript,true] mkdir ~/app/[/mw_shl_code]
3.2.2 解压
[mw_shl_code=applescript,true] tar -zxvf jdk-8u73-linux-x64.tar.gz -C ~/app/[/mw_shl_code]
3.3 将java添加到环境变量
[mw_shl_code=applescript,true]vim /etc/profile
# 在文件最后添加
export JAVA_HOME=/root/app/jdk1.8.0_73
export PATH=$PATH:$JAVA_HOME/bin
#刷新配置
source /etc/profile
# 检查
java
javac
java -version
#最后一起scp 到其他机器上[/mw_shl_code]
搭建集群:
# 4.在master上安装hadoop2.4.1
4.1 解压hadoop2.4.1(http://mirror.bit.edu.cn/apache/hadoop/common/)
[mw_shl_code=applescript,true] tar -xvzf hadoop-2.4.1.tar.gz -C ~/app/[/mw_shl_code]
4.2 配置文件(~/app/hadoop-2.4.1/etc/hadoop/)
4.2.1
[mw_shl_code=applescript,true] vim hadoop-env.sh
# 这个文件要修改的地方就是JAVA_HOME环境变量
export JAVA_HOME=/root/app/jdk1.8.0_73[/mw_shl_code]
4.2.2
[mw_shl_code=applescript,true]vim yarn-env.sh
# yarn的环境配置,同样只需要修改JAVA_HOME就行
在这一行“ # some Java parameters ” 下面添加
export JAVA_HOME=/root/app/jdk1.8.0_73[/mw_shl_code] 4.2.3
[mw_shl_code=applescript,true]vim slaves
# 这是设置从节点hostname的地方,一行一个,我们的例子里只要在文件里写上如下两行就行了
slave01
slave02[/mw_shl_code]
4.2.4
[mw_shl_code=applescript,true]mkdir ~/app/hadoop-2.4.1/tmp
vim core-site.xml
#fs.default.name配置了hadoop的HDFS系统的命名,位置为主机的9000端口;
#hadoop.tmp.dir配置了hadoop的tmp目录的根位置。
#这里使用了一个文件系统中没有的位置,所以要先用mkdir命令新建一下。
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/root/app/hadoop-2.4.1/tmp</value>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://master:9000</value>
</property>
</configuration>[/mw_shl_code]
4.2.5
[mw_shl_code=applescript,true]vim hdfs-site.xml
#这个是hdfs的配置文件,dfs.http.address配置了hdfs的http的访问位置;
#dfs.replication配置了文件块的副本数,一般不大于从机的个数。
<configuration>
<property>
<name>dfs.http.address</name>
<value>master:50070</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>master:50090</value>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>[/mw_shl_code]
4.2.6
[mw_shl_code=applescript,true]mv mapred-site.xml.template mapred-site.xml
vim mapred-site.xml
#在mapreduce.framework.name属性下配置为yarn。
# mapred.map.tasks和mapred.reduce.tasks分别为map和reduce的任务数
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>master:9001</value>
</property>
<property>
<name>mapred.map.tasks</name>
<value>20</value>
</property>
<property>
<name>mapred.reduce.tasks</name>
<value>4</value>
</property>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>master:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>master:19888</value>
</property>
</configuration>
[/mw_shl_code]
4.2.7
[mw_shl_code=applescript,true]vim yarn-site.xml
#该文件为yarn框架的配置,主要是一些任务的启动位置
<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>yarn.resourcemanager.address</name>
<value>master:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>master:8030</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>master:8088</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>master:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>master:8033</value>
</property>
<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>
</configuration>
[/mw_shl_code]
4.2.8
[mw_shl_code=applescript,true]将hadoop添加到环境变量
vim /etc/profile
# java
export JAVA_HOME=/root/app/jdk1.8.0_73
export CLASSPATH=.:$JAVA_HOME/lib.tools.jar
# hadoop2.4.1
export HADOOP_HOME=/root/app/hadoop-2.4.1
# path
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin[/mw_shl_code]
# 5.在slave进行hadoop 安装
[mw_shl_code=applescript,true] scp -r ~/app/ root@slave01:/root/
scp -r ~/app/ root@slave02:/root/
scp /etc/profile root@slave01:/etc/profile
scp /etc/profile root@slave02:/etc/profile[/mw_shl_code]
# 6.初始化、测试
6.1 格式化namenode
[mw_shl_code=applescript,true] hdfs namenode -format (hadoop namenode -format)
#在倒数的某行出现这个就是完成了
16/04/13 04:48:52 INFO common.Storage: Storage directory /root/app/hadoop-2.4.1/tmp/dfs/name has been successfully formatted.
[/mw_shl_code]
6.2 启动hadoop
6.2.1
启动HDFS
[mw_shl_code=applescript,true] start-dfs.sh[/mw_shl_code]
6.2.2
再启动YARN
[mw_shl_code=applescript,true]start-yarn.sh[/mw_shl_code]
6.2.3
[mw_shl_code=applescript,true][root@master ~]# jps
16768 Jps
16465 ResourceManager
16259 SecondaryNameNode
16127 NameNode
[root@slave01 ~]# jps
1379 Jps
1156 DataNode
1270 NodeManage
[root@slave02 ~]# jps
1377 Jps
1153 DataNode
1267 NodeManager[/mw_shl_code]
6.3 64位的CentOS,在启动时候会出现一个warning
WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
这个问题搜索一下能找到解决办法,主要就是因为下载的bin是32位机器上编译的,所以本地库不好用,需要拿源码在本机重新编译一下。
不过据说不影响使用,暂时就不管它了。
出现的问题以及解决方案:
# 7.出现的问题以及解决方法
7.1 问题描述:
在搭建完成测试的时候,slave01 和 slave02 上的DataNode 和 NodeManager 起来不。
7.2 解决方法:
(1)查看logs:
[mw_shl_code=applescript,true]2016-04-13 05:08:48,990 FATAL org.apache.hadoop.hdfs.server.datanode.DataNode: Exception in secureMain
java.net.UnknownHostException: hadoop241-slave01: hadoop241-slave01: unknown error
at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
at org.apache.hadoop.security.SecurityUtil.getLocalHostName(SecurityUtil.java:186)
at org.apache.hadoop.security.SecurityUtil.login(SecurityUtil.java:206)
at org.apache.hadoop.hdfs.server.datanode.DataNode.instantiateDataNode(DataNode.java:1816)
at org.apache.hadoop.hdfs.server.datanode.DataNode.createDataNode(DataNode.java:1865)
at org.apache.hadoop.hdfs.server.datanode.DataNode.secureMain(DataNode.java:2041)
at org.apache.hadoop.hdfs.server.datanode.DataNode.main(DataNode.java:2065)
Caused by: java.net.UnknownHostException: hadoop241-slave01: 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)
... 6 more
2016-04-13 05:08:49,029 INFO org.apache.hadoop.util.ExitUtil: Exiting with status 1
2016-04-13 05:08:49,041 INFO org.apache.hadoop.hdfs.server.datanode.DataNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down DataNode at java.net.UnknownHostException: hadoop241-slave01: hadoop241-slave01: unknown error
[/mw_shl_code]
(2)解决:
是主机名和ip 关联问题,看一下主机名和ip 是否映射,
hadoop241-slave01 - slave01
hadoop241-slave02 - slave02
没有映射上,
所以,先将两个主机名改成,
slave01
slave02
然后删除3个节点hadoop2.4.1/ 下的,
tmp
logs
文件夹下的所有东西,
然后重新hdfs namenode -format
问题解决。
|
|