What is NTP?
The Network Time Protocol (NTP) is used to synchronize a servers time with another reference time source. It will keep all your servers in same time. In linux you can use NTP or OpenNTPD server software. Both packages provide client and server application programs for time synchronization.
How to Install NTP
By using yum we can easily install the ntp package on linux machinie.
# yum install ntp
Steps to configure NTP Client
Here we are going to use the public ntp address (pool.ntp.org).
Step 1: Open the ntp.conf file under /etc directory and make sure the following line exists,
server ntp.server.com
Where,
• ntp.server.com : the hostname or IP address of the site NTP server.
Sometimes we have configured the ntp with LAN, For example, if you configure the ntp server at 192.168.1.5 then enter server 192.168.1.5. So that your client will communicate with 192.168.1.5 server for synchronization.
But in our example, we are using public ntp server “pool.ntp.org” right, so comment all the servers in /etc/ntp.conf and add our public ntp server address
server pool.ntp.org
Step 2: Schedule cron for time synchronize
30 * * * * /usr/sbin/ntpdate -u pool.ntp.org
The above command instructs crond to run ntpdate command to update the linux server time for every 30 minutes.
Step 3: Configure NTP at system boot
#chkconfig ntpd on
Steps to start, stop and restart NTP after booting.
#service ntpd start
#service ntpd stop
#service ntpd restart
Step 4: Testing NTP
After configuring and starting NTP, you should test it to make sure it is working. Here are some guidelines you can follow to get NTP working correctly.
Verifying NTP is Running
To test whether the NTP process is running use the command
# pgrep ntpd
You should get a response of plain old process ID numbers.
Troubleshooting
Doing an Initial Synchronization:
If the time on the local server is very different from that of its primary time server your NTP daemon will eventually terminate itself leaving an error message in the /var/log/messages file. You should run the ntpdate -u command to force your server to become instantly synchronized with its NTP servers before starting the NTP daemon for the first time.
# service ntpd stop
# ntpdate -u pool.ntp.org
# service ntpd start
The date is now corrected.
# date
Wed Jun 13 08:38:28 BST 2012
Determining if NTP is synchronized properly
Use the ntpq command to see the servers with which you are synchronized. It provided you with a list of configured time servers and the delay, offset and jitter that your server is experiencing with them. For correct synchronization, the delay and offset values should be non-zero and the jitter value should be under 100.
# ntpq -p