我有CentOS 5.5 32位。 我有一个服务提供商,在他们的路由器上启用NTP。 他们已经检查和加倍检查他们的访问列表,我可以ping时间服务器,但我得到一个奇怪的错误。我设置了NTP和我的conf文件如下所示:
# 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). #server 0.centos.pool.ntp.org #server 1.centos.pool.ntp.org #server 2.centos.pool.ntp.org #server 3.centos.pool.ntp.org server 10.5.1.1 minpoll 17 maxpoll 17 server 10.50.2.2 minpoll 17 maxpoll 17 #broadcast 192.168.1.255 key 42 # broadcast server #broadcastclient # broadcast client #broadcast 224.0.1.1 key 42 # multicast server #multicastclient 224.0.1.1 # multicast client #manycastserver 239.255.254.254 # manycast server #manycastclient 239.255.254.254 key 42 # manycast client # 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
我执行了一个ntpq -p命令,它返回以下内容:
[root@10 ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== 10.5.1.1 209.130.198.70 3 u 34m 36h 1 33.048 459.586 0.004 10.50.2.2 209.130.198.70 3 u 34m 36h 1 130.797 431.009 0.004 [root@10 ~]#
告诉我它正在使用NTP.conf文件中指定的时间服务器。
当我在一台正在工作的机器上执行date命令,并且在我遇到问题的时候,比较时间是5秒。
那么为什么服务ntpd restart命令在时间服务器同步上失败,即使它正在同步?
[root@10 ~]# service ntpd status ntpd (pid 10724) is running... [root@10 ~]# service ntpd restart Shutting down ntpd: [ OK ] ntpd: Synchronizing with time server: [FAILED] Starting ntpd: [ OK ] [root@10 ~]# [root@10 ~]# chkconfig --list ntpd ntpd 0:off 1:off 2:on 3:off 4:on 5:off 6:off [root@10 ~]# [root@10 ~]# cd /etc/init.d/ [root@10 init.d]# vi ntpd [root@10 init.d]# !/bin/bash # # ntpd This shell script takes care of starting and stopping # ntpd (NTPv4 daemon). # # chkconfig: - 58 74 # description: ntpd is the NTPv4 daemon. \ # The Network Time Protocol (NTP) is used to synchronize the time of \ # a computer client or server to another server or reference time source, \ # such as a radio or satellite receiver or modem. # Source function library. . /etc/init.d/functions # Source networking configuration. . /etc/sysconfig/network if [ -f /etc/sysconfig/ntpd ];then . /etc/sysconfig/ntpd fi ntpconf=/etc/ntp.conf ntpstep=/etc/ntp/step-tickers RETVAL=0 prog="ntpd" sync_hwclock() { ARC=0 SRM=0 UTC=0 if [ -f /etc/sysconfig/clock ]; then . /etc/sysconfig/clock [root@10 sysconfig]# vi /etc/sysconfig/ntpd # Drop root to id 'ntp:ntp' by default. OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid" # Set to 'yes' to sync hw clock after successful ntpdate SYNC_HWCLOCK=no # Additional options for ntpdate NTPDATE_OPTIONS="" ~ [root@10 sysconfig]# vi /etc/sysconfig/network NETWORKING=yes NETWORKING_IPV6=no HOSTNAME=10.1.1.66
您正在使用的时间服务器被同步到同一个(可能是本地的)时间服务器。 我曾经看到服务器声称是第0层或第1层,服务时间是正确的时间。 根据他们在哪里得到时间服务,他们可以是几秒钟。 我的ISP公共时间服务器当前closures1.8秒。
将最小轮询时间设置为36小时将严重降低NTP纠正时间的能力。 事实上,你的服务器与时间服务器相差半秒就是结果。
尝试启用一个或两个池服务器,看看你是否可以连接。 这将为您提供更好的时间服务。
要回答你的具体问题, service ntpd restart的错误是由于你有一个空的/etc/ntp/step-tickers文件造成的。 正如你可能知道的那样, ntpd在默认情况下不会重新同步一个超过20分钟的系统时钟,所以大多数ntpd启动脚本都会尝试使用ntpdate来使系统时钟变成一行,在启动ntpd之前保持这种状态。
在你的情况下,把一个有效的服务器放到分step-tickers文件中会导致错误消失。