本文將介紹如何在CentOS系統(tǒng)中配置自動時間同步,以確保系統(tǒng)時間的準(zhǔn)確性。通過配置網(wǎng)絡(luò)時間協(xié)議(NTP),可以讓系統(tǒng)自動與時間服務(wù)器聯(lián)網(wǎng)同步。下面的步驟將詳細說明配置過程以及注意事項。
sudo yum install ntp
安裝完成后,需要編輯NTP配置文件以指定同步的時間服務(wù)器。
sudo vi /etc/ntp.conf
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
這些服務(wù)器是CentOS官方提供的公共NTP服務(wù)器,iburst參數(shù)用來加快同步速度。
sudo systemctl start ntpd
sudo systemctl enable ntpd
可以使用以下命令查看NTP的同步狀態(tài):
ntpq -p
該命令將顯示當(dāng)前的同步狀態(tài)和時間服務(wù)器的信息。確保輸出中有一個以*標(biāo)記的服務(wù)器,表示系統(tǒng)已經(jīng)成功與該服務(wù)器同步。
sudo firewall-cmd --permanent --add-port=123/udp
sudo firewall-cmd --reload
sudo timedatectl set-timezone Asia/Shanghai