1,安装NTP
[[email protected] ~]# 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!
2,编辑NTP配置文件"/etc/ntp.conf"
[[email protected] ~]# 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,验证服务器时间同步
[[email protected] ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *time2.maxonline .GPS. 1 u 9 64 1 270.619 50.820 0.000 103.245.79.18 218.186.3.36 2 u 8 64 1 148.754 -32.530 0.000 ns2.cidc.com.kh 95.222.122.210 2 u 7 64 1 127.239 -11.423 0.000 sun.wktk.co 103.1.106.69 2 u 7 64 1 184.235 35.286 0.000 [[email protected] ~]# date -R Thu, 18 Feb 2016 12:14:14 +0800
4,在Linux客户端验证
[[email protected] ~]# ntpdate -u 192.168.1.10 18 Feb 12:45:50 ntpdate[2835]: adjust time server 192.168.1.10 offset -0.000051 sec [[email protected] ~]# date Thu Feb 18 12:45:54 CST 2016
时间: 2024-10-14 13:56:21