How to Install and Configure NTP Server On CentOS 6.2

In this post, i will show you on how to configure NTP server for time adjustment. NTP, Network Time Protocol, it is an Internet protocol used to synchronize the clocks of computers or servers to some NTP server on internet or intranet.

Install the following package using yum :

    [root@centos62 ~]# yum install ntp -y
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: centos.maulvi.net
     * extras: centos.maulvi.net
     * updates: centos.maulvi.net
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package ntp.i686 0:4.2.4p8-2.el6.centos will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ====================================================================================================
     Package       Arch           Version                          Repository                      Size
    ====================================================================================================
    Installing:
     ntp           i686           4.2.4p8-2.el6.centos             CentOS6.2-Repository           436 k
    
    Transaction Summary
    ====================================================================================================
    Install       1 Package(s)
    
    Total download size: 436 k
    Installed size: 1.1 M
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing : ntp-4.2.4p8-2.el6.centos.i686                                                    1/1
    
    Installed:
      ntp.i686 0:4.2.4p8-2.el6.centos
    
    Complete!
    

Once NTP is installed you need to update the configuration file, ntp.conf located in the /etc directory :

    [root@centos62 ~]# vi /etc/ntp.conf
    
    # For more information about this file, see the man pages
    # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
    
    driftfile /var/lib/ntp/drift
    
    # Permit time synchronization with our time source, but do not
    # permit the source to query or modify the service on this system.
    restrict default kod nomodify notrap nopeer noquery
    restrict -6 default kod nomodify notrap nopeer noquery
    
    # Permit all access over the loopback interface.  This could
    # be tightened as well, but to do so would effect some of
    # the administrative functions.
    restrict 127.0.0.1
    restrict -6 ::1
    
    # Hosts on local network are less restricted.
    restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
    
    # Use public servers from the pool.ntp.org project.
    # Please consider joining the pool (http://www.pool.ntp.org/join.html).
    server 0.centos.pool.ntp.org
    server 1.centos.pool.ntp.org
    server 2.centos.pool.ntp.org
    
    #broadcast 192.168.1.255 autokey        # broadcast server
    #broadcastclient                        # broadcast client
    #broadcast 224.0.1.1 autokey            # multicast server
    #multicastclient 224.0.1.1              # multicast client
    #manycastserver 239.255.254.254         # manycast server
    #manycastclient 239.255.254.254 autokey # manycast client
    
    # Undisciplined Local Clock. This is a fake driver intended for backup
    # and when no outside source of synchronized time is available.
    #server 127.127.1.0     # local clock
    #fudge  127.127.1.0 stratum 10
    
    # Enable public key cryptography.
    #crypto
    
    includefile /etc/ntp/crypto/pw
    
    # Key file containing the keys and key identifiers used when operating
    # with symmetric key cryptography.
    keys /etc/ntp/keys
    
    # Specify the key identifiers which are trusted.
    #trustedkey 4 8 42
    
    # Specify the key identifier to use with the ntpdc utility.
    #requestkey 8
    
    # Specify the key identifier to use with the ntpq utility.
    #controlkey 8
    
    # Enable writing of statistics records.
    #statistics clockstats cryptostats loopstats peerstats
    

Start the NTP service :

    [root@centos62 ~]# /etc/rc.d/init.d/ntpd start
    Starting ntpd:                                             [  OK  ]
    

Set NTP service start at boot :

    [root@centos62 ~]# chkconfig ntpd on
    
    [root@centos62 ~]# ntpq -p
    
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
     113.23.142.94   202.71.100.89    5 u   33   64    1   55.809  35573.8   0.001
     enterprise.wyne 203.129.68.14    3 u   32   64    1   55.888  35592.2   0.001
     202.71.100.89   124.82.204.2     4 u   31   64    1   54.479  35584.8   0.001
    

To verify the NTP service is now running on the server using the following command :

    [root@centos62 ~]# ps -ef | grep ntpd
    ntp      22682     1  0 22:38 ?        00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
    root     22696  2377  0 22:40 pts/0    00:00:00 grep ntpd
    

The command should return two lines showing that the ntpd process is running and the ntpd grep process you executed

    [root@centos62 ~]# service ntpd status
    ntpd (pid  22682) is running...
    
    [root@centos62 ~]# watch ntpq -c lpee
    
    Every 2.0s: ntpq -c lpee                                                    Tue Feb  7 23:00:24 2012
    
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
     ns2.epiweb.com. .RMOT.          16 u    -   64    0    0.000    0.000   0.000
     zephyr.vtsv.com .INIT.          16 u    -   64    0    0.000    0.000   0.000
    

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *