Files
Linux/Docs/NTP时间同步.md
offends cee91802b3
Some checks failed
continuous-integration/drone Build is failing
synchronization
2025-08-25 15:57:40 +08:00

1.7 KiB

本文作者:丁辉

NTP时间同步

节点名称 IP
ntp-master(NTP服务器) 192.168.1.100
node-1 192.168.1.10
node-2 192.168.1.20
node-3 192.168.1.30

基础环境配置

安装 ntp 服务

  • Centos

    yum -y install ntp
    
  • Ubuntu

    apt -y install ntp
    

NTP服务器配置

  1. 修改配置文件

    cp /etc/ntp.conf /etc/ntp.conf.bak
    vi /etc/ntp.conf
    

    修改配置文件内容如下

    ##server 0.centos.#pool.ntp.org iburst
    ##server 1.centos.#pool.ntp.org iburst
    ##server 2.centos.#pool.ntp.org iburst
    ##server 3.centos.#pool.ntp.org iburst
    server 127.127.1.0
    

    填写 127.127.1.0 是一个特殊的IP地址, 代表本地主机(即自己) 或 填写其他授时中心服务器地址

  2. 启动 ntpd 服务

    systemctl enable ntpd
    systemctl start ntpd
    

其他节点同步 NTP 服务器时间

  1. 修改配置文件

    cp /etc/ntp.conf /etc/ntp.conf.bak
    vi /etc/ntp.conf
    

    修改配置文件内容如下

    ##server 0.centos.#pool.ntp.org iburst
    ##server 1.centos.#pool.ntp.org iburst
    ##server 2.centos.#pool.ntp.org iburst
    ##server 3.centos.#pool.ntp.org iburst
    server 192.168.1.100
    

    192.168.1.100 为 NTP 服务器 IP 地址

  2. 启动 ntpd 服务

    systemctl enable ntpd
    systemctl start ntpd
    
  3. 启动 ntpd 服务

    systemctl enable ntpd
    systemctl start ntpd
    
  4. 查看状态

    ntpq -p