---
title: NTP 时钟不同步的问题排查-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于NTP 时钟不同步的问题排查相关的常见问题和使用技巧，帮助您快速解决NTP 时钟不同步的问题排查的难题。
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

划线反馈

# NTP 时钟不同步的问题排查

更新时间：2026-06-08 02:41

适用版本： V1.4.x、V2.1.x、V2.2.x、V3.1.x、V3.2.x、V4.0.x、V4.1.x、V4.2.x 内容类型：Troubleshoot  

## 适用版本

OceanBase 数据库所有版本。

## 问题描述

OBServer 服务器 NTP 时钟同步异常，导致 OBServer 无法正常启动。

```shell
[root@SYS ~]# systemctl status ntpdate

```

返回结果如下：

```shell
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 服务器与集群其他服务器时间不同步。排查步骤如下：

1. 查看 journalctl 日志，发现 NTP 服务无法启动：`Can't find host 0.kylin.pool.ntp.org: Name or service not known`。详细信息如下：

   ```shell
   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 地址。
 2. 查看 NPTDATE 使用的配置文件：`systemctl cat ntpdate`。

   ```shell
   [root@SYS ~]# systemctl cat ntpdate

   ```

   返回结果如下：

   ```shell
   # /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` 文件。
 3. 查看 ntpdate-wrapper 的内容。

   ```shell
   [ "$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 信息。
 4. 查看 step-tickers 文件的内容，其中填写了 0.kylin.pool.ntp.org。

   ```shell
   [root@SY-OB-DB51 ~]# more /etc/ntp/step-tickers

   ```

   返回结果如下：

   ```shell
   # 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` 文件中读取配置信息。

上一篇

[clockdiff: xx.xx.xx.xx is down](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000207674)

下一篇

[重启 OBServer 失败报错 -4013](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000002075657) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
