Time synchronization for ECS instances

更新时间:
复制 MD 格式

Inaccurate time can cause misaligned scheduled tasks, inconsistent log timestamps, and clock skew in distributed systems. Configure a time synchronization service to automatically keep the system time on your instances accurate.

How it works

image
  • Network Time Protocol (NTP): A protocol that synchronizes clocks between a client and a server to within milliseconds by calculating network latency.

  • Alibaba Cloud NTP server: A time synchronization service provided by Alibaba Cloud. It offers endpoints in a VPC internal network, which allows ECS instances to synchronize time with minimal network latency.

  • chrony/ntpd/W32time: Time synchronization services that use NTP to synchronize an instance's system time with an NTP server. On Linux systems, chrony offers better performance than ntpd. Windows systems use the built-in W32time service.

Check time accuracy

How to quickly check if your instance time is accurate

Linux (chrony)

Alibaba Cloud public images include a default time synchronization configuration. ECS instances created from public images run chrony by default for time synchronization. Some older public images run ntpd by default. To check which daemon is running, execute ps -C chronyd,ntpd -o comm=. If the output is ntpd, the instance uses ntpd. See Linux (ntpd) for instructions.

Run the following command to get detailed information about the current time synchronization status. Check the System time value to assess accuracy. For example, 0.000027851 seconds fast of NTP time indicates that the system time is 0.000027851 seconds ahead of the NTP server time. Compare this offset with your application's tolerance. If it is outside the acceptable range, you must adjust your time configuration.

To check the time accuracy on multiple instances, you can use Cloud Assistant to run batch checks.
sudo chronyc tracking
Reference ID    : 64643D58 (100.100.61.88)
Stratum         : 2
Ref time (UTC)  : Tue Oct 28 05:53:58 2025
System time     : 0.000027851 seconds fast of NTP time
Last offset     : +0.000044533 seconds
RMS offset      : 0.000036478 seconds
Frequency       : 41.053 ppm slow
Residual freq   : +0.000 ppm
Skew            : 0.007 ppm
Root delay      : 0.000408892 seconds
Root dispersion : 0.011003596 seconds
Update interval : 1028.9 seconds
Leap status     : Normal

Linux (ntpd)

Run the following command to get detailed information about the current time synchronization status. Check the offset value to assess accuracy. In this example, 1009.26 indicates that the system time differs from the NTP server time by 1009.26 milliseconds. Compare this offset with your application's tolerance. If it is outside the acceptable range, you must adjust your time configuration.

To check the time accuracy on multiple instances, you can use Cloud Assistant to run batch checks.
sudo ntpq -p
remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 LOCAL(0)        .LOCL.          10 l  107   64    2    0.000    0.000   0.000
+47.96.XXX.XXX   100.100.61.91    2 u   37   64    3   31.241  1009.95   1.313
 11.116.XXX.XX   .INIT.          16 u    -   16    0    0.000    0.000   0.000
-100.100.3.1     10.137.55.181    2 u   52   64    7   25.344  1010.26   0.566
-100.100.3.2     10.137.55.181    2 u   18   64    7   26.873  1008.80   2.143
-100.100.3.3     10.137.55.181    2 u   66   64   12   29.656  1010.16   0.902
-203.107.6.88    10.137.55.181    2 u   65   64    7   33.689  1005.74   0.697
 11.196.XXX.XXX  .INIT.          16 u    -   16    0    0.000    0.000   0.000
 11.196.XXX.XX   .INIT.          16 u    -   16    0    0.000    0.000   0.000
 10.143.0.44     .INIT.          16 u    -   16    0    0.000    0.000   0.000
 10.143.0.45     .INIT.          16 u    -   16    0    0.000    0.000   0.000
 10.143.0.46     .INIT.          16 u    -   16    0    0.000    0.000   0.000
+100.100.5.1     203.107.X.XX     2 u   59   64    7   53.214  1009.42   0.519
*100.100.5.2     203.107.X.XX     2 u   58   64    7   49.062  1009.26   0.984
-100.100.5.3     203.107.X.XX     2 u   57   64    7   56.670  1011.81   3.331

Windows

Press Win + R, enter cmd, and press Enter to open the command-line interface (CLI). Run the command w32tm /query /status. Check the Root Dispersion value to assess accuracy. For example, 7.7612440s means the system time differs from the NTP server time by 7.7612440 seconds. Compare this offset with your application's tolerance. If it is outside the acceptable range, you must adjust your time configuration.

To check the time accuracy on multiple instances, you can use Cloud Assistant to run batch checks.
Leap Indicator: 0(no warning)
Stratum: 3 (secondary reference - syncd via (S)NTP)
Precision: -23 (119.209ns per tick)
Root Delay: 0.0259591s
Root Dispersion: 7.7612440s
Reference ID: 0x64640302 (source IP:  100.100.3.2)
Last Successful Sync Time: 2025/10/28 15:05:02
Source: ntp11.cloud.aliyuncs.com,0x9
Poll Interval: 6 (64s)

Configure time synchronization

Linux (chrony)

Alibaba Cloud public images include a default time synchronization configuration. ECS instances created from these images run chrony by default for time synchronization. However, some older public images run ntpd by default. You can run the ps -C chronyd,ntpd -o comm= command to check which service is running. If the command returns ntpd, it indicates that ntpd is running by default. In this case, refer to Linux (ntpd) to configure time synchronization.

Important

A Linux system can run only one time synchronization daemon. You must choose between chronyd and ntpd. Before starting one service, stop and disable the other.

To configure time synchronization on multiple instances, you can use Cloud Assistant for batch execution.

1. Configure NTP servers

  1. Edit the chrony configuration file.

    Alibaba Cloud Linux/CentOS/RHEL

    sudo vim /etc/chrony.conf

    Ubuntu/Debian

    sudo vim /etc/chrony/chrony.conf
  2. Configure the Alibaba Cloud NTP servers.

    Comment out all lines that start with server in the file by using #, and copy the following content to the configuration file.

    Important

    To ensure high availability and improve accuracy, you must configure multiple NTP time sources. Using a single time source creates a single point of failure and is strongly discouraged.

    # This configuration includes NTP server addresses, and the minimum and maximum polling intervals.
    server ntp.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp10.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp11.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp12.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp7.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp8.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    server ntp9.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
  3. Save the configuration file and restart the chrony service.

    sudo systemctl restart chronyd.service

2. Verify time synchronization

After restarting, the service gradually and smoothly adjusts the time. You can run sudo chronyc tracking to verify the synchronization status.

sudo chronyc tracking

The System time field in the output precisely shows the slight offset between your system time and the NTP time. For example, 0.000036150 seconds fast of NTP time indicates that the system time is ahead of the NTP time.

If the time offset is large, such as several minutes or hours, and your application can tolerate a time jump, consider manually synchronizing the time.
Reference ID    : 64643D58 (100.100.61.88)
Stratum         : 2
Ref time (UTC)  : Sat Sep 20 07:55:33 2025
System time     : 0.000036150 seconds fast of NTP time
Last offset     : +0.000031322 seconds
RMS offset      : 0.000044841 seconds
Frequency       : 43.592 ppm slow
Residual freq   : +0.000 ppm
Skew            : 0.005 ppm
Root delay      : 0.000228760 seconds
Root dispersion : 0.010518964 seconds
Update interval : 1029.1 seconds
Leap status     : Normal

Linux (ntpd)

Some older public images for ECS instances, such as CentOS 6, use the ntpd service by default. Because ntpd is no longer actively maintained, we recommend upgrading to chrony for better performance and security.

Important

A Linux system can run only one time synchronization daemon. You must choose between chronyd and ntpd. Before starting one service, stop and disable the other.

To configure time synchronization on multiple instances, you can use Cloud Assistant for batch execution.

1. Configure NTP servers

  1. Edit the NTP configuration file.

    sudo vim /etc/ntp.conf
  2. Configure the Alibaba Cloud NTP servers.

    Comment out all lines that start with server in the file by using #, and copy the following content to the configuration file.

    Important

    To ensure high availability and improve accuracy, you must configure multiple NTP time sources. Using a single time source creates a single point of failure and is strongly discouraged.

    # This configuration includes NTP server addresses, and the minimum and maximum polling intervals.
    server ntp10.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
    server ntp11.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
    server ntp12.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
    server ntp7.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
    server ntp8.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
    server ntp9.cloud.aliyuncs.com iburst minpoll 4 maxpoll 10
  1. Save the configuration file and restart the ntpd service.

    Alibaba Cloud Linux/CentOS/RHEL

    sudo service ntpd restart

    Ubuntu/Debian

    service ntp restart

2. Verify time synchronization

After restarting, the service gradually and smoothly adjusts the time. You can run sudo ntpq -p to verify the synchronization status. The offset field in the output indicates the difference between the local time and the server time. Key parameters include:

  • offset: The difference between the system time and the server time, in milliseconds. The closer the offset is to 0, the more accurate the system time.

  • jitter: The variation in time delay. A smaller absolute value indicates higher time precision.

If the time offset is large, such as several minutes or hours, and your application can tolerate a time jump, consider manually synchronizing the time.
sudo ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 LOCAL(0)        .LOCL.          10 l   17   64    1    0.000    0.000   0.000
+100.100.3.1     10.137.55.181    2 u    8   16    1   30.426  -307.76   0.153
*100.100.3.2     10.137.55.181    2 u    5   16    1   26.845  -309.25   0.221
+100.100.3.3     10.137.55.181    2 u    4   16    1   28.819  -309.37   0.187
-100.100.5.1     203.107.X.XX     2 u    3   16    1   50.478  -310.70   0.164
-100.100.5.2     203.107.X.XX     2 u    2   16    1   47.235  -311.89   0.246
 100.100.5.3     203.107.X.XX     2 u    1   16    1   53.661  -310.50   0.119

Windows

GUI

Important

The Windows graphical user interface (GUI) supports configuring only a single NTP server. This creates a single point of failure if the server has network issues or becomes unavailable.

For high availability in production environments, we strongly recommend using the command-line interface (CLI) to configure multiple NTP servers.

  1. In the notification area of the taskbar, click the date and time, and then click Date and time settings.

    image

  2. On the Settings page, click Related settings > Add clocks for different time zones.

  3. In the Date and Time window, click the Internet Time tab, and then click Change settings....

  4. In the Internet Time Settings dialog box, select Synchronize with an Internet time server, enter ntp.cloud.aliyuncs.com in the Server field, click Update Now, and then click OK.

  5. Verify the time synchronization. A success message confirms that the clock is synchronized with the server. If synchronization fails, check whether a firewall or security software is blocking UDP port 123.

    image

CLI

Unlike the GUI, the CLI allows you to configure multiple time sources for automatic failover.

To configure time synchronization on multiple instances, you can use Cloud Assistant for batch execution.

1. Configure NTP servers

We recommend replacing the default Windows NTP server with Alibaba Cloud NTP servers. The following steps use Windows Server 2022 as an example.

  1. Press Win + R, enter cmd, and press Enter to open the command-line interface (CLI).

  2. Set the NTP servers. For example, use ntp.cloud.aliyuncs.com ntp7.cloud.aliyuncs.com ntp8.cloud.aliyuncs.com ntp11.cloud.aliyuncs.com.

     w32tm /config /manualpeerlist:"ntp.cloud.aliyuncs.com ntp7.cloud.aliyuncs.com ntp8.cloud.aliyuncs.com ntp11.cloud.aliyuncs.com" /syncfromflags:manual /reliable:YES /update
  3. Restart the time service.

     net stop w32time
     net start w32time
  4. Synchronize the time with the NTP servers.

    w32tm /resync

2. Verify time synchronization

Run the command w32tm /query /status. If the Source is Local CMOS Clock instead of one of your configured NTP servers, synchronization has failed.

 w32tm /query /status
Leap Indicator: 0(no warning)
Stratum: 3 (secondary reference - syncd via (S)NTP)
Precision: -23 (119.209ns per tick)
Root Delay: 0.0020371s
Root Dispersion: 0.0191713s
Reference ID: 0x64640302 (source IP:  100.100.3.2)
Last Successful Sync Time: 2025/10/28 14:37:42
Source: ntp11.cloud.aliyuncs.com
Poll Interval: 10 (1024s)

FAQ

Time synchronization in containers

No.

Do not run chronyd or ntpd inside a container. By default, containers share the host's system time and do not require separate time synchronization. Running a time synchronization service inside a container creates clock resource contention with the host and can severely impact application stability.

Manually synchronize time

Manually synchronizing time can cause a time jump and is not recommended. However, if the system time is off by a large amount (for example, several minutes or hours), you can perform a manual synchronization if your application can tolerate the sudden change.

Linux (chrony)

  1. Stop the chrony service.

    sudo systemctl stop chronyd.service
  2. Manually synchronize the time.

    Important

    To ensure high availability and improve accuracy, do not use a single NTP time source. Before you perform a manual synchronization, confirm that you have configured multiple Alibaba Cloud NTP servers.

    sudo chronyd -q
  3. Start the chrony service.

    sudo systemctl start chronyd.service

Linux (ntpd)

Alibaba Cloud Linux/CentOS/RHEL

  1. Stop the ntpd service.

    sudo service ntpd stop
  2. Manually synchronize the time.

    Important

    The ntpd service is no longer actively maintained, and using the ntpdate command for manual synchronization creates a risk of a time jump. If you must use it, specify three or more time sources in the command to reduce this risk. For a list of available servers, see Alibaba Cloud NTP server domains.

    Important

    Periodically running ntpdate with a script is not a valid replacement for an NTP daemon. An NTP daemon uses sophisticated algorithms to maximize time accuracy and reliability while minimizing resource usage.

    sudo ntpdate ntp.cloud.aliyuncs.com ntp7.cloud.aliyuncs.com ntp10.cloud.aliyuncs.com ntp11.cloud.aliyuncs.com ntp12.cloud.aliyuncs.com
  3. Start the ntpd service.

    sudo service ntpd start

Ubuntu/Debian

  1. Stop the ntpd service.

    sudo service ntp stop
  2. Manually synchronize the time.

    Important

    The ntpd service is no longer actively maintained, and using the ntpdate command for manual synchronization creates a risk of a time jump. If you must use it, specify three or more time sources in the command to reduce this risk. For a list of available servers, see Alibaba Cloud NTP server domains.

    sudo ntpdate ntp.cloud.aliyuncs.com ntp7.cloud.aliyuncs.com ntp10.cloud.aliyuncs.com ntp11.cloud.aliyuncs.com ntp12.cloud.aliyuncs.com
  3. Start the ntpd service.

    sudo service ntp start

Alibaba Cloud NTP server domains

The following table lists the Alibaba Cloud NTP server addresses for different networks. This service supports only IPv4.

  • For ECS instances, use the VPC internal network domains for lower latency.

  • For servers outside Alibaba Cloud, use the public network domains.

VPC internal network

Public network

ntp.cloud.aliyuncs.com

ntp7.cloud.aliyuncs.com

ntp8.cloud.aliyuncs.com

ntp9.cloud.aliyuncs.com

ntp10.cloud.aliyuncs.com

ntp11.cloud.aliyuncs.com

ntp12.cloud.aliyuncs.com

ntp.aliyun.com

ntp1.aliyun.com

ntp2.aliyun.com

ntp3.aliyun.com

ntp4.aliyun.com

ntp5.aliyun.com

ntp6.aliyun.com

ntp7.aliyun.com

Service fee

Yes, the service is free of charge. Alibaba Cloud public images include a default time synchronization configuration, and ECS instances created from these images use either chrony or the ntpd service to synchronize time by default.

Upgrade from ntpd to chrony

Some older public images for ECS instances, such as CentOS 6, are configured to use the ntpd service. The ntpd project is no longer actively maintained. If your ECS instance uses the ntpd service and your applications do not depend on it, we recommend upgrading to chrony.

  1. Uninstall the ntp service.

    Alibaba Cloud Linux/CentOS/RHEL
    sudo yum remove ntp
    Ubuntu/Debian
    sudo apt remove ntp
  2. Install chrony.

    If the download fails, see How to resolve yum installation failures for chrony on CentOS 6 (EOL)?
    Alibaba Cloud Linux/CentOS/RHEL
    sudo yum install chrony
    Ubuntu/Debian
    sudo apt update
    
    sudo apt install chrony
  3. Configure chrony.

    Edit the configuration file.

    Alibaba Cloud Linux/CentOS/RHEL

    sudo vim /etc/chrony.conf

    Ubuntu/Debian

    sudo vim /etc/chrony/chrony.conf

    In this file, you can add NTP servers and other settings. The following is a simple chrony.conf example:

    # NTP server settings
    server ntp.cloud.aliyuncs.com minpoll 4 maxpoll 10 iburst
    # Specify the location of the drift file.
    driftfile /var/lib/chrony/drift
    # Allow chronyd to be queried from localhost.
    allow 127.0.0.1

    The following table describes the parameters in the configuration file.

    Parameter

    Description

    server ntp.cloud.aliyuncs.com

    The domain name of the NTP server. chrony connects to this server to synchronize time.

    minpoll 4

    Specifies the minimum polling interval in seconds, as a power of 2. For example, minpoll 4 sets the interval to 2⁴, or 16 seconds. This means chrony sends a synchronization request to the server at least every 16 seconds.

    maxpoll 10

    Specifies the maximum polling interval in seconds, as a power of 2. For example, maxpoll 10 sets the interval to 2¹⁰, or 1024 seconds.

    iburst

    This option speeds up the initial time synchronization. When chrony starts, it sends a burst of requests (typically eight) to quickly get an accurate time from the server.

  4. Start the chrony service.

    1. Start the chrony service and enable it to start on boot.

      # Start the chrony service.
      sudo service chronyd start
      
      # Set chrony to start automatically when the system boots.
      sudo chkconfig chronyd on
    2. Check the chrony status. Use the chronyc tool to check the status and synchronization of chrony.

      # Check the service status.
      sudo service chronyd status
    3. Verify the time synchronization. Run the command to check the primary server status and the offset between the local clock and the time server.

      sudo chronyc tracking

Resolve yum installation failures for chrony on CentOS 6

  1. Back up and remove the old repo configurations.

    sudo mkdir -p /etc/yum.repos.d/backup && sudo mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/
  2. Create a new repository file that points to the official CentOS Vault. Run the following command to create a new CentOS-Vault.repo file.

    sudo tee /etc/yum.repos.d/CentOS-Vault.repo <<'EOF'
    [C6.10-base]
    name=CentOS-6.10 - Base
    baseurl=http://vault.centos.org/6.10/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=1
    [C6.10-updates]
    name=CentOS-6.10 - Updates
    baseurl=http://vault.centos.org/6.10/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=1
    [C6.10-extras]
    name=CentOS-6.10 - Extras
    baseurl=http://vault.centos.org/6.10/extras/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled=1
    EOF
  3. Clean the yum cache and rebuild it.

    sudo yum clean all && sudo yum makecache
  4. Install chrony.

    sudo yum install chrony

Related topics

  • For more information about time-related concepts and operations in Linux, or to learn about changes to time configurations in Linux public images, see Linux time and time zones.

  • The Precision Time Protocol (PTP) time synchronization service uses hardware-level timestamps and dynamic path compensation to achieve sub-microsecond clock synchronization. This ensures timing consistency in distributed systems, which makes it ideal for scenarios that require high time precision, such as high-frequency financial trading.