Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Linux 時間同步服務搭建:rdate 客戶端與 xinetd 時間伺服器端設定

編輯:Linux 系統常見問題解答

前言

叢集環境下,所有節點時間必須同步。若有外網,直接對公共 NTP/rdate 伺服器同步;純內網則需自建時間伺服器。本文示範 rdate + xinetd 輕量級方案。

一、客戶端:對外網/內網伺服器同步

# 立即同步(需安裝 rdate)
rdate -s tick.greyware.com        # 公共伺服器
rdate -s 192.168.1.100            # 內網自建伺服器 IP

# 寫入 crontab 每小時同步一次
echo "0 * * * * /usr/bin/rdate -s 192.168.1.100" >> /etc/crontab

二、伺服器端:CentOS 啟用 xinetd time 服務

1. 安裝 xinetd

yum install -y xinetd

2. 啟用 time-stream 服務

vim /etc/xinetd.d/time-stream
# 將 disable = yes 改為 disable = no

檔案內容應類似:

service time
{
    disable         = no
    type            = INTERNAL
    id              = time-stream
    socket_type     = stream
    protocol        = tcp
    user            = root
    wait            = no
}

3. 啟動並設定開機自啟

systemctl start xinetd
systemctl enable xinetd

4. 防火牆開放埠 37 (TCP)

firewall-cmd --permanent --add-port=37/tcp
firewall-cmd --reload

三、驗證

# 從客戶端測試
rdate -s 192.168.1.100
# 顯示伺服器時間即成功

進階建議:改用 NTP (chrony/ntpd)

  • rdate 精度僅秒級,無法補償網路延遲。
  • 生產環境強烈建議部署 **chrony**(CentOS 7+ 預設)或 **ntpd**,提供毫秒級精度、平滑校時、多源選擇。
  • chrony 客戶端設定範例:
# /etc/chrony.conf
server 192.168.1.100 iburst
# 重啟生效
systemctl restart chronyd

結語

rdate + xinetd 適合簡單內網快速部署;對時間精度有要求的場景,請直接上 chrony/ntpd,架構更穩健。

Copyright © Windows教程網 All Rights Reserved