频道栏目
首页 > 资讯 > 其他综合 > 正文

因服务器时间不一致导致的MapRecude 任务运行失败

17-08-10        来源:[db:作者]  
收藏   我要投稿

在一个测试环境下使用3个节点部署完成了Hadoop HA集群,集群启动都OK,但是当写了一个wordCounta测试打包后在集群上开始运行时,报了一个错误:

[root@node2 hadoop_jar]# /opt/package/hadoop-2.7.2/bin/hadoop jar wordcount.jar   /hello.txt   /output1
Container launch failed for container_1502174444721_0002_01_000002 : org.apache.hadoop.yarn.exceptions.YarnException: Unauthorized request to start container. 
This token is expired. current time is 1502197729279 found 1502175793372
Note: System times on machines may be out of sync. Check system time and time zones.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.apache.hadoop.yarn.api.records.impl.pb.SerializedExceptionPBImpl.instantiateException(SerializedExceptionPBImpl.java:168)
	at org.apache.hadoop.yarn.api.records.impl.pb.SerializedExceptionPBImpl.deSerialize(SerializedExceptionPBImpl.java:106)
	at org.apache.hadoop.mapreduce.v2.app.launcher.ContainerLauncherImpl$Container.launch(ContainerLauncherImpl.java:155)
	at org.apache.hadoop.mapreduce.v2.app.launcher.ContainerLauncherImpl$EventProcessor.run(ContainerLauncherImpl.java:375)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)

里面有一个很明显的提示:

Note: System times on machines may be out of sync. Check system time and time zones.

提示服务器系统时间不同步,立即查看集群里各个节点的时间,果然发现各个节点的时间都不一致,甚至分钟数都不同,太严重了,要立即同步时间!!!

其实可以使用utpdate做时间同步,在国内的话,当然要找国家的授时中心了,所以先要找到授时中心的IP

然后再找到[亚洲]打开之后是这样

看到红色地方了吧,找到中国,打开后是这样

我们使用上面的域名 cn.pool.ntp.org 然后在本机ping这个域名,就会得到具体的IP

root@node2> ping cn.pool.ntp.org
PING cn.pool.ntp.org (85.199.214.100) 56(84) bytes of data.
^C64 bytes from 85.199.214.100: icmp_seq=5 ttl=26 time=427 ms
64 bytes from 85.199.214.100: icmp_seq=6 ttl=26 time=427 ms
64 bytes from 85.199.214.100: icmp_seq=7 ttl=26 time=417 ms
64 bytes from 85.199.214.100: icmp_seq=8 ttl=26 time=423 ms
[1]+  Stopped                 ping cn.pool.ntp.org

然后使用ntpdate 来做时间同步:

[root@node2 hadoop_jar]# ntpdate -u 85.199.214.100
-bash: ntpdate: command not found

系统不认识这个命令,原来是ntpdate木有安装,根据下面方式安装

[root@node2 hadoop_jar]# yum -y install ntp.x86_64
Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirrors.btte.net
base                                                                                                                                            | 3.7 kB     00:00     
base/primary_db                                                                                                                                 | 4.7 MB     00:03     
extras                                                                                                                                          | 3.4 kB     00:00     
extras/primary_db                                                                                                                               |  29 kB     00:00     
updates                                                                                                                                         | 3.4 kB     00:00     
updates/primary_db                                                                                                                              | 2.5 MB     00:01     
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-10.el6.centos.2 will be installed
--> Processing Dependency: ntpdate = 4.2.6p5-10.el6.centos.2 for package: ntp-4.2.6p5-10.el6.centos.2.x86_64
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.6p5-10.el6.centos.2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
 Package                              Arch                                Version                                              Repository                         Size
=======================================================================================================================================================================
Installing:
 ntp                                  x86_64                              4.2.6p5-10.el6.centos.2                              base                              599 k
Installing for dependencies:
 ntpdate                              x86_64                              4.2.6p5-10.el6.centos.2                              base                               78 k

Transaction Summary
=======================================================================================================================================================================
Install       2 Package(s)

Total download size: 678 k
Installed size: 1.8 M
Downloading Packages:
(1/2): ntp-4.2.6p5-10.el6.centos.2.x86_64.rpm                                                                                                   | 599 kB     00:00     
(2/2): ntpdate-4.2.6p5-10.el6.centos.2.x86_64.rpm                                                                                               |  78 kB     00:00     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                  2.5 MB/s | 678 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : ntpdate-4.2.6p5-10.el6.centos.2.x86_64                                                                                                              1/2 
  Installing : ntp-4.2.6p5-10.el6.centos.2.x86_64                                                                                                                  2/2 
  Verifying  : ntp-4.2.6p5-10.el6.centos.2.x86_64                                                                                                                  1/2 
  Verifying  : ntpdate-4.2.6p5-10.el6.centos.2.x86_64                                                                                                              2/2 

Installed:
  ntp.x86_64 0:4.2.6p5-10.el6.centos.2                       

Dependency Installed:
  ntpdate.x86_64 0:4.2.6p5-10.el6.centos.2                          

Complete!
[root@node2 hadoop_jar]# 

这种方式安装要求服务器可以访问网络,也可以使用rpm包来安装

然后开始同步时间

root@node2> ntpdate -u 85.199.214.100
 8 Aug 15:08:06 ntpdate[1714]: step time server 85.199.214.100 offset 3084.905892 sec
root@node3> date
Tue Aug  8 15:08:12 CST 2017
root@node2> 
OK,提示已经从85.199.214.100同步好时间,时间偏差达到了3084.90.5892秒!!


所有的节点都用同样的方式做时间同步,然后再运行 MapRecude 应用就可以正常了。

注意,cn.pool.ntp.org这个域名的IP会经常发生变化,因此可以在执行ntpdate命令之前先执行ping 这个域名的操作,以便得到最新的IP,否则同步时间会失败

下面给出一个同步时间失败的案例:

[root@node1 hadoop_jar]# ntpdate 210.72.145.44
 8 Aug 15:03:05 ntpdate[30125]: no server suitable for synchronization found
同步失败时会提示找不到这个server,因为cn.poll.ntp.org的IP总是在变化,所以找不到server就很正常了,多试几次必然可以同步成功。

其实时间和时区也有关系的。

Linux系统时区修改

查看当前时区 # vi /etc/sysconfig/clock

修改时区命令 # tzselect 或 # timeconfig

如果知道时区名称也可以直接使用命令如:# TZ='Asia/Shanghai'; export TZ  //改为+8中国上海时区

或 使用新的时区文件覆盖系统默认时区(测试最有效)

例 # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime //亚洲上海时区替换系统时区

同步BIOS时钟,强制将系统时间写入CMOS,使之永久生效,避免系统重启后恢复成原时间。

# clock -w
查看BIOS时间命令: # hwclock -r

最终发现,使用date命令查看当前时间和用hwclock -r查看BIOS时间会一致,这样就不用担心重启服务器导致时间重新发生错误。

相关TAG标签
上一篇:flume性能调优
下一篇:ssm导出
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站