Home > Operation and Maintenance > Linux Operation and Maintenance > How to set Linux instance time zone and NTP service

How to set Linux instance time zone and NTP service

坏嘻嘻
Release: 2018-09-19 13:52:48
Original
1734 people have browsed it

The content of this article is about how to set the Linux instance time zone and NTP service. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Time settings: Set the Linux instance time zone and NTP service

The synchronization of time zone and time is very important for cloud servers (for example, when you update the database, the impact of time accuracy on the business will be Very large). To avoid confusion in the business logic running on the instance and avoid network request errors, you need to set one or more instances in the same time zone, such as Asia/Shanghai or America/Los Angeles. Currently, the default time zone for Alibaba Cloud ECS instances in all regions is CST (China Standard Time). You can set or modify the time zone for ECS instances according to your business needs and refer to this article. In addition, the NTP (Network Time Protocol) service can ensure that the time of your cloud server ECS is synchronized with the standard time. You can configure the NTP service according to this article.

Modify the ECS instance time zone

Here we take the Centos 6.5 instance as an example to enumerate the methods of modifying the time zone by modifying the configuration file:

Note: After changing the time zone, please remember that you need to run hwclock -w to update the instance hardware clock.

You need to open and edit the time zone configuration file as root, so use the sudo command here.

Remotely connect to a Linux instance.

Execute the command sudo rm /etc/localtime to delete the local time link in the system.

Execute the command sudo vi /etc/sysconfig/clock and use vim to open and edit the configuration file /etc/sysconfig/clock.

Enter i to add a time zone city, for example, add Zone=Asia/Shanghai, press the Esc key to exit editing and enter: wq to save and exit.

The executable command ls /usr/share/zoneinfo queries the time zone list. Shanghai is one of the list entries.

Execute the command sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime to update the time zone modification content.

Execute the command hwclock -w to update the hardware clock (RTC).

Execute the sudo reboot command to restart the instance.

Execute the command date -R to check whether the time zone information is effective. If it is not effective, you can go through the steps again.

Set NTP server

Linux system has two methods: ntpd and ntpdate to achieve NTP time synchronization. Among them, ntpd synchronization time is step-by-step. The gradual adjustment time, ntpdate is the breakpoint update. Newly purchased instances can use the ntpdate update service. For instances that are already running services, it is recommended to use ntpd to synchronize time. Standard NTP service configuration and custom NTP service configuration are provided here, and you can configure them selectively according to your needs. For more information about NTP services, please refer to the intranet and public NTP servers.

Prerequisite

The communication port of the NTP service is UDP 123. Please make sure you have opened the UDP 123 port before setting up the NTP service. You can use netstat -nupl to check whether the instance has opened UDP port 123. You can refer to the documentation to add security group rules to allow UDP 123 port.

Enable standard NTP service

Remotely connect to the Linux instance.

Execute the command sudo service ntpd start to run the NTP service.

Execute the command chkconfig ntpd on to enable the NTP service.

Execute the command ntpstat to check whether the NTP service is enabled.

(Optional) Execute the command ntpq -p to view the list information of NTP service peers; execute the command sudo chkconfig --list ntpd to view the running level of the NTP service.

Configure custom NTP service

Remotely connect to a Linux instance.

Execute the command sudo vi /etc/ntp.conf to open and edit the NTP service configuration file with vim.

After finding the server ntp server iburst information, enter i to start editing the file, and add # at the beginning of the NTP server sentence that you do not need temporarily to hide it.

Add a new line of NTP server information in the format: server The NTP server you need to add iburst. After finishing editing, press the Esc key and enter: wq to save and exit.

Execute the command sudo service ntpd start to enable the customized NTP service.

Execute the command chkconfig ntpd on to enable the NTP service.

Execute the command ntpstat to check whether the NTP service is enabled.

If the problem cannot be solved, you can go to the Alibaba Cloud community for free consultation, or contact the cloud market merchant for help.

The above is the detailed content of How to set Linux instance time zone and NTP service. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template