Setting timezone and synchronizing time with NTP
1. See what the current timezone is:Type date and press enter
You should see output like this:
Wed Sept 1 10:33:29 PDT 2012
2. What time zones are available by running the following command on the command line:
Type ls /usr/share/zoneinfo/ and press enterNote: If you want to change your time zone, then follow the step-3 and step-4.3. Then simply delete the current timezone:
Type rm /etc/localtime and press enter4. And replace it with a new timezone from /usr/share/zoneinfo. For example if your chosen zone is Pacific time:
Type cp /usr/share/zoneinfo/PST8PDT /etc/localtime and press enter
Network Time Protocol (NTP) is a standard way of synchronizing computer clocks across a network. Using NTP you can keep your server’s clock synchronized with super accurate atomic clocks located around the world. Computer clocks tend to “drift” so regularly synchronizing them with NTP servers helps keep them accurate.
5. The first step is to make sure you have the ntp program installed.Type which ntpdate and press enter
6. If its not available type:
Type yum install ntp and press enter
ntpd
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:#server 127.127.1.0 # local clock#fudge 127.127.1.0 stratum 107. Finally type the following two commands to start the daemon and make it run automatically at boot up:
Type service ntpd start and press enterType chkconfig ntpd on and press enterSetting the system clock
To set the system clock under Linux, use thedatecommand. As an example, to set the current time and date to July 31, 11:16pm, type ``date 07312316'' (note that the time is given in 24 hour notation). If you wanted to change the year as well, you could type ``date 073123161998''. To set the seconds as well, type ``date 07312316.30'' or ``date 073123161998.30''. To see what Linux thinks the current local time is, rundatewith no arguments.Setting the hardware clock
First Method:To set the hardware clock, my favourite way is to set the system clock first, and then set the hardware clock to the current system clock by typing ``/sbin/hwclock --systohc'' (or ``/sbin/hwclock --systohc --utc'' if you are keeping the hardware clock in UTC). To see what the hardware clock is currently set to, runhwclockwith no arguments. If the hardware clock is in UTC and you want to see the local equivalent, type ``/sbin/hwclock --utc''Second Method:
Set the hardware clock to local time
hwclock --set --date="2012-04-19 16:45:05" --localtimeSet the hardware clock to UTChwclock --set --date="2011-04-19 20:45:05" --utcSetting the date
date +%Y%m%d -s "20120418''Setting the Time
date +%T -s "11:14:00"Setting the Date & Time
date -s "19 APR 2012 11:14:00"
Summary
/etc/sysconfig/clocksets whether the hardware clock is stored as UTC or local time.- Symlink
/etc/localtimeto/usr/share/zoneinfo/...to set your timezone.- Run ``
date MMDDhhmm'' to set the current system date/time.- Type ``
/sbin/hwclock --systohc [--utc]'' to set the hardware clock.
Comments
Post a Comment