Sunday, October 3, 2010

Time Server and NTP in LINUX


Setup an NTP Server for Time Synchronization

It is a very good idea to set up your system so that it keeps its clock synchronized to the correct time. If you have multiple systems, including an HA configuration, it can be essential. If clocks are not synchronized, correlating events on different systems can make diagnosing any problem very difficult.
You should run an ntp daemon on each of your servers as described below; you can also use those servers to provide a local time source to your phones and other systems within your network; this will be more accurate and less burden on your external network links than each internal system using the external time sources individually.

Installation & Configuration of the NTP Time Server

To install the ntp daemon package:
yum install ntp
To enable it to run by default:
chkconfig ntpd on

Configuring time sources

If you are using a system that has X windows running, you can use the command system-config-date, system-config-time, or dateconfig at a shell prompt (as root) to guide you through setting up the time.
The full documentation is available in man pages
man ntp
and at The Network Time Protocol (NTP) Distribution web site.
You should select from 2 to 4 time sources for your servers. You can get help finding servers at The Public NTP Servers List; a simple approach is to use the NTP Pool Servers (this is what the sipX ISO images use).
Essentially, you just need to add server lines to your /etc/ntp.conf configuration file. If your distribution has one, it's a good idea to configure the same servers in the /etc/ntp/step-tickers file (that is used to set the clock at boot time).

Using a local clock

If you do not have any access to a real NTP server and can't get one, you can still use NTP to synchronize your clocks locally. Pick one system to be your local time source, and install the ntp server there as above. Then look at that documentation in /usr/share/doc/ntp-*/drivers/driver1.html and set the "stratum number" on your chosen system to a lower number than your other systems (a lower number indicates a more precise clock). THen configure that system as the server for the others; even if that time is not strictly correct, at least all your systems will have the same incorrect time, which is better than having many different incorrect times.

To allow your system to be a server for others

Add the line as shown below to the standard /etc/ntp.conf configuration file. It allows access to the time source for other clients on the local LAN segment (here 192.168.5).
File: /etc/ntp.conf
# -- CLIENT NETWORK -------
# Permit systems on this network to synchronize with this
# time service.  Do not permit those systems to modify the
# configuration of this service.  Also, do not use those
# systems as peers for synchronization.
restrict 192.168.5.0 mask 255.255.255.0 nomodify notrap

Start the daemon

/sbin/service ntpd start
Important: After starting the ntp deamon it will be some time before its clock is sufficiently synchronized to provide a clock to the other clients on your network. If everything is properly configured, this will resolve itself. If you try to use the ntpdate command to set the time from some other system before the servers clock is sufficiently synchronized, you will see the error "ntpdate[10560]: no server suitable for synchronization found"

How to update the TimeZone files

Assuming you have ntpd installed and working properly...
 1. Login to the server as root.
 
 2. Stop ntpd: service ntpd stop
 
 3. Get the latest time zone files: wget ftp://elsie.nci.nih.gov/pub/tzdata2008a.tar.gz
       You might want to check the pub folder on elsie.nci.nih.gov for the most current timezone file.
 
 4. Expand: tar xzf tzdata2008a.tar.gz
 
 5. Remove the old localtime link: rm -f /etc/localtime
 
 6. Link to the proper timezone file (for me): ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
 
 7. Restart ntpd: service ntpd start

How to Configure Clients

Phone Clients

SIP phones can be synchronized with an NTP server, but usually do not pick up the server address through DHCP. For sipX ConfigServer managed phones (i.e. Polycom, Snom, Cisco, Grandstream, and others) the NTP server address is configured as part of the phone's profile. Best practice is to create a device group for which the NTP server is set, so that it does not have to be set for every phone individually.

Windows NTP Clients

You can add your new NTP server to your Windows client. Here's how:
  1. Click on the time at the bottom right hand side of your screen.
  2. Click on the "Internet Time" tab of the dialog box
  3. Click the check box labeled "Automatically synchronize with an Internet time server" and enter the name or IP address in the box underneath it.
  4. Click on the "Update Now" button
You will get a message saying "Your time has been successfully synchronized" when the operation is complete.
Note: If your Windows 2000 or Windows XP system is part of a Windows Domain, then time synchronization is provided through the Windows domain controller and therefore the tab "Internet Time" is not available in the time dialog box.

DHCP Distribution of NTP Server Information

An NTP server address can be distributed as an option with the DHCP server. Some clients will pick it up automatically then when obtaining an IP address:
File: /etc/dhcpd.conf
 option ntp-servers            192.168.5.145;

Troubleshooting

The ntpq utility program is used to query NTP servers. You can use the following two commands to print a status of the server if executed on the ntpd host. Refer to the man pages of ntpq.
ntpq -p
 
echo rv | ntpq
This command can be executed on a Linux client to print the status of its clocks without actually updating the time (-q option).
ntpdate -q sipx.domain.com
 
date

No comments:

Post a Comment