How to fix the time drift issue on a cPanel linux server
Many times you may notice a time drift problem on the server. It is common with some of the AMD Processor server series as well. In most cases its impact is not very high and it can be controlled by setting up a cron to run each minute to make sure the time remains close to accurate.
e.g. you can setup below cron in either root cron file at /var/spool/cron or in /etc/crontb
*/1 * * * * rdate -s rdate.cpanel.net
This basically syncs the time using rdate, you can use cPanel’s rdate server or any of other public rdate servers.
Another way to fix it is by setting up ntpd (Network Time Protocol Daemon) on the server and is a method to achieve more accurate results. You can install ntp using following simple commands :
# yum install ntp
Edit /etc/ntp.conf for choice of your server
# vi /etc/ntp.conf
The default timer servers should work too , or you can update them as per your liking. The service can be controlled using below simple/standard commands :
# service ntpd start
# service ntpd stop
# service ntpd restart
There are more detail configuration settings as well like drift etc, but for normal use the default settings should be fine. Another reason for time drift ( usually a crazy one ) can be kernel specific problem. That is in this case the time drifts forward and background with a jump of 20 / 30 seconds, and this becomes a serious problem resulting in failure of different services, one server I handled had both imap and ftp services failing on it.
This was a cPanel server with courier throwing below error :
“BYE Clock skew detected. Check the clock on the file server”
And ftp was also failing with such a time drift as was not able to do the initial connection session. This was resolved by installing the latest CentOS5 kernel on the related sever.
So for resolving a time drift issue, your sequence would be from rdate cron, ntpd to kernel upgrade , depending on what exactly is the problem and how severe it is.
If you have to choose between cron and ntpd then ntpd solution is preferred.
How to synchronize time with NTP servers
1. Synchronizing time with NTP(Network Time Protocol) server.
# which ntpdate
2. If its not available type:
# yum install ntp
3. Once ntp is installed synchronize your computer clock with:
# ntpdate 0.us.pool.ntp.org
4. You are not limited to the above server. There are numerous NTP servers around the world. You can find a complete list at ntp.org. Also keep in mind that ntp only affects the system time. The hardware clock on your server will not reflect that. So you want to set it as well so that the correct time is maintained after reboot:
# hwclock –systohc
# ntpd
5. To keep your server clock automatically synchronized you can run the ntpd daemon which is installed as part of the ntp package. Edit the /etc/ntp.conf file to comment out the following lines:
# vi /etc/ntp.conf
——————————————–
#server 127.127.1.0 # local clock
#fudge 127.127.1.0 stratum 10
——————————————–
6. The above two lines can sometimes prevent ntpd from properly synchronizing your clock. They are already commented out by default on CentOS/RHEL 6. But on 5.x you have to comment them out manually. Finally type the following two commands to start the daemon and make it run automatically at boot up:
# service ntpd start
# chkconfig ntpd on
How to set the correct timezone
1. Login as root either locally or remotely via SSH.
2. See what the current timezone is using following command :-
# date
Fri Nov 4 10:33:29 PDT 2011
3. To change the timezone first look at what timezones are available by running the following command on the command line interface:
# ls /usr/share/zoneinfo
Africa Australia Cuba Etc GMT0 Iceland Japan MST Poland right Universal Zulu
America Brazil EET Europe GMT-0 Indian Kwajalein MST7MDT Portugal ROC US
Antarctica Canada Egypt Factory GMT+0 Iran Libya Navajo posix ROK UTC
Arctic CET Eire GB Greenwich iso3166.tab MET NZ posixrules Singapore WET
Asia Chile EST GB-Eire Hongkong Israel Mexico NZ-CHAT PRC Turkey W-SU
Atlantic CST6CDT EST5EDT GMT HST Jamaica Mideast Pacific PST8PDT UCT zone.tab
4. Then simply delete the current timezone:
# rm /etc/localtime
5. And replace it with a symbolic link to the new timezone from /usr/share/zoneinfo. For example if your chosen zone is Pacific time:
# ln –s /usr/share/zoneinfo/PST8PDT /etc/localtime