这里搭建ntp服务器,服务端和客户端,客户端去拉取服务端的时间,为自己所用。
yum -y install ntp*
vim /etc/ntp.conf
最后加上下面的
#添加常用的授时服务器,允许上层时间服务器主动修改本机时间 server ntp1.aliyun.com server time1.aliyun.com server 127.127.1.0 # 本地时钟服务器
#启动 systemctl start ntpd.service #开机自启 systemctl enable ntpd.service #重启 systemctl restart ntpd.service
ntpstat
输出是 synchronised to NTP server 那证明已经连上了NTP服务器,
如果输出是 unsynchronised 开头的 那证明还没有连上NTP服务器,过几分钟再试一下
yum -y install ntp*
/usr/sbin/ntpdate 192.168.220.138 && hwclock --systohc #ip是我的服务端的
crontab -e #然后加上下面的 */10 * * * * /usr/sbin/ntpdate 192.168.220.138 && hwclock --systohc
是因为客户端的ntp服务 没关闭(可能是客户端安装ntp时,不小心启动了)
执行
systemctl stop ntpd.service