Tuesday, August 21, 2007

date and time sync via NTP server howto

Syncronizing your current date and time is as important as making database backups. Without proper accurate stamped date and time, any backup file with any stamped date on it would be meaningless. Without correct time and date, those scripts that depend on date and time schedule would be executed inaccurately and would give you result on a wrong date and time stamp.

There are many ways to adjust, correct and synchronize your system date and time via terminal. Changing and syncing hardware and system clock has been covered from recent entry which can be found here.

If you happen not to have any local NTP server from your network, here's an entry to update, set and adjust your system date and time from external NTP servers around the globe using ntpdate and rdate.

How to synchronize system date and time from NTP pool servers around the web. Do as follows.

Assuming we would like to sync our system date and time with 2.fedora.pool.ntp.org NTP time pool server. This blog entry covers doing it using ntpdate linux command via terminal.

Ntpdate man says:
ntpdate sets the local date and time by polling the Network Time Protocol (NTP) server(s) given as the server arguments to determine the correct time. It must be run as root on the local host. A number of samples are obtained from each of the servers specified and a subset of the NTP clock filter and selection algorithms are applied to select the best of these. Note that the accuracy and reliability of ntpdate depends on the number of servers, the number of polls each time it is run and the interval between runs. Makes use IPv4 and IPv6 on adjusting system date and time.

Getting the current system date and time is needed for comparison values.

# date

Now let us proceed.

SYNCING WITH NTP SERVER MANUALLY
================================

How to synchronize system date and time with NTP time server using ntpdate?

# ntpdate 2.fedora.pool.ntp.org

Alternative time pool servers are:

~~~~~~~~~~~~~~~~~~~~~~~~
0.fedora.pool.ntp.org
1.fedora.pool.ntp.org
time.nist.gov
~~~~~~~~~~~~~~~~~~~~~~~~

If you wish to query date and time only, this would be done like so

# ntpdate -q 2.fedora.pool.ntp.org

If you have a local time server near to your network, this would be

# ntpdate yourlocal.timeserver.host

If the above command failed, and you are more likely behind the firewall. This is how to update date and time behind the firewall

# ntpdate -u yourlocal.timeserver.host

Sync date and time using IP address is also possible like so

# ntpdate 216.194.70.2

SYNCING TIME LOCALLY USING RDATE
=======================================

Rdate linux command gets and update time via network.

Again, initially get your current date and time system values for comparison.

# date

To print current date and time values from local NTP server using rdate, this could be done like so:

# rdate -p local.NTP.IP.address

To sync date and time locally from your NTP server or from the network using rdate would be:

# rdate -s local.NTP.IP.address

To sync date and time locally using rdate via UDP instead of TCP as its transport, this could be done like so:

# rdate -u local.NTP.IP.address

SYNCING DATE/TIME PERMANENTLY AND AUTOMATICALLY USING NTP DAEMON
================================================================

How to sync date between or after reboot?
How to synchronize date and time automatically in linux?
How to install NTP daemon service in linux?

If your server has never been rebooted, there should be a lot of difference and time skipped by the server during high load processes. Because of this, unattended syncing of date and time is needed to be checked, monitored and synced automatically. This approach calls for making NTP act as a NTP daemon service.

How to install NTP daemon service to automatically check and update date/time values from NTP server?

NTP daemon can be installed by doing so:

# yum -y install ntp

With default installation, NTP daemon service could be started and run faily well as follows

# service ntpd start

NTP daemon service makes use of /etc/ntp.conf . Watch the date/time differences from the result of issuing date command and after starting NTP daemon service.

To check for NTP daemon service status would be

# service ntpd status

Making NTP daemon service permanent between reboots would normally be like so

# chkconfig --levels 35 ntpd on

Note:
3 represent runlevel 3, that is bootup to command line with no GUI and 5 represents with X.

Further ntp.conf customization would not be included here, I am going to create a separate entry for creating a NTP server out of Fedora box. Changing timezone via terminal would also not be covered and created here. They would be covered on a separate entry too sooner or later.

If you wish to sync your hardware clock from your system clock or vice versa, there is howto that can be easily viewed here.

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy