• 【纯离线】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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    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
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

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

  • 相关阅读:
    Java 进阶多线程(一)
    关于制作一个Python小游戏(三)
    SpringBoot整合JUnit、MyBatis、MyBatis-plus、Druid详解
    pojo层、dao层、service层、controller层的作用
    Windows10用Navicat 定时备份报错80070057
    嘿!selenium自动下载driver版本,得知道一下
    基于ARM+FPGA+AD的多通道精密数据采集仪方案
    如何使用Jupyter Notebook
    PyTorch微调终极指南1:预训练模型调整
    【无标题】
  • 原文地址:https://blog.csdn.net/qq_44890458/article/details/134053801