Focus on cloud service provider activities
Notes on website operation and maintenance

Solution to time zone, date and time synchronization in CentOS 6 environment

Sometimes we directly mount the website after the VPS host solution provided by the selected VPS service provider is installed and the site environment is installed. However, we may find that the published articles or sometimes the time set for automatic script execution does not match our actual time. Even some programs can be accessed only when the time difference is compared with the local time. If the current server time is before the local time, we may not be able to start the software.

Therefore, if there is such a problem, or we can adjust the time of our current VPS/server to be consistent with the current local time regardless of the time difference. Just at noon, there was a netizen who needed to solve such a problem. Lao Zuo operated in his CentOS6 environment and shared the records.

First, display the current system time

date

The results displayed are as follows:

Thu Mar 26 02:30:59 EDT 2015

Second, change the time zone

View the current time zone list

cd /usr/share/zoneinfo/
ls

Here we can see all the time zones

 Solution to time zone, date and time synchronization in CentOS 6 environment

Here we show the time zones of a wide range of regions, but we need to find more detailed time, such as Asian Beijing, then we need to continue to the Asia directory

cd Asia

ls

 linux-date-2

If we need to set the "Shanghai" time to the current time.

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Then ask us whether to replace it, and we can enter y and enter. The time zone becomes the current time zone.

Third, date and time of modification

date MMDDhhmmYYYY

If the current time and date of our date test are incorrect, we can directly replace the update after entering the above command.

MM: month number
DD: date number
Hh: 24 hour time
Mm: minute 2 digits
YYYY: Year

We can also synchronize the current system time and date with NTP (Network Time Protocol). Generally, NTP should be installed on your Linux system. By default, if our system does not have NTP, I can use a simple command to install NTP packages.

A - Install NTP to Ubuntu, Debian

apt-get update
apt-get install ntp

B - Install NTP to Fedora, Centos or redhat

yum install ntp

Then execute the ntpdate pool.ntp.org command to synchronize.

In conclusion, through the above method, we can keep the current VPS time consistent with our local time, so that whether we are debugging software or editing articles, the time is consistent with our current time.

Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » Solution to time zone, date and time synchronization in CentOS 6 environment


Scan the code to follow the official account

Get more news about webmaster circle!
Entrepreneurship, operation and new knowledge