在CentOS系統中,時間戳同步通常是通過NTP(網絡時間協議)服務來實現的。以下是同步CentOS系統時間戳的步驟:
timedatectl
命令檢查當前時間同步狀態
timedatectl status
啟用NTP服務
sudo timedatectl set-ntp true
手動同步時間 如果需要立即同步時間,可以使用以下命令:
sudo ntpdate pool.ntp.org
重啟NTP服務 有時重啟NTP服務可以解決同步問題:
sudo systemctl restart chronyd
或者如果你使用的是ntpd
:
sudo systemctl restart ntpd
chrony
服務(CentOS 7及更高版本)安裝chrony
sudo yum install chrony -y
啟動并啟用chronyd
服務
sudo systemctl start chronyd
sudo systemctl enable chronyd
檢查chrony
狀態
sudo systemctl status chronyd
手動同步時間
sudo chronyc makestep
配置NTP服務器
編輯/etc/chrony.conf
文件,添加或修改NTP服務器:
sudo vi /etc/chrony.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
重啟chronyd
服務
sudo systemctl restart chronyd
ntpd
服務(CentOS 6)安裝ntpd
sudo yum install ntp -y
啟動并啟用ntpd
服務
sudo service ntpd start
sudo chkconfig ntpd on
檢查ntpd
狀態
sudo service ntpd status
手動同步時間
sudo ntpdate pool.ntp.org
配置NTP服務器
編輯/etc/ntp.conf
文件,添加或修改NTP服務器:
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
重啟ntpd
服務
sudo service ntpd restart
通過以上步驟,你可以確保CentOS系統的時間戳與NTP服務器保持同步。