Thursday, 1 January 2015

Maintaining System clock using chrony in RHEL 7.0


 Maintaining System clock using chrony in RHEL 7.0

The chrony package provides a chronyd service daemon and chronyc utility that enable mobile systems and virtual machines to update their system clock after a period of suspension or disconnection from a network. Chrony is an NTP client and server designed to work well without permanent network connection. It uses different algorithms to discipline the clock which gives chrony several advantages over ntp:
  • works well even with irregular polling of NTP servers, useful for laptops or systems without permanent network connection
  • much faster synchronization, it usually needs only minutes instead of hours to minimize the time and frequency error, useful for systems not running 24/7
  • larger range for frequency correction (100000 ppm vs 500 ppm), useful for systems running in virtual machines which may have quickly drifting clocks
  • after the initial synchronization the clock is never stepped, this is good for applications which need system time to be monotonic
  • better response to rapid changes in the clock frequency, useful for systems running in virtual machines
  • better stability with temporary asymmetric delays, e.g. when the link is saturated by a large download  
The computer relies on the real-time clock (RTC) to maintain the correct time during shutdown and offline periods. At boot up, chronyd sets the system time to RTC time. When the Internet connection is made, chronyd starts measuring the error and drift rate between system and RTC time, gradually bring both times into sync with the NTP time signal. After a number of hours online, both system time and RTC time will equal true time.

Lets see how to check the system date and time in RHEL 7.0 before we configure the chronyd to maintain the system clock. In RHEL 7.0 we have a command # timedatectl to check the time and date information. here is the sample output.
timedatectl command output
timedatectl command has many sub options to set time date and other properties related to time and date. refer manpage for more information
Here is the few options :
To list timezones run the command # timedatectl list-timezones
timedatectl list-timezone 
To set the time and date using the following command.
# timedatectl set-time "2015-01-02 00:00:55"
timedatectl set-time
Lets verify the time again after settings it. run timedatectl command again.
timedatectl

Now lets configure NTP Client using chronyd to set the system clock.
First we need to install the chrony package using YUM . The chrony package provides a chronyd service daemon and chronyc utility . run the following command to install the chrony package.
# yum install chrony
yum chrony installation
Run #rpm -qlc chrony command to see the configuration files for chrony package.
chrony configuration files

Now edit the /etc/chrony.conf  file to  configure the NTP client. edit this file and add the NTP server details.
# vim /etc/chrony.conf
add the following line in this file :
server ntp1.vinzlinux.com iburst
 
There are few options we could give after mentioned in the NTP server details in  /etc/chrony.conf  here are they :
offline  If the server will not be reachable when chronyd is started, the offline option may be specified. chronyd will not try to poll the server until it is enabled to do so (by using the online option of chronyc).
auto_offline   If this option is set, the server will be assumed to have gone offline when 2 requests have been sent to it without receiving a response. This option avoids the need to run the offline (see section offline) command from chrony when disconnecting the dial-up link.
iburst   On start, make four measurements over a short duration (rather than the usual periodic measurements).
minstratum   When the synchronisation source is selected from available sources, sources with lower stratum are normally preferred. This option can be used to increase stratum of the source to the specified minimum, so chronyd will avoid selecting that source. This is useful with low stratum sources that are known to be unrealiable or inaccurate and which should be used only when other sources are unreachable.
polltarget   Target number of measurements to use for the regression algorithm which chronyd will try to maintain by adjusting polling interval between minpoll and maxpoll. A higher target makes chronyd prefer shorter polling intervals. The default is 6 and a useful range is 6 to 60.
prefer    Prefer this source over sources without prefer option.
noselect     Never select this source. This is particularly useful for monitoring.

After setting the NTP Server details in /etc/chrony.conf restart the chronyd deamon to get the effects.
# systemctl restart chronyd
systemctl restart chronyd
Check the service status using the following command :
# systemctl status chronyd
systemctl status chronyd

Enable the NTP using the following command.
 # timedatectl set-ntp yes

Now lets monitor the chronyd daemon using chronyc utility.
Run the command chronyc sources -v to display information about the current set of sources
chronyc sources -v
We can see that this server is now synced with the NTP server in our network.
To display the rate & offset estimation performance of sources run # chronyc sourcestats command
chronyc sourcestats
To display system clock performance run # chronyc tracking command.
chronyc tracking

Thats all about it . Hope this topic is useful to you ! Stay tuned for more updates on Linux configuration.


No comments:

Post a Comment