NTP time server configuration "1" Hardware time and system time

I recently made a project and deployed it to the server, but the server time always changes, so I spent some time studying the use of the NTP time server. I have compiled some learning experiences and recorded them so that they will not be forgotten.

 

 

NTP time server 《1》 Hardware time and system time

 

 

There are two kinds of clocks in Linux system: hardware clock and system clock. By default, they are not automatically synchronized and run in an asynchronous manner without interfering with each other.

 

The hardware clock refers to the clock device on the motherboard, that is, the clock that can usually be set in the BIOS screen.

The system clock refers to the clock in the kernel. All Linux-related commands and functions read the settings of the system clock.

 

Because there are two different clocks, there will be differences between them. When Linux starts, the system clock will read the setting of the hardware clock, and then the system clock will operate independently.

 

Modify system time and hardware time

( 1) System time

View: date

Edit: date -s ' 2015-12-12 00:00:00 ' 

( 2) Hardware time

Check: hwclock -r or hwclock --show

Edit: hwclock --set --date ' 2015-12-12 00:00:00 '

 

After the system time is set with the date command, the hardware clock will not be modified, so after the system restarts, the system time will still read the hardware time, which is why the date setting is invalid. Therefore, it is necessary to synchronize the system time to the hardware clock after setting the system time.

 

Synchronize system time and hardware time

( 1) Write the hardware time to the system time

Command: hwclock --hctosys or hwclock -s

Command: clock --hctosys or clock -s

 

( 2) Write the system time to the hardware time

Command: hwclock --systohc or hwclock -w

Command: clock --systohc or clock -w

 

If we observe the initialization script "/etc/rc.d/rc.sysinit " executed when the system starts/shutdown , we can easily find:

During system startup , /sbin/hwclock --hctosys is automatically called to synchronize the hardware clock system time to the operating system time.

During system shutdown , automatically call /sbin/hwclock --systohc to synchronize the operating system time to the hardware clock system time

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326449893&siteId=291194637