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 -r
2014年03月27日 星期四 11时03分53秒 -0.797264 seconds
[root@localhost ~]# hwclock --show
2014年03月27日 星期四 11时04分01秒 -0.672267 seconds
2. clock与hwclock相同

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

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

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

同步网络时间到系统时间
[root@localhost ~]# ntpdate 210.72.145.44
27 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=false
ZONE="Asia/Shanghai"
重启系统
[root@localhost ~]# reboot
(文章来源:http://www.cnblogs.com/shockerli/p/linux-time-set.html)
Linux系统时间和硬件时间设置的更多相关文章
- linux 系统文件类型、系统安装时间、系统启动时间、系统运行时间、设置及显示时间、系统时间和硬件时间
系统文件类型: 1) $mout 2) df -l:仅列出本地文件系统:-h (--human-readable):-T:文件系统类型 $df -lhf 3) file -s (--special-f ...
- CentOS 6.9系统时间和硬件时间设置(转)
总结一下hwclock,这个容易晕: 1)/etc/sysconfig/clock 文件,只对 hwclock 命令有效,且只在系统启动和关闭的时候才有用(修改了其中的 UTC=true 到 UTC= ...
- CentOS 7修改系统时间及硬件时间
转载于:https://www.cnblogs.com/LouisZJ/p/8554991.html [root@nginx ~]# timedatectl --help timedatectl [O ...
- CentOS 系统时间与硬件时间
date 系统时间查看 date -s 'YYYYMMDD HHMMSS' 设置系统时间 hwclock 硬件时间查看 hwclock -w 将系统时间同步到硬件时间 cp /usr/share/zo ...
- CentOS7系统时间和硬件时间不同步问题
CentOS7系统中有两个时间:系统时间 和 硬件时间 我们常用命令 date 会输出系统时间,用 date 命令修改的也是系统时间 硬件时间是写入到 BIOS 中的时间,用 hwclock -r 命 ...
- Linux入门教程:如何检查Linux系统的最后重启时间
问题: 是否有一个命令可以快速地检查系统已经运行了多久? 也就是我怎么知道Linux系统最后的重启时间? 有许多方法来查询系统最后的重启时间. 方法一 第一种方法是使用last命令. $ last r ...
- Centos7 修改系统时间和硬件时间不一致的问题
查看系统时间 [root@localhost ~]# dateSat Feb 24 14:41:22 CST 2018 查看硬件时间 [root@localhost ~]# hwclock --sho ...
- Linux 系统时钟(date) 硬件时钟(hwclock)
/********************************************************************* * Linux 系统时钟(date) 硬件时钟(hwclo ...
- linux系统时钟和硬件时钟不一致
在做DB2 集群复制的时候要求两台主机时间相互一致. 但是在一台主机上系统时间和硬件时间相差12个小时左右:手动同步后,重启后又相差12个小时左右. 为什么会是这样的,先介绍下系统时钟和硬件时钟的区别 ...
随机推荐
- UVA它11292 - Dragon of Loowater
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- Swift - 多线程实现方式(2) - NSOperation和NSOperationQueue
1,Swift继续使用Object-C原有的一套线程,包括三种多线程编程技术: (1)NSThread (2)Cocoa NSOperation(NSOperation和NSOperationQueu ...
- delphi实现穿XP防火墙
procedure TForm1.Button1Click(Sender: TObject);var FwMgr,Profile,FwApp: variant;begin FwMgr := C ...
- 基于visual Studio2013解决面试题之0207单词翻转
题目
- 【源代码】LinkedHashMap源代码剖析
注:下面源代码基于jdk1.7.0_11 之前的两篇文章通过源代码分析了两种常见的Map集合,HashMap和Hashtable.本文将继续介绍还有一种Map集合--LinkedHashMap. 顾名 ...
- Cocos2d-x3.3RC0的Android编译Activity启动流程分析
本文将从引擎源代码Jni分析Cocos2d-x3.3RC0的Android Activity的启动流程,以下是具体分析. 1.引擎源代码Jni.部分Java层和C++层代码分析 watermark/2 ...
- camel-name-utils 在驼峰风格跟下划线风格之间切换
用处 用来将字符串在驼峰风格跟下划线风格之间切换. 对于一般人可能没用.对于写orm框架的人有点作用. 样例: company_name -> companyName 安装方式 加入下面依赖到p ...
- leetcode第一刷_Sqrt(x)
这道题乍看下来很easy,实际上要注意的问题许多. 注意看给出来的函数的接口,返回的是int值,也就是计算结果是个近似值.如何求呢?难道是从2開始往上算?直到某个值正好接近x?当然不行,肯定超时了.再 ...
- hdu 4707 Pet 2013年ICPC热身赛A题 dfs水题
题意:linji的仓鼠丢了,他要找回仓鼠,他在房间0放了一块奶酪,按照抓鼠手册所说,这块奶酪可以吸引距离它D的仓鼠,但是仓鼠还是没有出现,现在给出一张关系图,表示各个房间的关系,相邻房间距离为1,而且 ...
- Tengine中的proxy_upstream_tries
upsream xxx { server 192.168.100.100; server 192.168.100.101; server 192.168.100.102; } server { loc ...