CentOS7使用NTP服务器
一、安装ntp
yum -y install ntp
二、开启ntp
开启
systemctl start ntpd
开机启动
systemctl enable ntpd
三、手动授时
ntpdate -u cn.pool.ntp.org
四、自动授时
1、编辑shell脚本
echo "Time service start ..."
/usr/sbin/ntpdate -u cn.pool.ntp.org
if [ `echo $?` -eq 0 ]; then
echo "Time service complete"
else
echo "ERROR: Time service fail"
fi
date
2、确保crontab开启
service crond status 查看状态
service crond start 开启服务
service crond stop 关闭服务
service crond restart 重启服务
service crond reload 重新载入配置
3、增加crontabl任务
crontable -e
输入
*/1 * * * * /home/ntptask >> /home/ntptask.log
五、其他命令
修改系统时间
date -s "2019-06-25 20:13:00"
查看系统时间
date
动态查看系统时间
watch -n 1 "date"