1、服务端配置
yum -y install ntp
cp /etc/ntp.conf /etc/ntp.conf.bak
egrep -v "^$|#" /etc/ntp.conf.bak >/etc/ntp.conf
vim /etc/ntp.conf
driftfile /var/lib/ntp/drift restrict default kod nomodify notrap nopeer noquery restrict -6 default kod nomodify notrap nopeer noquery restrict 127.0.0.1 restrict -6 ::1 允许内网其他机器同步时间 restrict 172.16.1.0 mask 255.255.255.0 nomodify notr #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 定义使用的上游 ntp服务器,将原来的注释 server ntp1.aliyun.com server time1.aliyun.com 允许上层时间服务器主动修改本机时间 restrict time1.aliyun.com nomodify notrap noquery restrict ntp1.aliyun.com nomodify notrap noquery 外部时间服务器不可用时,以本地时间作为时间服务 server 127.127.1.0 fudge 127.127.1.0 stratum 10 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys
systemctl restart ntpd
systemctl enable ntpd
2、客户机配置
yum -y install ntpdate
同步时间,指定ip时间同步服务器
ntpdate 10.0.0.111
客户机写入定时任务
0 0 * * * /usr/sbin/ntpdate 10.0.0.111