操作系统运行时间长后,系统时间跟实际时间就会相差越来越大,为了保证程序产生的数据正确,需要定期调整系统时间。
# 如果没有 ntpdate 命令可先安装yum install ntp
# 查看当前系统时间命令date -R # 查看当前主板硬件时间hwclock --show # 同步系统时间到实际时间 (备用服务器 asia.pool.ntp.org)ntpdate 1.cn.pool.ntp.org # 将新时间写入到 BIOShwclock --systohc
设置定期自动同步系统时间
# 查看 ntpdate 命令所在路径which ntpdate # 查看 hwclock 命令所在路径which hwclock # 修改 crontabcrontab -e
添加以下内容并保存 (注意 ntpdate 和 hwclock 的路径必须正确)
# 每3小时同步一次系统时间, 并写到 BIOS0 */3 * * * /sbin/ntpdate 1.cn.pool.ntp.org >> /var/log/ntpdate.log; /sbin/hwclock --systohc