NTP原理及配置使用
一、NTP简介
1.NTP简介
NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-50ms。(1s=1000ms) NTP服务器就是利用NTP协议提供时间同步服务的。
2.NTP原理 NTP客户端可以定时自动向NTP服务器发送请求来获取时间,NTP服务器将时间发送给客户端,。 NTP服务器的时间来源有两个1.网络时间
2.NTP服务器自己的时间 2.NTP架构 C/S 二、部署NTP服务端
1.NTP安装
[root@web02 ~]# yum install ntp -y
restrict efault ignore 设置默认策略,允许任意主机进行时间同步
2)server 表示当前NTP服务从哪个主机来获取时间 默认的ntp地址 server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst 常用的ntp地址 server ntp1.aliyun.com #→阿里云时间服务器(ntp1...21等) server time.nist.gov #→微软时间服务器 3)fudge 设置你的ntp优先级 4)statsdir logfile 指定日志文件的位置 3.修改NTP配置文件
【此例使用ntp本机时间作为时间源】
[root@web02 ~]# cd /etc/
[root@web02 etc]# mv ntp.conf ntp.conf.bak
[root@web02 etc]#cat > ntp.conf<<eof
server 127.127.1.0
restrict 127.0.0.1
restrict 10.0.0.0 mask 255.255.255.0
fudge 127.127.1.1 startnum 10
statsdir /var/log/ntp/
logfile /var/log/ntp/ntp.log
eof
[root@web02 etc]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 5 l 1 64 1 0.000 0.000 0.000
[root@web02 etc]# ntpstat
synchronised to local net at stratum 6
time correct to within 7948 ms
polling server every 64 s
启动ntp会报错:
[root@test ~]# yum install ntpdate
[root@test ~]# crontab -e
*/5 * * * * /usr/sbin/ntpdate 10.0.0.7 >/dev/null 2>&1