Easy steps to correct the incorrect VPS time

When you get a VPS outside your own territory the time-zone is unlikely correct. Not only that, sometimes the VPS clock is just wrong: it can be 10 to 20 minutes faster or slower. You are happy after correcting it, not not too long as the clock will be wrong again after a reboot. This guide is for CentoOS 5.x

Here is a solution: submit a ticket to your provider:-)

I don’t want to bother those busy guys (almost always men) unless there is no other way. So if you are like me, follow those steps:

Step 1: Edit /etc/sysctl.conf and add this line (if you are using Xen):

xen.independent_wallclock=1

Step 2: Save the file and exit and then run at the command line

sysctl -p

Step 3: Set up your local time. Go to the /usr/share/zoneinfo/ (easier on SFTP) and find your correct time zone file. Remember the location and file name (writing it in notepad or on paper). For example, mine is:

/usr/share/zoneinfo/Asia/Shanghai

Then run the following code at the command line (Replacing /usr/share/zoneinfo/Asia/Shanghai with yours)


rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum install -y ntp
ntpdate us.pool.ntp.org
date

Bingo! The time is correct, finally! But don’t be happy too early. You will still need to do one last step.

Step 4: Edit file /etc/rc.local and add the following line:

ntpdate us.pool.ntp.org

In this way, your VPS will sync time automatically with us.pool.ntp.org server, not local BIOS.

Share

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Leave a Reply

You must be logged in to post a comment.