当前位置:   article > 正文

Hadoop集群时间同步

Hadoop集群时间同步

0x01 ntp安装

1.1 检查时间服务器是否安装

  1. # rpm -q ntp
  2. ntp-4.2.4p8-2.el6.x86_64 // 这表示已安装了,如果没有安装,这是空白。
  3. //如果没有安装,通过以下命令进行安装
  4. # yum install ntp

1.2 设置ntp自启动

按上面的安装方式在内网每台服务器上都安装好ntp软件包。

完成后,都需要配置ntp服务为自启动

  1. # chkconfig ntpd on
  2. # chkconfig --list ntpd
  3. ntpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

1.3 手动同步时间

在配置前,先使用ntpdate手动同步下时间,免得本机与外部时间服务器时间差距太大,让ntpd不能正常同步。

  1. # ntpdate -u 202.112.10.36
  2. 22 Dec 16:52:38 ntpdate[6400]: adjust time server 202.112.10.36 offset 0.012135 sec

0x02 ntp配置

2.1 修改配置文件ntp.cnf

  1. vim /etc/ntp.conf
  2. # For more information about this file, see the man pages
  3. # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
  4. driftfile /var/lib/ntp/drift
  5. # Permit time synchronization with our time source, but do not
  6. # permit the source to query or modify the service on this system.
  7. restrict default kod nomodify notrap nopeer noquery
  8. restrict -6 default kod nomodify notrap nopeer noquery
  9. # Permit all access over the loopback interface. This could
  10. # be tightened as well, but to do so would effect some of
  11. # the administrative functions.
  12. restrict 127.0.0.1
  13. restrict -6 ::1
  14. # Hosts on local network are less restricted.
  15. # 允许内网其他机器同步时间
  16. restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
  17. # Use public servers from the pool.ntp.org project.
  18. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  19. # 中国这边最活跃的时间服务器 : http://www.pool.ntp.org/zone/cn
  20. server 210.72.145.44 perfer # 中国国家受时中心
  21. server 202.112.10.36 # 1.cn.pool.ntp.org
  22. server 59.124.196.83 # 0.asia.pool.ntp.org
  23. #broadcast 192.168.1.255 autokey # broadcast server
  24. #broadcastclient # broadcast client
  25. #broadcast 224.0.1.1 autokey # multicast server
  26. #multicastclient 224.0.1.1 # multicast client
  27. #manycastserver 239.255.254.254 # manycast server
  28. #manycastclient 239.255.254.254 autokey # manycast client
  29. # allow update time by the upper server
  30. # 允许上层时间服务器主动修改本机时间
  31. restrict 210.72.145.44 nomodify notrap noquery
  32. restrict 202.112.10.36 nomodify notrap noquery
  33. restrict 59.124.196.83 nomodify notrap noquery
  34. # Undisciplined Local Clock. This is a fake driver intended for backup
  35. # and when no outside source of synchronized time is available.
  36. # 外部时间服务器不可用时,以本地时间作为时间服务
  37. server 127.127.1.0 # local clock
  38. fudge 127.127.1.0 stratum 10
  39. # Enable public key cryptography.
  40. #crypto
  41. includefile /etc/ntp/crypto/pw
  42. # Key file containing the keys and key identifiers used when operating
  43. # with symmetric key cryptography.
  44. keys /etc/ntp/keys
  45. # Specify the key identifiers which are trusted.
  46. #trustedkey 4 8 42
  47. # Specify the key identifier to use with the ntpdc utility.
  48. #requestkey 8
  49. # Specify the key identifier to use with the ntpq utility.
  50. #controlkey 8
  51. # Enable writing of statistics records.
  52. #statistics clockstats cryptostats loopstats peerstats

配置文件修改完成,保存退出。

启动服务:

# service ntpd start

0x03 在其它节点上与master节点时间同步

# ntpdate master

这时候发现节点间的时间同步了,但ntpdate只在开机运行,我们若要设置为1小时同步一次
安装完以后使用crontab来自动更新时间:

# crontab -e

添加如下行:

* */1 * * * /usr/sbin/ntpdate 192.168.64.11

使用date命令发现所有节点时间已经一致。

0x04 同步过程中的问题

4.1 the NTP socket is in use

Linux下 ntp 时间同步服务ntpd 出现 the NTP socket is in use, exiting 解决

  1. # service ntpd stop
  2. Shutting down ntpd: [ OK ]
  3. # ntpdate master
  4. 6 Sep 09:37:19 ntpdate[30658]: step time server 192.168.1.10 offset -51.869609 sec

2017年1月23日, 星期一

转载于:https://www.cnblogs.com/ning-wang/p/6443226.html

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号