ubuntu16.04.3 ntp服务

搭建NTP服务器,下端的设备都主动向服务器对时,保持整个系统的时间同步。下端设备采用NTP客户端 ntpd,(注:这个之前已经测试过,NTP服务器在win7系统),现在ubuntu上搭建NTP服务器。

ubuntu版本:
由于公司架构需求部分服务器走内部网络,这部分服务器均无外部网络,导致存在一个问题就是时间无法进行同步,于是网上找了下资料可以通过搭建ntp服务器来解决这问题

1、安装NTP

   sudo apt-get install ntp

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

#增加了NTP服务器自身到时间服务器的同步

            fudge 127.127.1.0 stratum 8 ---这是wdr后加的,不知道是否可用?

    restrict -4 default kod notrap nomodify nopeer noquery

    restrict -6 default kod notrap nomodify nopeer noquery

    restrict 192.168.10.0 mask 255.255.255.0 nomodify

restrict 133.16.157.34  --- #增加了一些需要同步的客户端的ip
            restrict 133.16.157.36 --- #增加了一些需要同步的客户端的ip
              主要是在配置文件中的:

  restrict -6 default kod notrap nomodify nopeer noquery

  语句后面加入:

  restrict 192.168.10.0 mask 255.255.255.0 nomodify

  restrict 192.168.10.0 mask 255.255.255.0 nomodify---主要是允许能同步的服务器所在的内部网段

3、如果有设置防火墙必须取消对123端口的限制

iptables -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT

4、重启ntp服务

sudo /etc/init.d/ntp restart

5、客户端同步(也就是要进行同步的内网服务器)

sudo ntpdate 192.168.10.2  (ntp Server)

可同时查看服务器的硬件时钟并进行更改:

sudo hwclock
sudo hwclock -w

客户端同时时出现:no server suitable for synchronization found 错误提示

原因:

在ntp server上重新启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令时会产生no server suitable for synchronization found的错误。如5分钟后,再在客户端执行ntpdate 192.168.10.2,提示同步完成。

那么如何知道何时ntp server完成了和自身同步的过程呢?

在ntp server上使用命令:

#ntpq -p

7、客户端配置
如果你以为上面配置好了,局域网段的服务器就能和这台ntp server自动时间同步了,那就太天真了。
还需要在需要同步时间的每台客户端上安装ntp, sudo apt-get install ntp,然后修改vim /etc/ntp.conf,增加server 192.168.10.2,

然后重启客户端的ntp服务,sudo /etc/init.d/ntp restart,这样客户端就能和ntp server 进行时间同步了。

点赞

ubuntu16.04.3 ntp服务无法正常启动的修复

在ubuntu16的节点执行

rm -f /etc/network/if-up.d/ntpdate
mkdir -p /etc/systemd/system/ntp.service.d/

在该目录添加文件 restart.conf 内容为

[Service]
Type=forking
PIDFile=/var/run/ntpd.pid
RemainAfterExit=no
Restart=always
RestartSec=1s

添加完成后执行,加载配置

systemctl daemon-reload

手动重启下ntp

service ntp restart

扩展

1、如果有设置防火墙必须取消对123端口的限制

iptables -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT

参考链接 :

ubuntu16.04.3 ntp服务无法正常启动的修复 : https://www.jianshu.com/p/50cc2b578a55

https://blog.csdn.net/wdr2003/article/details/81977147

发布了313 篇原创文章 · 获赞 57 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/qq_40907977/article/details/104147580