linux ntpd时间同步

主:

# yum install -y ntp ntpdate # cat /etc/ntp.conf driftfile /var/lib/ntp/drift restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict ::1 server ntp1.aliyun.com iburst includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor # systemctl start ntpd # ntpq -p
# timedatectl

从:

# yum install -y ntp ntpdate # cat /etc/ntp.conf driftfile /var/lib/ntp/drift restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict ::1 server 主IP iburst includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor # systemctl start ntpd # ntpq -p # timedatectl

同步没成功:

# timedatectl status       Local time: Tue 2022-04-26 21:46:24 CST   Universal time: Tue 2022-04-26 13:46:24 UTC         RTC time: Tue 2022-04-26 13:45:13        Time zone: Asia/Shanghai (CST, +0800)      NTP enabled: yes NTP synchronized: no  RTC in local TZ: no       DST active: n/a

解决:

# systemctl stop ntpd # ntpd -gq ntpd: time slew +0.000041s # systemctl start ntpd 等待一会儿后,NTP synchronized恢复成yes: # timedatectl