For cloud server administrators, maintaining the correct system time setting is crucial. Incorrect system time can cause many server environment issues, such as data inconsistency, data synchronization failure, and the failure of scheduled tasks.
To avoid these unnecessary troubles, we need to first set the correct system time zone. Next, we use the NTP (Network Time Protocol) service for real-time synchronization to ensure the system time is always precise. Below, we use a CentOS 7 server as an example to explain how to change the time zone and use the NTP service.
First, we use the date command to check the current time.
date
The result returned is as follows:
Fri Feb 21 07:23:08 UTC 2020
We can change the time zone from UTC (Coordinated Universal Time) to Beijing Time using the following command.
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Confirm the change again with the date command.
Fri Feb 21 15:24:28 CST 2020
The NTP service is a daemon running on Linux operating systems, used to synchronize with remote NTP servers. Use the following command to install the NTP service.
yum install ntp
Since the NTP service requires communication through port 123 to function properly, we need to open this port in the firewall.
Use iptables for this:
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
service iptables restart
With this, the time zone change and firewall configuration on the CentOS cloud server are complete.
23-02-2024 02:02:07
22-02-2024 03:19:32
22-02-2024 03:16:03
22-02-2024 03:14:03
22-02-2024 03:11:58