1

I have a VPS running on Cent Os 5.8 (x86). There are situations in which we are forced to reset the entire VPS (it hangs and the only way to get it back on is to reset it). When we do so, the time is reset too.

We use the following command to set the time (the timezone is configured through kloxo admin panel and is not reset like the time does):

#date +%T%p -s "10:10:10" (as for hour 10 and minutes 10 and seconds 10 ) 
5
  • You have no choice but to tolerate the lockups? I would be hammering on the VPS providers door for answers. Commented Aug 21, 2012 at 17:36
  • Are you hard coding 10:10:10 every time or is that an example? Are you trying to pull real time values? Commented Aug 21, 2012 at 17:37
  • Can't you use NTP? Commented Aug 21, 2012 at 17:51
  • @Tim:Well he is not answering and keeps saying the vps is completely unmanned and its all on us. And at the moment yes, because i couldn't have found the cause(s) so far.(i will open another question for solving this question later) that 10:10:10 is just an example of my input.My local timezone is Iran/Tehran, the timezone is set , for setting the time, i sync it with my pcs current time.Im trying to set the time not getting it( if i got your meaning by 'pulling the time' right) Commented Aug 21, 2012 at 18:30
  • @cjc:What is NTP? i have no idea what that is.I am just a simple linux user(newbie) Commented Aug 21, 2012 at 18:30

2 Answers 2

5

You can use NTP (Network Time Protocol) if this machine is Internet connected. This will synchronize the machine's clock to an Internet time server.

yum install ntp, then edit the /etc/ntp.conf file so that you have at least one line that looks like:

server 0.pool.ntp.org 

Then chkconfig ntpd on so that it will start up automatically on boot.

Once this is done, start the NTP service with service ntpd start or /etc/init.d/ntpd start. Or, for newer versions of CentOS that use systemd, run systemctl start ntpd.

Here's some additional documentation from Slicehost.

3
  • It still says 7:13 while it should say 11:13PM,are there any other options which i should mess around with? Commented Aug 21, 2012 at 18:44
  • @Hossein That's a timezone issue. Look at redhat.com/advice/tips/timezone.html Commented Aug 21, 2012 at 18:47
  • I just noticed everything is fine:),I guess that was a browser cache issue and not the servers itself;) it is set to 12:22PM as it should have :) Commented Aug 21, 2012 at 19:52
4

The program date sets the system clock, i.e. the clock maintained internally by the operating system. There is a separate clock inside the computer which keeps the time when the computer is off (or rebooting). If you've set the system clock manually, call hwclock to set the hardware clock as well.

hwclock --utc --systohc 

(Replace --utc by --localtime if your hardware clock is set to local time. This should only be done if you dual boot with Windows.)

Some distributions have a script that calls hwclock with the right options (--utc or --localtime, and if relevant other hardware-specific options). For example, on Debian, run /etc/init.d/hwclock.sh stop. I don't know about CentOS.

All of this is for a one-time thing. If your computer has a permanent or frequent Internet connection, once you've set the time approximately right manually, make it synchronize its time over the network, using NTP. See cjc's answer.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.