配置Ubuntu内网NTP对时

1,071 阅读1分钟

一、服务端配置(本次配置服务端IP为192.168.2.222)

1、安装ntp服务

sudo apt-get install ntp

2.修改配置文件 /etc/ntp.conf

(1)
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
#linux自带的时间同步,需要注释掉
#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst

(2)
# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
restrict 192.168.2.222 mask 255.255.255.0 nomodify notrap

3.重启服务

service ntp restart

二、客户端配置

1.安装ntpdate

sudo apt-get install ntpdate

2.编辑crontab

sudo vim /etc/crontab

最后一行追加

*/5 * * * * root     sudo ntpdate 192.168.2.222  //使用root用户5分钟自动对时一次

三、问题

1.  16 Oct 22:59:49 ntpdate[2392]: no server suitable for synchronization found

这很可能是服务还未启动好,需要耐心等待5-10分钟
除此之外,还有可能是防火墙/配置文件存在notrust属性
restrict 192.168.50.0 mask 255.255.255.0 notrust

2.the NTP socket is in use, exiting
执行下面命令
sudo /etc/init.d/ntp stop
sudo ntpdate 120.25.2.222

3.Failed to restart ntpd.service: Unit ntpd.service not found.
执行下面命令
apt install ntpdate
apt install ntp
ntpdate -u "in.pool.ntp.org"
sudo service ntp restart

四、相关链接

1、 链接1 2、 链接2 3、 链接3