If you need to have valid date and time on your server, you need to synchronize it with a time server as well. In order to do this in Linux (especially in CentOS), we will follow my short howto.
1. Ensure you’ve got ntp installed. Run rpm -qa | grep ntp to find out if it already exists on your system and yum install ntp if it is not present.
2. Run ntpdate. On CentOS, you will probably get this error:
[root@server ~]# ntpdate
29 Jan 09:52:54 ntpdate: no servers can be used, exiting
This means you have to include a server into your request, just like shown below.
[root@server ~]# ntpdate 0.pool.ntp.org
29 Jan 10:08:07 ntpdate: step time server 22.214.171.124 offset 676.605025 sec
This means my server had a 10-minute time diffrence with the time server. After this command my time has been adjusted.
3. Add time synchronization to your crontab and run it as often as you need.
30 * * * * /usr/sbin/ntpdate -s 0.pool.ntp.org
Will sync your clock every hour; I think is enough to perform synchronization weekly. Let’s do it.
30 10 5 * * /usr/sbin/ntpdate -s 0.pool.ntp.org
This simple guide will keep your clock synchronized. Have fun!