Monday, 8 July 2013

Centos 6/RHEL install and use OpenNTPD local clock sync

If using the Centos 6 minimal installation you may want to find a way of syncronising your local system clock if you are not using the bells and whistles of a full desktop environment.

You can do this using OpenNTPD which is a free implementation of the Network Time Protocol. It provides the ability to sync the local clock to remote NTP servers and can act as NTP server, redistributing the local clock.

Installing is just a matter of downloading the tar.gz, building it and setting up a few configuration files. 

Intall wget if not already there and as always when compiling source files make sure you have set up kernels and build tools.

$ sudo yum -y install wget

$ cd /tmp

$ wget ftp://ftp.openbsd.org/pub/OpenBSD/OpenNTPD/openntpd-3.9p1.tar.gz
 

$ tar xvf openntpd-3.9p1.tar.gz

$ cd openntpd-3.9p1


$ ./configure  

$ make

$ sudo make install

Set up the config files

 
$ sudo groupadd _ntp


$ sudo useradd -g _ntp -s /sbin/nologin -d /var/empty -c 'OpenNTP daemon' _ntp

Install startup script

$ sudo cp
contrib/redhat/ntpd /etc/init.d/openntpd

$ sudo chmod +x /etc/init.d/openntpd

Edit the scripts

# vi /etc/init.d/openntpd

add the following before prog="ntpd"

PATH=/usr/local/sbin:$PATH


Close, save and then edit ntpd.conf

# vi /usr/local/etc/ntpd.conf

Edit /usr/local/etc/ntpd.conf

Listen localhost and the main IP then sync to ntp server


listen on 127.0.0.1
listen on 192.168.0.100

Then further down the file
 

servers pool.ntp.org
Close and save


Start OpenNTPD

$ sudo service openntpd start

$ sudo service openntpd stop

$ sudo service openntpd restart

Start on reboot


# chkconfig openntpd on

Check ntpd is running


$ sudo service openntpd status

$ sudo netstat -tulpn


$ sudo netstat -tulpn | grep :123

And you can also use the ntpstat command as follows


$ ntpstat
synchronised to NTP server (85.31.186.170) at stratum 3
   time correct to within 58 ms
   polling server every 256 s


You can now run the clock on the command line and obtain the correct time.

$ sudo /sbin/clock
Mon 08 Jul 2013 07:42:23 AM BST  -0.828329 seconds


No comments:

Post a Comment