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.
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.
The following command output indicates that the ECS instance runs NTP.
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.
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.
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.
NTP
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.
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
Connect to a Linux instance.
For more information, see Connect to a Linux instance by using a password or key.
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.Run the following command to open the
chrony
configuration file:sudo vim /etc/chrony.conf
To block unnecessary NTP servers, comment out the unnecessary NTP servers in the configuration file, as shown in the following figure.
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.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
View the status of the chrony service.
Run the following command to view the time synchronization status of the instance and check whether chrony is started:
sudo chronyc tracking
Run the following command to view information about the time synchronization servers:
sudo chronyc -n sources -v
NTP
Connect to a Linux instance.
For more information, see Connect to a Linux instance by using a password or key.
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.Run the following command to open the
NTP
configuration file:sudo vim /etc/ntp.conf
To block unnecessary NTP servers, comment out the unnecessary NTP servers in the configuration file, as shown in the following figure.
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 atntp12.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.Save the configuration file and exit. Run the following command to restart
ntpd
:sudo service ntpd restart
Start NTP.
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
Run the following command to check the status of NTP:
sudo ntpstat
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
Use CLI.
Press
Win+R
, entercmd
, and then press theEnter
key to open CLI.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. Thetime /t
command returns the current system time.
Use GUI to view the taskbar. In the lower-right corner of the Windows taskbar, view the current date and time.
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
Press
Win+R
, entercmd
, and then press theEnter
key to open CLI.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.
Run the following command to view the synchronization status in the synchronization result:
w32tm /query /status
GUI
In the notification area of the taskbar, click the date and time and then click Date and time settings.
View time settings. On the Date & time page, make sure that the Set time automatically parameter is set to On.
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
Open CLI as the administrator.
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
Run the following commands to restart the time synchronization service:
net stop w32time net start w32time
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:
Connect to a Windows instance.
For more information, see Connect to a Windows instance by using a password or key.
In the notification area of the taskbar, click the date and time and then click Date and time settings.
On the Settings page, click Add clocks for different time zones.
In the Date and Time dialog box, click the Internet Time tab and then click Change settings.
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.
ImportantTime synchronization may fail due to third-party antivirus software on the instance. Disable the antivirus software and resynchronize the time.
Click OK.
FAQ
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.