当host1可以连接网络时间同步服务器,则
$ ntpd pool ntp.ubuntu.com
当host1不能连接外网,则手动调整时间
$ date -s ‘2008-05-23 01:01:01’
$ vim /etc/ntp.conf
添加如下三行:
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
restrict 192.168.1.6 mask 255.255.255.0 nomodify notrap
前两行表示将本地的硬件时间也作为同步的时间源之一,这样在不联网的时候可以把本机时间作为同步时间源, 在内网环境下,可以把配置文件中其他的server都删除掉。
第三行表示对客户端的限制,IP+mask表示允许网段的客户端,
其中parameter的参数主要有: ignore : 拒绝所有类型的ntp连接 nomodify : 客户端不能使用ntpc与ntpq两支程式来修改服务器的时间参数 noquery : 客户端不能使用ntpq、ntpc等指令来查询服务器时间,等于不提供ntp的网络校时 notrap : 不提供trap这个远程时间登录的功能 notrust : 拒绝没有认证的客户端 nopeer : 不与其他同一层的ntp服务器进行时间同步
查看systemd-timesyncd是否已注册到service列表中:
$ systemctl list-unit-files --type=service
如果没有,则:
$ systemctl daemon-reload
如果还没有,则可能是ntpd与ntpdate或者chrony冲突了,需要全部卸载,再重装ntpd的deb。
如果正常,则启动:
$ sudo service systemd-timesyncd start
设置ntpd开机自启动:
$ chkconfig ntpd on
$ date -s “2020-01-01 08:08:08”
$ vim /etc/ntp.conf
删除其他的server 开头的配置项,这里一定要删除,只同步我们配置的那台服务器,添加上面设置的NTP服务器地址 :
server 192.168.1.100
与1.3相同
$ ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================