時間同步(網路校時)

CentOS 時間同步

CentOS 6

1
ntpdate pool.ntp.org # ntpdate [ip]

CentOS 8 (7開始提供使用Chrony)

  • 使用Chrony

安裝

1
yum install chrony

啟動

1
systemctl start chronyd.service 或  systemctl start chronyd

設置開機後就自動執行

1
systemctl enable chronyd.service 或  systemctl enable chronyd

設定檔位於路徑

  • /etc/chrony.conf

預設值

1
2
3
4
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

想改用台灣本地的時間主機,如下台灣本地的時間主機

1
2
3
server tock.stdtime.gov.tw prefer
server tick.stdtime.gov.tw
server time.stdtime.gov.tw

查看 chronyd運行狀態

1
systemctl status chronyd.service

查看 chronyc 校時來源server

1
chronyc sources

查看 chronyc 校時來源server狀態

1
chronyc sourcestats

查看最後一次取得的校時資料

1
chronyc tracking

如果系統時間與網路時間差異較大,不想等chrony慢慢校時,手動執行強制校時指令

1
chronyc -a makestep

More info:ntpdate from 鳥哥
More info: RedHat chrony vs ntpdate 差異
More info:RHEL8或CentOS8上配置NTP伺服器和客戶端
More info:Linux 設定 NTP 同步系統時間,自動網路校時教學