首批通过分布式安全可靠测评,为关键业务系统打造
NTP 时钟不同步的问题排查
更新时间:2026-06-08 02:41
适用版本
OceanBase 数据库所有版本。
问题描述
OBServer 服务器 NTP 时钟同步异常,导致 OBServer 无法正常启动。
[root@SYS ~]# systemctl status ntpdate
返回结果如下:
ntpdate.service - Set time via NTP
Loaded: loaded (/usr/lib/systemd/system/ntpdate.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2023-04-03 20:58:16 CST; 17h ago
Process: 12788 ExecStart=/usr/libexec/ntpdate-wrapper (code=exited, status=1/FAILURE)
Main PID: 12788 (code=exited, status=1/FAILURE)
Apr 03 20:58:16 SY-OB-DB51 systemd[1]: Starting Set time via NTP...
Apr 03 20:58:16 SY-OB-DB51 systemd[1]: ntpdate.service: Main process exited, code=exited, status=1/FAILURE
Apr 03 20:58:16 SY-OB-DB51 systemd[1]: ntpdate.service: Failed with result 'exit-code'.
Apr 03 20:58:16 SY-OB-DB51 systemd[1]: Failed to start Set time via NTP.
问题原因
OBServer 服务器与集群其他服务器时间不同步。排查步骤如下:
查看 journalctl 日志,发现 NTP 服务无法启动:
Can't find host 0.kylin.pool.ntp.org: Name or service not known。详细信息如下:Apr 03 20:58:16 SY-OB-DB51 systemd[1]: Starting Set time via NTP... Apr 03 20:58:16 SY-OB-DB51 ntpdate[12794]: Can't find host 0.kylin.pool.ntp.org: Name or service not known (-2) Apr 03 20:58:16 SY-OB-DB51 ntpdate[12794]: no servers can be used, exiting Apr 03 20:58:16 SY-OB-DB51 systemd[1]: ntpdate.service: Main process exited, code=exited, status=1/FAILURE Apr 03 20:58:16 SY-OB-DB51 systemd[1]: ntpdate.service: Failed with result 'exit-code'. Apr 03 20:58:16 SY-OB-DB51 systemd[1]: Failed to start Set time via NTP.NTP 尝试使用的服务器
0.kylin.pool.ntp.org不是ntp.conf文件中配置的 Server 地址。查看 NPTDATE 使用的配置文件:
systemctl cat ntpdate。[root@SYS ~]# systemctl cat ntpdate返回结果如下:
# /usr/lib/systemd/system/ntpdate.service [Unit] Description=Set time via NTP After=network-online.target nss-lookup.target Before=time-sync.target Wants=time-sync.target network-online.target [Service] Type=oneshot ExecStart=/usr/libexec/ntpdate-wrapper RemainAfterExit=yes [Install] WantedBy=multi-user.target其在启动时使用了
/usr/libexec/ntpdate-wrapper文件。查看 ntpdate-wrapper 的内容。
[ "$EUID" != "0" ] && exit 4 [ -x /usr/sbin/ntpdate ] || exit 5 [ -f /etc/sysconfig/ntpdate ] || exit 6 . /etc/sysconfig/ntpdate [ -f $ntpstep ] && tickers=$(sed 's/#.*//' $ntpstep) || tickers= if ! echo "$tickers" | grep -qi '[a-z0-9]' && [ -f $ntpconf ]; then # the step-tickers file doesn't specify a server, # use servers from ntp.conf instead tickers=$(awk '$1=="peer"||$1=="server"{print $2}' $ntpconf | \ grep -Ev '127\.127\.[0-9]+\.[0-9]+') fi if ! echo "$tickers" | grep -qi '[a-z0-9]'; then echo "NTP server not specified in $ntpstep or $ntpconf" exit 6 fi /usr/sbin/ntpdate -s -b $OPTIONS $tickers &> /dev/null RETVAL=$? [ $RETVAL -eq 0 ] && [ "$SYNC_HWCLOCK" = "yes" ] && /sbin/hwclock --systohc exit $RETVAL脚本里引用了两个配置文件:
ntp.conf和step-tickers,并且会优先从 step-tickers 中获取服务端 IP 信息。查看 step-tickers 文件的内容,其中填写了 0.kylin.pool.ntp.org。
[root@SY-OB-DB51 ~]# more /etc/ntp/step-tickers返回结果如下:
# List of NTP servers used by the ntpdate service. 0.kylin.pool.ntp.org
通常配置 NTP 服务时,会使用 ntp.conf 来指定时钟服务器,而 step-tickers 一般为空。当 step-tickers 文件配置了时钟服务器时,NTPDATE 会优先使用 step-tickers 中指定的服务器。
解决方法
注释 /etc/ntp/step-tickers 文件中的域名信息,保证 NTPD 和 NTPDATE 服务都从 ntp.conf 文件中读取配置信息。