我有 CentOS 5.5 32 位。我有一个服务提供商,在他们的路由器上启用了 NTP。他们检查并仔细检查了他们的访问列表,我可以 ping 时间服务器,但我收到了一个奇怪的错误。我已经设置了 NTP,我的配置文件如下所示:
# 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 文件中指定的时间服务器。
当我在一台正常运行的机器和一台出现问题的机器上执行日期命令时,比较时间时,它们相差了 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
答案1
您使用的时间服务器与同一个(可能是本地)时间服务器同步。我见过一些声称属于 0 或 1 层的服务器,它们提供的时间服务与正确时间相差数天。根据它们获取时间服务的位置,它们可能相差几秒钟。我的 ISP 公共时间服务器当前相差 1.8 秒。
将最小轮询设置为 36 小时将严重降低 NTP 校正时间的能力。结果就是您的服务器与时间服务器相差半秒。
尝试启用一个或两个池服务器,看看是否可以连接。这将为您提供更好的时间服务。
答案2
为了回答你的具体的问题,上面的错误service ntpd restart
是由于您有一个空文件而导致的/etc/ntp/step-tickers
。您可能知道,ntpd
默认情况下不会重新同步相差超过 20 分钟的系统时钟,因此大多数ntpd
启动脚本都会尝试使用ntpdate
来将系统时钟调整到一致,然后再开始ntpd
保持这种状态。
就您而言,将有效的服务器放入step-tickers
文件会导致错误消失。