ntp服务器

yum install -y ntp #同步服务器
systemctl start ntpd 
systemctl enable ntpd

ntpq -p #查看运行状态

配置

vi /etc/ntp.conf

restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap   (允许内网通讯网段)  
server 127.127.1.0 iburst#使用本机时钟

#以下可以选填
#如果能上网添加多个外网时钟
server 210.72.145.44 prefer (中国国家授时中心服务器地址 prefer表示优先 注意把默认的server更改成这样)  
server 218.21.130.42     (cn.pool.ntp.org的IP)    
#restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap noquery notrust (屏蔽其他IP过来更新时间)

systemctl restart ntpd #重启

终端机安装ntpdate

yun install ntpdate  
#设置时区
timedatectl set-timezone Asia/Shanghai 
#同步时间
ntpdate 10.3.60.27 
ntpdate -u 10.3.60.27
-u 指定使用无特权的端口发送数据包

设置定时任务
crontab -e
0 1 * * 1 /usr/sbin/ntpdate 10.3.60.40  #周一凌晨1点同步一次时间


#开机自动同步
vi /etc/rc.d/rc.local
/usr/sbin/ntpdate -u 10.3.60.40 
/sbin/hwclock -w #修改硬件时间

报错

错误:/bin/sh: ntpdate: command not found
处理:
whereis ntpdate
0 1 * * 1 /usr/sbin/ntpdate 10.3.60.40