Linux系统时间和硬件时间设置

在Linux中有硬件时钟与系统时钟两种时钟。硬件时钟是指主机板上的时钟设备,,也就是通常可在BIOS画面设定的时钟。系统时钟则是指kernel中的时钟。所有Linux相关指令与函数都是读取系统时钟的设定。因为存在两种不同的时钟,那么它们之间就会存在差异。当Linux启动时,系统时钟会去读取硬件时钟的设定,之后系统时钟即独立运作。

用date命令对系统时间进行设置后,并不会去修改硬件时钟,所以系统重启后,系统时间还算会去读取硬件时间,这就是为何date设置失效到原因。

因此,需要在设置系统时间后,将系统时间同步到硬件时钟。

clock/hwclock:

显示与设定硬件时钟(query and set the hardware clock (RTC)),两个命令相同。RTC=Real Time Clock,也就是硬件时钟。

命令参数:

-r, –show 读取并打印硬件时钟(read hardware clock and print result)-s, –hctosys 将硬件时钟同步到系统时钟(set the system time from the hardware clock)-w, –systohc 将系统时钟同步到硬件时钟(set the hardware clock to the current system time)

命令示例:

1. 查看硬件时钟

2014年03月27日 星期四 11时03分50秒 -0.328520 seconds[root@localhost ~]# hwclock -r2014年03月27日 星期四 11时03分53秒 -0.797264 seconds[root@localhost ~]# hwclock –show2014年03月27日 星期四 11时04分01秒 -0.672267 seconds

2. clock与hwclock相同

复制代码[root@localhost ~]# type -a hwclockhwclock is /sbin/hwclockhwclock is /usr/sbin/hwclock[root@localhost ~]# ll /sbin/hwclock /usr/sbin/hwclock -rwxr-xr-x. 1 root root 46940 11月 22 23:27 /sbin/hwclocklrwxrwxrwx. 1 root root 18 3月 26 19:27 /usr/sbin/hwclock -> ../../sbin/hwclock[root@localhost ~]# type -a clockclock is /sbin/clock[root@localhost ~]# ll /sbin/clock lrwxrwxrwx. 1 root root 7 3月 26 19:27 /sbin/clock -> hwclock

复制代码

3. 同步系统时间到硬件时钟

复制代码[root@localhost ~]# hwclock2014年03月27日 星期四 18时50分51秒 -0.312960 seconds[root@localhost ~]# date2014年 03月 27日 星期四 10:50:55 CST[root@localhost ~]# hwclock -w[root@localhost ~]# hwclock2014年03月27日 星期四 10时51分15秒 -0.875387 seconds

复制代码

同步网络时间到系统时间

[root@localhost ~]# ntpdate 210.72.145.4427 Mar 11:11:24 ntpdate[4766]: adjust time server 210.72.145.44 offset 0.011401 sec

210.72.145.44 (中国西安授时中心的官方时间同步服务器IP域名)

同步网络时间到系统时间后,就可以用hwclock -w将系统时间同步到硬件时间。

修改时区

可能部分系统在执行以上两步后,在重启后仍然失效,所以需要进行时区修改。

[root@localhost ~]# tzselect #按照提示进行选择时区[root@localhost ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

修改系统时间配置文件

[root@localhost ~]# /etc/sysconfig/clock

#打开clock文件,将相关内容改成以下内容UTC=true ARC=falseZONE=”Asia/Shanghai”

重启系统

[root@localhost ~]# reboot

本文永久更新链接地址:

你说只有有缘人才可以取下,我看着你手中的戒指,

Linux系统时间和硬件时间设置

相关文章:

你感兴趣的文章:

标签云: