Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

CentOS 時間同步最佳實踐:NTP 部署與定時校準

編輯:關於伺服器

核心步驟三部曲

  1. 設定時區:cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime(+8 區)
  2. 安裝 NTP 客戶端:yum install -y ntp(含 ntpdate)
  3. 手動同步一次:ntpdate cn.pool.ntp.org(推薦國內源)

自動化:加入 Crontab 定時任務

crontab -e
# 每 10 分鐘同步一次,日誌打標籤便於追蹤
0-59/10 * * * * /usr/sbin/ntpdate cn.pool.ntp.org | logger -t NTP

優質國內 NTP 服務器推薦

服務器地址運營單位備註
ntp.aliyun.com阿里雲雲服務器首選,低延遲
ntp.tencent.com騰訊雲同理
cn.pool.ntp.orgNTP 池項目自動就近分配
time.windows.com微軟兼容性好
210.72.145.44中國國家授時中心官方權威源

進階:部署本地 NTP 服務器(局域網環境)

若管理數十台機器,建議搭建一台內網 NTP Server,其他機器指向它同步,減少公網流量並提升精度:

# Server 端 /etc/ntp.conf 關鍵配置
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
server cn.pool.ntp.org prefer iburst
# Client 端只需指向 Server IP
server 192.168.1.100 iburst

常見坑點提醒

  • 防火牆放行 UDP 123:firewall-cmd --add-port=123/udp --permanent
  • 虛擬機時間漂移:關閉宿主機時間同步,由 Guest OS 直接對外同步。
  • ntpdate vs ntpd:前者一次性校準(大步調整),後者漸進式調整(生產環境推薦運行 ntpd 守護進程)。

驗證同步狀態

ntpq -p
# 輸出中 * 表示當前同步源,+ 表示候選,達標條件:reach 377、delay/jitter 較小
Copyright © Windows教程網 All Rights Reserved