適用於臨時校時或測試環境:
# 同步至 NIST 時間伺服器
ntpdate time.nist.gov
# 設定時區為上海(刪除舊連結後重建)
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 編輯系統 crontab
vi /etc/crontab
# 每天 00:00 同步一次
0 0 * * * root rdate -s time.nist.gov
rpm -ivh ntp-4.1.2-4.EL3.1.i386.rpm(現代系統用 yum install ntp)/etc/ntp.conf:
# 註釋預設拒絕所有
# restrict default ignore
# 允許內網 192.168.10.0/24 同步,不信任、不修改、不陷阱
restrict 192.168.10.0 mask 255.255.255.0 notrust nomodify notrap
/etc/ntp/step-tickers 加入上層時間源:pool.ntp.orgservice ntpd startnetstat -an | grep 123ntpdate 192.168.10.1crontab -e → 加入 */10 * * * * /usr/sbin/ntpdate 192.168.10.1CentOS 7+/RHEL 7+ 預設採用 chronyd 取代 ntpd,優勢在於:
server ntp.aliyun.com iburst遷移命令:yum install chrony && systemctl enable --now chronyd