- Documentation
Elastic Compute Service
Elastic Compute Service
Best Practices
ECS instance local time synchronization
Configuring Chrony service for Linux instances (CentOS 7)
ECS instance local time synchronization
Configuring Chrony service for Linux instances (CentOS 7)
Configuring Chrony service for Linux instances (CentOS 7)
This topic describes how to modify the time zone of a Linux ECS instance, as well as how to enable, configure, and use the Chrony service to ensure accurate local time synchronization for the instance. In the example provided in this topic, CentOS 7.9 is used.
About Chrony
Chrony is a general-purpose implementation of the Network Time Protocol (NTP). In CentOS 7, you can use the Chrony tool to synchronize the local time with standard time, minimizing time and frequency discrepancies to the greatest extent possible. Chrony is also particularly useful for systems that do not run continuously or operate on virtual machines. For more information, see Chrony. Prerequisites
- CentOS 7 comes with Chrony preinstalled. If not, install it by executing the yum install chrony -y command.
- Chrony uses the User Datagram Protocol (UDP) to send and receive timestamps over port 123. Make sure that an inbound rule is added to the security group of the instance to allow inbound traffic on UDP port 123. For more information, see Creating security groups.
Procedure
Modify the time zone of a Linux instance
- Execute the following command to view the list of time zones.
ls /usr/share/zoneinfo/<时区文件夹名称>
- For example, you can execute the following command to view the list of time zones in Asia.
ls /usr/share/zoneinfo/Asia
- Execute the following command to modify the time zone. In the example provided in this topic, the time zone is changed to Shanghai.
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
- Execute the following command to update the Real-Time Clock (RTC).
- Execute the following command to view the time zone.
- If the following query result is displayed, the time zone is changed to Shanghai.
Local time: Sat 2022-10-08 03:26:16 UTC
Universal time: Sat 2022-10-08 03:26:16 UTC
RTC time: Sat 2022-10-08 03:26:16
Time zone: Asia/Shanghai (UTC, +0800)
Enable the Chrony service
- Execute the following commands to start the chronyd service and specify that the service automatically starts upon instance startup.
systemctl start chronyd.service
systemctl enable chronyd.service
- Execute the following command to view the time synchronization status of the ECS instance and verify whether the service is started.
- Execute the following command to view the list of time synchronization servers.
Configure the Chrony service
- Execute the following command to open the chrony configuration file. For more information about the chrony.conf file, see chrony.conf.
- Press the i key to start editing the file. Delete any unnecessary NTP server lines, or add a # at the beginning of the lines to comment them out.
- Add the required NTP servers. After you complete the editing, press the Esc key to exit edit mode, enter :wq, and then press Enter to save and exit the file.
server ntp0.ivolces.com minpoll 4 maxpoll 10 iburst
server ntp1.ivolces.com minpoll 4 maxpoll 10 iburst
server ntp2.ivolces.com minpoll 4 maxpoll 10 iburst
server ntp3.ivolces.com minpoll 4 maxpoll 10 iburst
- Execute the following commands to start the chronyd service and specify that the service automatically starts upon instance startup.
systemctl start chronyd.service
systemctl enable chronyd.service
- Execute the following command to view the list of time synchronization servers.
Manually synchronize the clock by using Chrony
- Execute the following command to enter the Chrony tool.
- In the Chrony tool, execute the following command to synchronize the clock.
You can execute the help command to obtain usage instructions for common Chrony commands.
Last updated: 2026.06.17 19:32:52