【纯离线】Ubuntu离线安装ntp时间同步服务

Ubuntu离线安装ntp服务

准备阶段:下载安装包
apt-get download ntp
apt-get download ntpdate
在这里插入图片描述

一、服务端( 192.166.6.xx)
1、环境准备
先判断是否已安装 systemd-timesyncd
systemctl is-active systemd-timesyncd
如果返回结果是 active,则表示 systemd-timesyncd 已经在运行。在这种情况下,你可以使用以下命令停止并卸载它:
sudo systemctl stop systemd-timesyncd
sudo systemctl disable systemd-timesyncd
sudo apt-get remove systemd-timesyncd
如果返回inactive,则表示 systemd-timesyncd没有在运行,可直接安装ntp
2、安装
sudo dpkg -i ntp包
sudo dpkg -i ntpdate包

2、编辑配置文件/etc/ntp.conf

# /etc/ntp.conf, NTP服务配置文件
# 指定 drift 文件的位置,它用于存储系统时钟的漂移信息
driftfile /var/lib/ntp/ntp.drift
# 指定闰秒的定义文件
leapfile /usr/share/zoneinfo/leap-seconds.list
# 启用统计数据记录,以便进行性能监控
statistics loopstats peerstats clockstats
# 定义日志文件的生成,可以在文件中存储不同类型的统计信息
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
# 配置本地系统的时钟作为 NTP 时间服务器
# 127.127.1.0 表示本地时钟 每16秒向本地时钟服务器发出一次查询
server 127.127.1.0 minpoll 4 maxpoll 4
# 设置本地时钟的层级,stratum 值表示时间源的等级
# stratum 0 是最高等级,通常不应该更改
fudge 127.127.1.0 stratum 5
# 使用 Ubuntu 提供的 NTP 服务器作为备用时间源
#pool ntp.ubuntu.com
# 限制外部访问,不允许未授权的操作
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
# 允许本地主机 127.0.0.1 访问 NTP 服务
restrict 127.0.0.1
# 允许 IPv6 本地主机 ::1 访问 NTP 服务
restrict ::1
# 不允许外部主机修改或请求服务器的状态信息
restrict source notrap nomodify noquery

3、重启
service ntp restart

二、客户端(192.168.228.xx)
1、环境准备
先判断是否已安装 systemd-timesyncd
systemctl is-active systemd-timesyncd
如果返回结果是 active,则表示 systemd-timesyncd 已经在运行。在这种情况下,你可以使用以下命令停止并卸载它:
sudo systemctl stop systemd-timesyncd
sudo systemctl disable systemd-timesyncd
sudo apt-get remove systemd-timesyncd
如果返回inactive,则表示 systemd-timesyncd没有在运行,可直接安装ntp
2、安装
sudo dpkg -i ntp包
sudo dpkg -i ntpdate包

3、编辑配置文件/etc/ntp.conf

# 指定 drift 文件的位置,用于存储系统时钟漂移信息
driftfile /var/lib/ntp/drift

# 针对默认配置,限制 NTP 服务的访问权限,阻止外部修改服务器状态
restrict default kod limited nomodify notrap nopeer noquery
# 允许本地主机 127.0.0.1 访问 NTP 服务
restrict 127.0.0.1
# 允许 IPv6 本地主机 ::1 访问 NTP 服务
restrict ::1
# 限制特定 IP 地址 192.166.6.47 访问,但不允许修改或请求服务器状态
restrict 192.166.6.47 nomodify notrap noquery
# 配置 NTP 服务器的地址
server 192.166.6.47
# 包含文件,通常用于加密配置信息
includefile /etc/ntp/crypto/pw
# 指定 NTP 密钥文件的位置
keys /etc/ntp/keys
# 禁用监视器功能
disable monitor

4、重启
service ntp restart
5、手动更新系统的时钟
ntpdate -d 192.166.6.xx

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值