ubuntu系统中NTP服务配置

首先进行软件的安装:sudo apt-get install ntp

          sudo apt-get install ntpdate(手动校时软件)

然后修改ntp配置文件:sudo vim /etc/ntp.conf (/etc/inet/ntp.conf)

在配置文件中添加如下内容:

server 192.168.1.2 prefer  #上层对时服务器地址

server 202.112.10.36

server 127.127.1.0

fudge 127.127.1.0 stratum 8  #

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

修改完配置文件要先将NTP客户端和服务器端分别重启:sudo /etc/init.d/ntp restart (#svcaam disable ntp "停止ntp服务"   #svcaam enable ntp   )

最后在客户端命令行输入:ntpdate –u 192.168.1.2 进行手动校时,出现“sec”则表明时间同步成功。如果出现 no server suitable for synchronization found 则表示校时失败。可以在客户端输入:ntpdate –d 192.168.1.2 查看校时失败的原因。

 #编辑cron任务 

##sudo crontab -e 0 8,16 * * * /usr/sbin/ntpdate 192.168.1.79 (每天8点、16点自动进行对时)

 

 

遇到问题:

(一)root@xa1occ03-1 # ntpdate 192.1.100.1
3 Mar 14:42:16 ntpdate[10788]: the NTP socket is in use, exiting

此问题为存在已启动的ntpdate服务,重复启动导致。

 处理方案:通过lsof -i:123 来查看ntp服务的进程后,kill ntp的服务进程即可;

(二)

engineer@xa2occ17-1:/etc$ ntpdate -u 192.2.1.11
21 May 15:59:22 ntpdate[25375]: no server suitable for synchronization found
engineer@xa2occ17-1:/etc$ ntpdate -u 192.1.168.1

在ntp客户端运行ntpdate serverIP,出现no server suitable for synchronization found的错误。

在ntp客户端用ntpdate –d serverIP查看,发现有“Server dropped: strata too high”的错误,并且显示“stratum 16”。而正常情况下stratum这个值得范围是“0~15”。

 此问题有两种情况:1、客户端的ntp.conf文件配置有误。-----需重新修改配置文件

                                  2、服务端的ntp服务未启动。

# watch ntpq -p      ##查看对时情况

 

posted on 2022-03-04 11:01  暗夜、逝  阅读(2302)  评论(0编辑  收藏  举报

导航