1. 安装NTP软件
- yum -y install ntp
- or
- tar zxvf ntp-4.2.6p5.tar.gz
- cd ntp-4.2.6p5
- ./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
- make && make install
- cd ..
2. 同步NTP服务器时间
- [root@ ntp-4.2.6p5]# ntpdate ntp.api.bz
- 13 Apr 16:22:00 ntpdate[26620]: adjust time server 219.239.93.23 offset 0.004556 sec
3. 自动与权威NTP服务器同步时间
- [root@ ntp-4.2.6p5]# crontab -l
- */5 * * * * /usr/sbin/ntpdate ntp.api.bz
4. 编辑ntp.conf配置文件
- # kod是指kiss o'death的意思
- # 现在越来越多的主机都指向了同一台NTP服务器, 从而造成每秒有大量的NTP Request信息
- # 即client访问server时, server会告诉client不要来找我, 之后client会询问另一台server, 或等一段时间再询问server
- # nomodify: client不能修改NTP服务器的时间参数
- # notrap: client不能通过trap远程登录
- # nopeer: 不清楚, 有知道的朋友跟帖回复
- # noquery: client不能通过ntpq, ntpc等查询NTP服务器信息
- # -4 Force DNS resolution of following host names to the IPv4 namespace.
- # -6 Force DNS resolution of following host names to the IPv6 namespace.
- restrict default kod nomodify notrap nopeer noquery
- # restrict -6 default kod nomodify notrap nopeer noquery
- # restrict ntp.api.bz
- # restrict 210.72.145.44
- restrict 127.0.0.1
- restrict 172.31.11.0 mask 255.255.255.0
- # Hosts on local network are less restricted.
- #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
- server ntp.api.bz prefer
- server 210.72.145.44
- server 127.127.1.0 # local clock
- fudge 127.127.1.0 stratum 10
- driftfile /var/lib/ntp/drift
- 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
- logfile /var/log/ntp.log # 日志信息
- broadcastdelay 0.008 # 广播延迟时间
- SYNC_HWCLOCK=yes # BIOS时间同步
5. 开启NTP服务器
- [root@ ntp-4.2.6p5]# service ntpd start
- Starting ntpd: [ OK ]
- or
- [root@ ntp-4.2.6p5]# /usr/local/ntp/bin/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid
- [root@ ntp-4.2.6p5]# ps -ef | grep ntp
- root 27562 1 0 16:56 ? 00:00:00 /usr/local/ntp/bin/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid
6. 查看NTP服务器与权威NTP服务器的关系
- [root@ ntp-4.2.6p5]# ntptrace -n ntp.api.bz
- ntp.api.bz: stratum 3, offset -0.001246, synch distance 0.115837
- 218.75.4.130: stratum 2, offset 0.002165, synch distance 0.105875
- 66.220.9.122: stratum 1, offset -0.000004, synch distance 0.000447, refid 'CDMA'
7. 查看NTP服务器与权威NTP服务器的状态
- [root@ ntp-4.2.6p5]# ntpq -p
- remote refid st t when poll reach delay offset jitter
- ==============================================================================
- *219.239.93.23 218.75.4.130 3 u 128 128 377 4.239 40.777 8.788
- +210.72.145.44 .ACTS. 1 u 9 64 163 27.135 36.602 25.212
- LOCAL(0) .LOCL. 10 l 800 64 0 0.000 0.000 0.000
