按照Cloudera 的官方建议,所有的CDH节点和Cloudea Manager节点都需要启动ntpd服务。要不然会报如下错误:
1)此角色的主机的运行状况为不良。 以下运行状况测试不良: 时钟偏差.
2)The host’s NTP service is not synchronized to any remote server.
解决方法如下:
先配置一台NTP服务,然后所有的CDH节点都作为此NTP服务的客户端。
1,NTPD服务,10.51.120.12,此机器负责与外部网络的NTPD服务同步标准时间,并作为局域网内的NTPD服务器。
2,NTPD客户端,10.51.120.64 到 10.51.120.68,这些机器与NTPD服务同步时间。
一,配置内网NTP-Server(10.51.120.12)
1,配置/etc/ntp.conf文件。
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# 中国这边最活跃的时间服务器 : http://www.pool.ntp.org/zone/cn
server 0.cn.pool.ntp.org
server 0.asia.pool.ntp.org
server 3.asia.pool.ntp.org
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# allow update time by the upper server
# 允许上层时间服务器主动修改本机时间
restrict 0.cn.pool.ntp.org nomodify notrap noquery
restrict 0.asia.pool.ntp.org nomodify notrap noquery
restrict 3.asia.pool.ntp.org nomodify notrap noquery
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
# 外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
其中如下部分是添加部分:
# 中国这边最活跃的时间服务器 : http://www.pool.ntp.org/zone/cn
server 0.cn.pool.ntp.org
server 0.asia.pool.ntp.org
server 3.asia.pool.ntp.org
# allow update time by the upper server
# 允许上层时间服务器主动修改本机时间
restrict 0.cn.pool.ntp.org nomodify notrap noquery
restrict 0.asia.pool.ntp.org nomodify notrap noquery
restrict 3.asia.pool.ntp.org nomodify notrap noquery
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
# 外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
配置文件修改完成,保存退出。
2,启动ntpd服务。
#service ntpd start
执行chkconfig –level 35 ntpd on命令,开启启动。
3,查看服务连接和监听
[root@grc-cdh03 ~]# netstat -tlunp | grep ntp
udp 0 0 10.51.120.12:123 0.0.0.0:* 19265/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 19265/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 19265/ntpd
udp 0 0 ::1:123 :::* 19265/ntpd
udp 0 0 fe80::3a63:bbff:fe45:92b:123 :::* 19265/ntpd
udp 0 0 :::123 :::* 19265/ntpd
看第一行,表示连接和监听已正确,采用UDP方式。
4,ntpq -p
查看网络中的NTP服务器,同时显示客户端和每个服务器的关系
[root@grc-cdh03 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
dns.sjtu.edu.cn .INIT. 16 u - 1024 0 0.000 0.000 0.000
linode.dev.fawo .INIT. 16 u - 1024 0 0.000 0.000 0.000
112.220.115.166 .INIT. 16 u - 1024 0 0.000 0.000 0.000
dns1.synet.edu. .INIT. 16 u - 1024 0 0.000 0.000 0.000
news.neu.edu.cn .INIT. 16 u - 1024 0 0.000 0.000 0.000
gus.buptnet.edu .INIT. 16 u - 1024 0 0.000 0.000 0.000
*LOCAL(0) .LOCL. 10 l 25 64 377 0.000 0.000 0.000
5,ntpstat 命令查看时间同步状态,这个一般需要5-10分钟后才能成功连接和同步。所以,服务器启动后需要稍等下。
刚启动的时候,一般是:
# ntpstat
unsynchronised
time server re-starting
polling server every 64 s
连接并同步后:
[root@grc-cdh03 ~]# ntpstat
synchronised to local net at stratum 11
time correct to within 11 ms
polling server every 64 s
二,配置内网NTP-Clients
1,配置/etc/ntp.conf文件,在此文件中添加如下配置:
server 10.51.120.12 prefer
保存,并退出。
2,执行chkconfig ntpd on,设置开机启动。
3,执行service ntpd start启动ntpd服务。
4,同步NTP-Server时间
ntpdate -u 10.51.120.12
5,执行hwclock –systohc,把系统时间同步到硬件BIOS。
配置完毕。重启CDH。