Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of time-related commands in CentOS system

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you the example analysis of time-related commands in the CentOS system, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Time is the most basic part in any system and is indispensable. This paper introduces the commands related to time in CentOS system.

Basic concept

Hardware clock (Hardware Clock)

Hardware clock, also known as real-time clock (RealTimeClock), or BIOS clock, or CMOS clock. It is the actual hardware equipment located on the motherboard of the machine, which is generally maintained by batteries. Therefore, even if the machine is turned off, it will keep track of the current time, which is generally not very accurate.

System time (System Time)

System time refers to the time in the operating system. It is driven by the hardware timer after the system is powered on, and the Linux system increments the time count according to the timer signal. This timer is very accurate and has a small error.

When the Linux system starts, it first reads the current time from the hardware clock to initialize the system time count, and then increments it according to the timer interrupt, which is no longer dependent on the hardware clock.

Time zone (time zone)

The time of sunrise varies around the world, but the time of sunrise is locally known as 6 o'clock, and the hands of clocks vary from country to country at the same time. It also created the emergence of the time zone. When UTC is the world standard, other time zones increase or decrease on this basis. For example, Beijing time in China is 8 hours earlier than world time.

Generally speaking, the time zone information is not recorded in the hardware clock, but often only the local time. The concept of time zone must be taken into account in the system time, otherwise the time can not be unified when computers in different time zones exchange information. This is fatal for many software systems, such as version management systems that rely heavily on time tags. The current time zone information is stored in the Linux kernel, and Linux's file system depends on this time zone information.

Common command

1 View and set the current BIOS time

[root@centos192 smstong] # hwclock-r # read the hardware clock Wednesday, June 3, 2015 12:30:46-0.891230 seconds [root@centos192 smstong] # hwclock-- set-- date= "06ap03gamma 16:45:05" # set the hardware clock

2 View and set the current operating system time

[root@centos192 smstong] View the current system time on Wednesday, June 3, 2015, 19:37:55 CST [root@centos192 smstong] # date-s 10:00:00 # set the system time on Wednesday, June 3, 2015, at 10:00:00 CST

3 the hardware clock interacts with the system time

[root@centos192 smstong] # hwclock-- hctosys # set system time with hardware clock [root@centos192 smstong] # hwclock-- systohc # set hardware clock with system time

4 View and set the time zone of the current system

[root@centos192 smstong] # date-R # View the current system time Wed with time zone information, 03 Jun 2015 19:45:37 + 0800 [root@centos192 smstong] # export TZ='America/Havana' # set the time zone to Cuba time [root@centos192 smstong] # date-R # you can see that the time zone is-0400 Wed, 03 Jun 2015 07:49:49-0400

To permanently set the time zone information, you can add export TZ='America/Havana' to the / etc/profile configuration file. In this way, the time zone will be automatically set when the machine is restarted.

Note that the time zone used by the Linux kernel and the application is not necessarily the same, although it should be the same. The application first relies on the TZ environment variable to determine the time zone, and if TZ is not set, the kernel setting is used. The kernel sets the time zone based on the / etc/sysconfig/clock file. * (this is my guess, please correct me) *

5 through the network time correction, we said earlier that the hardware clock is often not accurate, although the system clock is more accurate, but still can not meet the high-precision time requirements. The best way is to read the correct time from a dedicated time server through the NTP protocol, and then correct the system time and hardware clock.

[root@centos192 smstong] # ntpdate-u s1a.time.edu.cn # correct system time 3 Jun 19:56:42 ntpdate [21550]: adjust time server 202.112.10.60 offset 0.000163 sec [root@centos192 smstong] # hwclock-w # then set the hardware clock according to the corrected system time

If it is a long-running server, you need to write the calibration command into a script and execute it automatically and regularly through crond.

The above is all the contents of the article "sample Analysis of time-related commands in CentOS system". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report