按照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。