All Products
Search
Document Center

Elastic Compute Service:Manage the time synchronization service

Last Updated:Nov 13, 2024

Time accuracy and consistency are important for Elastic Compute Service (ECS) instances in various scenarios, such as when instances need to punctually execute scheduled tasks, record correct log timestamps, and maintain clock consistency in a distributed ECS cluster. This topic describes how to configure and manage the time synchronization service on Linux and Windows ECS instances.

Time synchronization service

A time synchronization service synchronizes the time on ECS instances with the time on Network Time Protocol (NTP) servers by using NTP to ensure that the ECS instance time is accurate.

Linux

chrony and NTP are common time synchronization tools for Linux instances.

The following table describes the chrony and NTP services.

Time synchronization service

Description

Scenario

Time synchronization precision

Stability

chrony

chrony is a software package that uses network time protocol to synchronize the computer system time with NTP servers around the world. chrony is suitable for changing network environments and can adjust the system time in a fast and efficient manner.

Suitable for scenarios that require high precision, high stability, and automation.

High

Suitable for high-latency and unstable network environments.

NTP

NTP is a classic time synchronization service and an implementation of the NTP protocol. NTP is suitable for long-running servers, such as in environments that have stable network connectivity.

Suitable for most scenarios that do not require high precision.

Medium

Handles only a limited level of network instability.

View the time synchronization service process

Alibaba Cloud public images contain default time synchronization configurations. The ECS instances that are created from public images run chrony to implement time synchronization. In most cases, you do not need to intervene with the time synchronization service.

Note

NTP is configured for specific earlier versions of images, such as CentOS 6 images of ECS instances. NTP is no longer maintained by the NTP community. If the ECS instance runs NTP but your business does not require NTP, we recommend that you use chrony.

Run the following command to view the time synchronization service run by an ECS instance:

sudo ps aux | grep -E "ntpd|chronyd"
  • The following command output indicates that the ECS instance runs chrony.

    image

  • The following command output indicates that the ECS instance runs NTP.

    image

View the current system time

You can run commands to check whether the current system time is accurate.

chrony

Run the following command to view information about the time synchronization status, including the system time offset, the stability of the system time, and the time when the previous time synchronization was performed. You can check the System time parameter to check whether the current time is accurate. In this example, the returned information (0.000025116 seconds slow of NTP time) indicates that the current system time is slower than the NTP time.

sudo chronyc tracking

The following sample command output is returned.

image

NTP

Run the following command to view information about the configured NTP server and the corresponding status indicators. In the command output, the offset parameter indicates the difference between the NTP server time and the local time of the ECS instance.

sudo ntpd -p

The following sample command output is returned.

image

Configure manual time synchronization

By default, chrony or NTP that runs on ECS instances gradually adjusts the time to prevent time jumps. We recommend that you do not manually synchronize time. If your business requires manual time synchronization, perform the following operations.

chrony

sudo chronyc makestep

If chrony is used to complete time synchronization, 200 OK is returned.

image

NTP

Important

NTP is no longer maintained by the NTP community. If you run the ntpdate command to perform time synchronization, time jumps may occur. If you want to run the ntpdate command, specify at least three clock sources in the command to prevent time jumps. For information about Alibaba Cloud NTP servers, see the Domain names of Alibaba Cloud NTP servers section of this topic.

  • Manually synchronize the time on an ECS instance in a virtual private cloud (VPC).

    sudo ntpdate ntp.cloud.aliyuncs.com ntp7.cloud.aliyuncs.com ntp10.cloud.aliyuncs.com ntp11.cloud.aliyuncs.com ntp12.cloud.aliyuncs.com
  • Manually synchronize the time on an ECS instance in the classic network.

    sudo ntpdate ntp1.cloud.aliyuncs.com ntp2.cloud.aliyuncs.com ntp3.cloud.aliyuncs.com ntp4.cloud.aliyuncs.com ntp5.cloud.aliyuncs.com

Specify an NTP server address

You can specify an NTP server for time synchronization.

Note

To ensure clock consistency among the instances in a distributed cluster, make sure that all instances are configured with an address that points to the same or reliable NTP server.

chrony

  1. Connect to a Linux instance.

    For more information, see Connect to a Linux instance by using a password or key.

  2. Configure the NTP server.

    If you want to configure an Alibaba Cloud NTP server, configure the <NTP server> parameter. For more information, see the Domain names of Alibaba Cloud NTP servers section of this topic. For information about how to select an Alibaba Cloud NTP server address, see What do I do if NTP time synchronization becomes abnormal? in the "FAQ" section of this topic.

    1. Run the following command to open the chrony configuration file:

      sudo vim /etc/chrony.conf
    2. To block unnecessary NTP servers, comment out the unnecessary NTP servers in the configuration file, as shown in the following figure.

      image

    3. Add an NTP server. In this example, you can add a new NTP server at the ntp12.cloud.aliyuncs.com address to the configuration file, as shown in the following figure. For information about the available NTP server addresses, see the Domain names of Alibaba Cloud NTP servers section of this topic.

      image

    4. Save the configuration file and exit. Run the following commands in sequence to restart chronyd and enable chrony to run on system startup:

      sudo systemctl restart chronyd.service
      sudo systemctl enable chronyd.service
  3. View the status of the chrony service.

    1. Run the following command to view the time synchronization status of the instance and check whether chrony is started:

      sudo chronyc tracking
    2. Run the following command to view information about the time synchronization servers:

      sudo chronyc -n sources -v

NTP

  1. Connect to a Linux instance.

    For more information, see Connect to a Linux instance by using a password or key.

  2. Configure the NTP server.

    If you want to configure an Alibaba Cloud NTP server, configure the <NTP server> parameter. For more information, see the Domain names of Alibaba Cloud NTP servers section of this topic. For information about how to select an Alibaba Cloud NTP server address, see What do I do if NTP time synchronization becomes abnormal? in the "FAQ" section of this topic.

    1. Run the following command to open the NTP configuration file:

      sudo vim /etc/ntp.conf
    2. To block unnecessary NTP servers, comment out the unnecessary NTP servers in the configuration file, as shown in the following figure.

      image

    3. Add an NTP server by running the server <NTP server address> minpoll <Minimum request interval> maxpoll <Maximum request interval> iburst command. In this example, a new NTP server at ntp12.cloud.aliyuncs.com is added to the configuration file, as shown in the figure. For information about NTP server addresses, see the Domain names of Alibaba Cloud NTP servers section of this topic.

      image

    4. Save the configuration file and exit. Run the following command to restart ntpd:

      sudo service ntpd restart
  3. Start NTP.

    1. Run the following commands in sequence to start NTP and enable NTP to run on system startup:

      sudo service ntpd start
      sudo chkconfig ntpd on
    2. Run the following command to check the status of NTP:

      sudo ntpstat
    3. Run the following command to view NTP peers:

      sudo ntpq -p

Windows

Windows instances use the built-in time service for time synchronization, such as Windows Time Service or W32time.

View the current system time

  1. Use CLI.

    1. Press Win+R, enter cmd, and then press the Enter key to open CLI.

    2. Run the following commands at the command prompt to view the current system time:

       date /t 
       time /t

      The date /t command returns the current date. The time /t command returns the current system time.

  2. Use GUI to view the taskbar. In the lower-right corner of the Windows taskbar, view the current date and time.

  3. To change the date or time settings, right-click the date and time in the notification area of the taskbar and then click Adjust date/time. You can view and change the current date and time.

Configure manual time synchronization

CLI

  1. Press Win+R, enter cmd, and then press the Enter key to open CLI.

  2. Run the following command to manually synchronize the time:

     w32tm /resync

    The preceding command forcefully resynchronizes the time set by the Windows Time service with the configured NTP server.

    image

  3. Run the following command to view the synchronization status in the synchronization result:

     w32tm /query /status

    image

GUI

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

  2. View time settings. On the Date & time page, make sure that the Set time automatically parameter is set to On.

  3. Configure manual time synchronization. On the Date & time page, click Sync now in the Synchronize your clock section to complete manual time synchronization.

Configure the NTP server

If you want to specify an NTP server for time synchronization, use one of the following methods based on your business requirements.

CLI

  1. Open CLI as the administrator.

  2. Run the following command to specify an NTP server.

    In this example, the NTP server at ntp11.cloud.aliyuncs.com is used. For more information about NTP server addresses, see the Domain names of Alibaba Cloud NTP servers section of this topic.

     w32tm /config /manualpeerlist:"ntp11.cloud.aliyuncs.com" /syncfromflags:manual /reliable:YES /update

    image

  3. Run the following commands to restart the time synchronization service:

     net stop w32time
     net start w32time
  4. Run the following command to resynchronize the time:

     w32tm /resync

GUI

By default, Windows Server operating systems are synchronized to the Microsoft NTP server (time.windows.com). However, synchronization errors may occur. When you use a Windows ECS instance, you can replace the default Microsoft NTP server with an internal NTP server provided by Alibaba Cloud. In this example, a Windows Server 2022 operating system is used. Perform the following steps to change the default NTP server address:

  1. Connect to a Windows instance.

    For more information, see Connect to a Windows instance by using a password or key.

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

    image

  3. On the Settings page, click Add clocks for different time zones.

    image

  4. In the Date and Time dialog box, click the Internet Time tab and then click Change settings.

    image

  5. In the Internet Time Settings dialog box, select Synchronize with an Internet time server, enter the address of an Alibaba Cloud NTP server deployed in the internal network, click Update now, and then click OK. For information about NTP server addresses, see the Domain names of Alibaba Cloud NTP servers section of this topic.

    Important

    Time synchronization may fail due to third-party antivirus software on the instance. Disable the antivirus software and resynchronize the time.

    image

  6. Click OK.

FAQ

Am I charged for using Alibaba Cloud NTP servers?

No, Alibaba Cloud NTP servers are free of charge. Alibaba Cloud public images contain default time synchronization configurations. By default, ECS instances that are created from public images run chrony or NTP for time synchronization.

What do I do if NTP time synchronization becomes abnormal?

Check the network type of your server. Select an NTP server address based on the network type. For information about NTP server addresses, see the Domain names of Alibaba Cloud NTP servers section of this topic. The public NTP server address is used to provide the time synchronization service over the Internet. Compared with the public NTP server address, the private NTP server address can provide higher time accuracy and stability.

  • If the network type of your instance is VPC, select an NTP server address provided in the VPC (internal network) column of the following table.

  • If the network type of your instance is classic network, select an NTP server address provided in the Classic network (internal network) column of the following table.

Appendix

Domain names of Alibaba Cloud NTP servers

The following table describes the domain names of Alibaba Cloud NTP servers in various networks. These domain names support only IPv4. If you want to modify the Alibaba Cloud NTP server address, you can select one of the following addresses based on your business requirements.

Classic network (internal network)

VPC (internal network)

Internet

ntp1.cloud.aliyuncs.com

ntp2.cloud.aliyuncs.com

ntp3.cloud.aliyuncs.com

ntp4.cloud.aliyuncs.com

ntp5.cloud.aliyuncs.com

ntp6.cloud.aliyuncs.com

Important

Services related to ECS instances in the classic network will reach end of life (EOL) on February 28, 2025. For information about the discontinuation announcement and the VPC migration plan, see EOL notice for Alibaba Cloud ECS instances in the classic 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

References

For information about the time-related concepts and operations of the Linux operating systems or the time configuration changes to Linux public images, see Linux time and time zones.