红联Linux门户
Linux帮助

ubuntu ntp时间同步

发布时间:2016-07-06 15:02:17来源:linux网站作者:mct123
1.在不装ntp时,ntpdate 命令是可以用的,且能与ntp服务器同步时间
root@wilson-software:~# date -s "18:22"  
Tue Jul  5 18:22:00 CST 2016  
root@wilson-software:~# ntpdate -d 202.108.6.95  
5 Jul 18:22:12 ntpdate[4439]: ntpdate 4.2.6p3@1.2290-o Tue Jun  5 20:12:12 UTC 2012 (1)  
Looking for host 202.108.6.95 and service ntp  
host found : xk-6-95-a8.bta.net.cn  
transmit(202.108.6.95)  
receive(202.108.6.95)  
transmit(202.108.6.95)  
receive(202.108.6.95)  
transmit(202.108.6.95)  
receive(202.108.6.95)  
transmit(202.108.6.95)  
receive(202.108.6.95)  
transmit(202.108.6.95)  
server 202.108.6.95, port 123  
stratum 2, precision -23, leap 00, trust 000  
refid [202.108.6.95], delay 0.18800, dispersion 0.04358  
transmitted 4, in filter 4  
reference time:    db26271d.a0ac71ba  Tue, Jul  5 2016 20:31:25.627  
originate timestamp: db262ab0.7833e87e  Tue, Jul  5 2016 20:46:40.469  
transmit timestamp:  db2608db.c66385a5  Tue, Jul  5 2016 18:22:19.774  
filter delay:  0.32901  0.32188  0.25488  0.18800   
0.00000  0.00000  0.00000  0.00000   
filter offset: 8660.688 8660.677 8660.649 8660.613  
0.000000 0.000000 0.000000 0.000000  
delay 0.18800, dispersion 0.04358  
offset 8660.613347  
5 Jul 18:22:21 ntpdate[4439]: step time server 202.108.6.95 offset 8660.613347 sec  
root@wilson-software:~# date 
Tue Jul  5 18:22:30 CST 2016  
root@wilson-software:~#
如上所示,设置错误时间后,用ntpdate -d 202.108.6.95 只能调试模式测试能否同步时间,但不会真正同步时间
root@wilson-software:~# date  
Tue Jul  5 18:22:30 CST 2016  
root@wilson-software:~# ntpdate 202.108.6.95  
5 Jul 20:52:33 ntpdate[4465]: step time server 202.108.6.95 offset 8660.555090 sec  
root@wilson-software:~# date 
Tue Jul  5 20:52:49 CST 2016  
ntpdate 202.108.6.95 可以同步时间
 
2.安装ntp后,ntp服务已经起来的情况下ntpdate 命令是不能用的,即不能通过ntpdate命令与其他时间服务器同步
root@wilson-software:~# date  
Tue Jul  5 20:57:07 CST 2016  
root@wilson-software:~# date -s "18:18"  
Tue Jul  5 18:18:00 CST 2016  
root@wilson-software:~# ntpdate 202.108.6.95  
5 Jul 18:18:09 ntpdate[5081]: the NTP socket is in use, exiting  
root@wilson-software:~# ps -ef|grep ntp  
ntp       5067     1  0 18:17 ?        00:00:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 120:129  
root      5091  2877  0 18:20 pts/0    00:00:00 grep --color=auto ntp  
root@wilson-software:~# date  
Tue Jul  5 18:20:31 CST 2016  
root@wilson-software:~#  
 
3.机器启动时ntp服务会起动并会与/etc/ntp.conf里配置的server同步时间(网上有人说时间比服务器快,则不能同步,证实是错误的)
 
4.具体参考:http://www.linuxdiyf.com/linux/10534.html
 
5.这行是时间服务器的层次。设为0则为顶级,执行ntpq -p是无效的,如果要向别的NTP服务器更新时间,请不要把它设为0
fudge 127.127.1.0 stratum 0  stratum
root@wilson-software:~# ntpq -p  
localhost: timed out, nothing received  
***Request timed out  
root@wilson-software:~# vi /etc/ntp.conf   
root@wilson-software:~# /etc/init.d/ntp restart  
* Stopping NTP server ntpd     [ OK ]   
* Starting NTP server ntpd     [ OK ]   
root@wilson-software:~# ntpq -p  
remote           refid      st t when poll reach   delay   offset  jitter  
time7.aliyun.co .INIT.          16 u    -   64    0    0.000    0.000   0.001  
dns1.synet.edu. .INIT.          16 u    -   64    0    0.000    0.000   0.001  
news.neu.edu.cn .INIT.          16 u    -   64    0    0.000    0.000   0.001  
time6.aliyun.co .INIT.          16 u    -   64    0    0.000    0.000   0.001  
juniperberry.ca .INIT.          16 u    -   64    0    0.000    0.000   0.001
 
本文永久更新地址:http://www.linuxdiyf.com/linux/22124.html