安装ntpdate
yum -y install ntpdate
查看当前时间
date
同步当前时间
ntpdate time.nist.gov; #更新时间 hwclock -w; #将时间写入到硬盘
加入定时任务
注意一定要带:root ,否则不执行
1.打开crontab vi /etc/crontab 2.加入定时任务 * */48 * * * root ntpdate time.nist.gov;hwclock -w;
如果ntpdate time.nist.gov;hwclock -w; 不执行,将他写到.sh文件中
例如:
/etc/rc.d/sys_uptime.sh
#!/bin/bash ntpdate time.nist.gov; hwclock -w;
重新编辑/etc/crontab
1.打开crontab vi /etc/crontab 2.加入定时任务 * */48 * * * root /etc/rc.d/sys_uptime.sh