查看虚拟机中是否有ntp服务
systemctl status ntpd
如图,若没有则先下载ntp服务
yum -y install ntp
注:查看的命令中为ntpd,而下载服务时没有d
下载完成后启用ntp,并查看ntp状态
systemctl start ntpd
systemctl status ntpd
编辑ntp的配置文件,添加要加入的ip,加在第一使其优先级最高,下面centos自带的可以禁用也可以不动,prefer的作用是优先选择
vi /etc/ntp.conf
启用时间服务器,并设置开机自启动
service ntpd start
chkconfig ntpd on
查看ntp是否正常运行,有些虚拟机中可能用不了netstat,可用以下命令下载
netstat -tlunp | grep ntp --查看状态
sudo yum install net-tools --下载netstat服务
重启ntp服务并查看时间同步状态
systemctl restart ntpd
ntpq -p