Cause Analysis of system time changes
Linux has two types of time: system time and hardware time (BIOS time ).
The System reads the BIOS time every time it starts and assigns it to the system time. The system time will run independently, but the BIOS time will not change.
There are two representation formats in BIOS time. One is expressed in localtime and the other in UTC. You can run hwclock-debug to display the current hardware time.
The following describes the changes in system time in various situations:
1. When hwclock is set to localtime and UTC = true in/etc/sysconf/clock, the system time is 8 hours earlier than the BIOS time after the system is restarted.
2. When hwclock is set to localtime and UTC = false in/etc/sysconf/clock, the system time does not change relative to the BIOS time after restart.
3. When hwclock is set to UTC and UTC = true in/etc/sysconf/clock, the system time does not change relative to the BIOS time after the system is restarted.
4. When hwclock is set to UTC and UTC = false in/etc/sysconf/clock, the system time relative to the BIOS time is pushed 8 hours after the system is restarted.
As shown in:
|
UTC = true in/etc/sysconf/clock |
UTC = false in/etc/sysconf/clock |
Hardware time localtime |
After the reboot, the system time is 8 hours earlier than the BIOS time. |
System time unchanged |
Hardware time UTC |
System time unchanged |
After the reboot, the system time is pushed 8 hours after the BIOS time |
It can be seen that when the BIOS time settings are different from those in/etc/sysconf/clock, the system time at system startup is incorrect.
If there is a script to synchronize time, but it runs after the system is started. Although time synchronization can synchronize the system time to the correct time, an incorrect time interval may occur due to the incorrect system time setting, this interval may affect programs that depend on the system time.
Countermeasure: the root cause of this problem is that the hardware time type is inconsistent with the setting in/etc/sysconf/clock. Therefore, we will add hardware time synchronization in the time synchronization script to solve this problem.
Note:
UTC Time: the Universal Time Coordinated (UTC), that is, the Time of the 0 Time zone.
CST Time: CST China Standard Time UTC + China Coastal Time (Beijing Time), which is the localtime of our Time zone.
2.
Time zone settings:
To ensure that the time is correct, set the time zone correctly. The correct setting is only for better time understanding and other maintenance.
Setting method:
1.
Manually set the time zone:
For example, set the UTC + 8 time
Ln-sf/usr/share/zoneinfo/Asia/Shanghai
/Etc/localtime
Edit ZONE = "Asia/Shanghai" in/etc/sysconfig/clock"
2.
Set using graphical commands
System-config-date (RedHat and CentOS only in most cases) or tzselect can be used as instructed by the command.
This article is taken from the wdlinux Forum http://www.wdlinux.cn/bbs/. For more information, see!