NTP配置

1,安装NTP

[root@localhost ~]# yum install ntp
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
cdrom                                                                 | 4.1 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-18.el7 will be installed
--> Processing Dependency: ntpdate = 4.2.6p5-18.el7 for package: ntp-4.2.6p5-18.el7.x86_64
--> Processing Dependency: libopts.so.25()(64bit) for package: ntp-4.2.6p5-18.el7.x86_64
--> Running transaction check
---> Package autogen-libopts.x86_64 0:5.18-5.el7 will be installed
---> Package ntpdate.x86_64 0:4.2.6p5-18.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================
 Package                   Arch             Version                    Repository       Size
=============================================================================================
Installing:
 ntp                       x86_64           4.2.6p5-18.el7             cdrom           539 k
Installing for dependencies:
 autogen-libopts           x86_64           5.18-5.el7                 cdrom            66 k
 ntpdate                   x86_64           4.2.6p5-18.el7             cdrom            82 k

Transaction Summary
=============================================================================================
Install  1 Package (+2 Dependent packages)

Total download size: 687 k
Installed size: 1.6 M
Is this ok [y/d/N]: y
Downloading packages:
---------------------------------------------------------------------------------------------
Total                                                         10 MB/s | 687 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : autogen-libopts-5.18-5.el7.x86_64                                         1/3 
  Installing : ntpdate-4.2.6p5-18.el7.x86_64                                             2/3 
  Installing : ntp-4.2.6p5-18.el7.x86_64                                                 3/3 
  Verifying  : ntpdate-4.2.6p5-18.el7.x86_64                                             1/3 
  Verifying  : autogen-libopts-5.18-5.el7.x86_64                                         2/3 
  Verifying  : ntp-4.2.6p5-18.el7.x86_64                                                 3/3 

Installed:
  ntp.x86_64 0:4.2.6p5-18.el7                                                                

Dependency Installed:
  autogen-libopts.x86_64 0:5.18-5.el7             ntpdate.x86_64 0:4.2.6p5-18.el7            

Complete!
View Code

2,编辑NTP配置文件"/etc/ntp.conf"

[root@localhost ~]# vim /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 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 ::1

# Hosts on local network are less restricted.
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap  //允许"192.168.1.0"使用NTP服务,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.rhel.pool.ntp.org iburst
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
server 0.asia.pool.ntp.org   //NTP官方服务器池:http://www.pool.ntp.org/zone/asia 
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.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

# 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

# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

  logfile /var/log/ntp.log

3,验证服务器时间同步

[root@localhost ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+pontoon.latt.ne 253.235.63.48    3 u   21   64    1  317.764  -25.597   0.000
+106.185.48.114  157.7.235.92     3 u   21   64    1  203.775   30.158   0.000
*160.16.201.66   103.1.106.69     2 u   30   64    1  180.811  -49.994   0.000
 linode.dev.fawo 118.189.211.186  2 u   39   64    1  201.558  -14.302   0.000
[root@localhost ~]# ntpstat  //查看NTP服务器是否配置正确
synchronised to NTP server (160.16.201.66) at stratum 3 
   time correct to within 4090 ms
   polling server every 64 s

4,在Linux客户端验证

[root@localhost ~]# ntpdate -u 192.168.1.10
18 Feb 12:45:50 ntpdate[2835]: adjust time server 192.168.1.10 offset -0.000051 sec
[root@localhost ~]# date
Thu Feb 18 12:45:54 CST 2016

 

你可能感兴趣的:(NTP配置)