linux 时间设置

特性系统时间(System Time)硬件时间(Hardware Time)
存储位置 由 Linux 内核维护,存储在内存中,断电后丢失。 存储在主板的 CMOS 芯片(或 BIOS/UEFI)中,由主板电池供电,断电后保留。
获取方式 通过 date 命令查看,实时更新。 通过 hwclock 或 clock 命令查看,依赖硬件芯片。
时间来源 通常通过 NTP(网络时间协议)同步,或手动设置。 开机时从硬件读取,或由系统时间写入(如关机前同步)。
时间格式 通常为本地时区时间(如 CST)或 UTC(取决于系统配置)。 推荐存储为 UTC 时间(避免时区转换问题),部分旧系统可能存储为本地时间。
# 自动校准
ntpdate -u cn.pool.ntp.org
#通过cron 每天凌晨两点自动同步时间
crontab -e
0 2 * * * ntpdate -u cn.pool.ntp.org
# 时区
rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 同步系统时间到硬件时钟
# 将系统时间同步到硬件时间
hwclock --systohc
hwclock -w
# 查看硬件时间
hwclock --show
# 查看硬件时间是否与系统时间一致
hwclock -s
posted @ 2017-03-16 14:40  嘿.嘿.嘿  阅读(192)  评论(0)    收藏  举报