Correcting CentOS System Clock
The simple answer is "set the date manually", which you need to do, but to prevent this occurring again, there is more that you should do.
Ensure that the system timezone configuration is in a sane state.
Unless there is a very strong reason not to do so (such as software compatibility issues), server clocks should always run on UTC time.
If you decide not to use UTC, choose a timezone by running
tzselect. A timezone will be printed on screen which you will use below. An example would be
Europe/Moscow. Otherwise use
UTCas the timezone below.
Here is that TZ value again, this time on standard output so that you can use the /usr/bin/tzselect command in shell scripts: Europe/Moscow
Set the system clock to your desired timezone by the following steps:
Replace the contents of
/etc/sysconfig/clockwith the following:
UTC=trueshould be set here, even if you don't use UTC as your timezone. This refers to the server's hardware clock, which should always be UTC regardless of your chosen system timezone.
/etc/localtimefile with a link to the selected timezone:
# ln -snf /usr/share/zoneinfo/<timezone> /etc/localtime
# ln -snf /usr/share/zoneinfo/Europe/Moscow /etc/localtime # ln -snf /usr/share/zoneinfo/UTC /etc/localtime
Set the clock manually to the current time.
Sync the system clock to the current time:
# ntpd -g -q
Check that the time appears correct:
Sync the server's hardware clock to the system clock:
# hwclock -wu
Restart the computer. Restarting is necessary because all system services must be restarted to pick up the corrected time and timezone, and the server's hardware clock needs to be tested (e.g. for a faulty battery).
After restart, check to see that the system shows the correct time and that ntpd is running properly.