Ubuntu-安装部署ntp

服务端

apt-get update

apt-get install ntp

apt-get install ntpdate

启动ntp服务

service ntp start

查看服务状态

‘systemctl status ntp

  • 停止systemd-timesyncd服务

systemctl stop systemd-timesyncd.service

  • 防止systemd-timesyncd服务开机自启

systemctl disable systemd-timesyncd.service

正确时区

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

查看是否正确

date

编辑配置文件

vim /etc/ntp.conf

最后加上

限制只允许10.60.0.0网段的主机访问本服务器(机器ip是10.60.81.86)

restrict 10.60.0.0 mask 255.255.255.0 nomodify notrap

重启

sudo systemctl restart ntp
查看服务状态

sudo systemctl status ntp
这里服务端就设置好了。客户端用来同步服务端的时间

客户端

apt-get update

apt-get install ntp

apt-get install ntpdate

启动ntp服务

service ntp start

查看服务状态

‘systemctl status ntp

  • 停止systemd-timesyncd服务

systemctl stop systemd-timesyncd.service

  • 防止systemd-timesyncd服务开机自启

systemctl disable systemd-timesyncd.service

编辑配置文件

sudo vi /etc/ntp.conf
注释掉公共NTP服务配置

# 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

# pool ntp.ubuntu.com

在这些注释掉的服务器后,添加一行新的服务器配置,指定你要同步的服务器 10.60.81.86

server 10.60.81.86 prefer iburst

重启

sudo systemctl restart ntp

查看同步状态

ntpq -p

如果希望它在每次启动时自动启动,请启用该服务:

sudo systemctl enable ntp