This topic describes how to change the time zone of a Linux instance, and how to enable and configure the Network Time Protocol (NTP) service to ensure that the local time for ECS instances is precisely synchronized. CentOS 6.5 is used in this topic.
Prerequisites
The NTP service uses UDP port 123 for communication. Before you configure the NTP
service, make sure that UDP port 123 is enabled. You can run the netstat -nupl
command to check whether UDP port 123 is enabled. For more information about how
to allow traffic on UDP port 123, see Add security group rules.
Background information
By default, ECS instances in all Alibaba Cloud regions use UTC+8. You can configure or change time zones for your instances.
ntpdate
performs a one-time-only update to the system clock. For newly purchased instances, you can usentpdate
to synchronize time.ntpd
adjusts the system clock in small steps. For instances with running workloads, we recommend that you usentpd
to synchronize time.
Modify the time zone of a Linux instance
Enable the standard NTP service
- Connect to the Linux instance. For more information, see Overview.
- Run the
sudo service ntpd start
command to enable the NTP service. - Run the
chkconfig ntpd on
command to enable the NTP service to run upon startup. - Run the
ntpstat
command to check whether the NTP service is enabled. - Optional:Run the
ntpq -p
command to view the list of NTP peers and run thesudo chkconfig --list ntpd
command to view the run level for the NTP service.
Configure the custom NTP service
- Connect to the Linux instance. For more information, see Overview.
- Run the
sudo vi /etc/ntp.conf
command to use vim to open and edit the configuration file of the NTP service. - Find the
server ntp server iburst
information and enteri
to start to edit the file. For NTP servers that you do not need, you can add a number sign (#
) at the beginning of the lines to hide the servers. - Add a new line of NTP server information in the following format:
server <the NTP server that you want to add> iburst
. After you edit the file, press the Esc key and enter:wq
to save the file and exit. - Run the
sudo service ntpd start
command to enable the custom NTP service. - Run the
chkconfig ntpd on
command to enable the custom NTP service to run upon startup. - Run the
ntpstat
command to check whether the NTP service is enabled.