服务器
首先是安装:
sudo apt-get install ntp
修改配置文件(ntp仅有的配置文件):
sudo vi /etc/ntp.conf
# 如果进行局域网配置,可参考如下:
# Specify one or more NTP servers.
server 192.168.0.100 #这个是该ntp server 的上层server
# 配置可以访问该server的网段
restrict 192.168.5.0 mask 255.255.255.0 nomodify notrap
# 如果可以联网,可配置公用的NTP server:
# Specify one or more NTP servers.
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
配置完成重启ntp 服务:
sudo /etc/init.d/ntp restart
查看ntp 运行状态
ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*192.168.0.100 LOCAL(0) 11 u 209 256 377 0.131 0.793 0.226
LOCAL(0) .LOCL. 10 l 108m 64 0 0.000 0.000 0.000
客户端
客户端同样安装ntp 服务,进行配置:
sudo vi /etc/ntp.conf
只需增加 server 即可。
配置完成,手动进行时间同步:
ntpdate -u 192.168.0.x
查询命令:
ntpdc -n -c lispeers 192.168.0.x
ntpdc -n -c monlist 192.168.0.x
常用的时间服务器地址
http://www.pool.ntp.org/zone/cn
参考链接:
http://blog.csdn.net/wzy_1988/article/details/8629304
http://acooly.iteye.com/blog/1993484