rdate 透過 RFC 868 Time Protocol (TCP/37) 同步時間,輕量簡單,適合不需 NTP 複雜功能的場景。本文涵蓋外部同步、內網架設時間伺服器與定時校正。
rdate -s tick.greyware.com # 知名公共時間源
# 或其他:time.nist.gov, time.windows.com
寫入 /etc/cron.hourly/rdate-sync 每小時校正:
#!/bin/bash
rdate -s tick.greyware.com >/dev/null 2>&1
hwclock -w # 同步至硬體時鐘
加執行權限 chmod +x。
以 CentOS 為例:
yum install -y xinetd/etc/xinetd.d/time-stream,將 disable = yes 改為 noservice xinetd start,並設開機啟動 chkconfig xinetd on此時該機器監聽 TCP/37,其他機器可用 rdate -s 伺服器IP 同步。
| 特性 | rdate | ntpd/chronyd |
|---|---|---|
| 協議 | RFC 868 (TCP/37) | NTP (UDP/123) |
| 精度 | 秒級 | 毫秒/微秒級 |
| 平滑調整 | 無 (階躍) | 有 (漸變) |
| 認證/加密 | 無 | 支援 |
| 適用場景 | 簡單同步、嵌入式、隔離網 | 生產叢集、資料庫、金融 |
rdate 階躍調整可能導致日誌時間倒流/跳躍,敏感應用慎用chronyd (RHEL 7+ 預設) 或 systemd-timesyncdhwclock -w 需 root,虛擬機中可能無效rdate 適合快速部署、資源受限環境;生產核心業務請使用 NTP 體系。