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
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值