在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服务器保持同步。