Linux system time and hardware time settings

Source: Internet
Author: User

There are two times in a Linux system, hardware clock and system time, the hardware clock refers to the clock device on the motherboard, which is usually the clock that can be set on the BIOS screen. The system clock refers to the clock in the kernel. All Linux-related instructions and functions are programmed to read the system clock. Because there are two different clocks, there is a difference between them. When Linux starts, the system clock reads the settings of the hardware clock, and then the system clock runs independently.

When the system time is set with the date command, the hardware clock is not modified, so the system time is still read hardware time after the system restarts, which is why the date setting fails to the cause.

Therefore, the system time needs to be synchronized to the hardware clock after the system time has been set.

Clock/hwclock:

Display and set the hardware clock (query and set the hardware clock (RTC)), the two commands are the same. Rtc=real time Clock, which is the hardware clock.

Command parameters:

-R,--show read and print the hardware clock (read hardware clock and print result)
-S,--hctosys synchronizes the hardware clock to the system clock (set the time from the hardware clock)
-W,--SYSTOHC synchronizes the system clock to the hardware clock (set the hardware clock to the current system time)

command example:

Date display is the current system time

Modify the system time

Linux System time Date manual modification (1)

View current Time # date

Modify Time Command # Date–s 12:12:00

Modify Date Command # Date–s 01/12/2008

[[email protected] ~]# Hwclock-r2016 year April 24 Sunday 13:51 01 seconds   -0.880312date   *:CST

(2) Synchronizing the system time to the hardware clock

[Email protected] ~]#Date#显示当前的系统时间2016年 Sunday, April 24 at: the: -CST [[email protected]~]# Hwclock-R #显示当前的硬件时间 April 24, 2016 Sunday 14:05 47 seconds-0.845293Seconds[[email protected]~]# Hwclock-W#将系统时间同步到硬件时钟 (System time as hardware time) [[email protected]~]# Hwclock-R #再次显示硬件时间2016年04月24日 Sunday 23:16 42 seconds-0.956500Seconds[[email protected]~]#Date#再次显示系统时间2016年 Sunday, April 24 at: -: -Cst

(3) Hardware time as the system time

[Email protected] ~]# Hwclock-R #显示硬件时间2016年04月24日 Sunday 14:14 56 seconds-0.690487seconds [[email protected]~]#Date#显示系统时间2016年 Sunday, April 24 -: -: -CST #将硬件时间作为系统时间 [[email protected]~]# Hwclock-S[[email protected]~]# Hwclock-R #再次显示硬件时间da2016年04月24日 Sunday 14:15 21 seconds-0.785729Seconds[[email protected]~]#Date#再次显示系统时间2016年 Sunday, April 24 -: the: ACst

(3) Synchronizing the system time to the network time

Synchronization commands

# ntpdate NTP server domain name or IP

Example: # ntpdate 1.cn.pool.ntp.org

Http://www.pool.ntp.org is the official website of NTP, where we can find the NTP server cn.pool.ntp.org from our country. It has 3 server addresses:

Server One: 1.cn.pool.ntp.org
Server Two: 2.asia.pool.ntp.org
Server Three: 3.asia.pool.ntp.org

(directly with the domain name sometimes have problems, you can ping their IP, and then synchronize with the IP address)

Automatically run synchronization time script settings

# crontab–e

Examples of adding scripts are as follows:

*/20 * * * */usr/sbin/ntpdate 210.72.145.44//Every 20 minutes or below

5 * * * */usr/sbin/ntpdate 210.72.145.44//Daily 5:30 A.M. execution.

[Email protected] ~]#  1. cn.pool.ntp.org: ntpdate[11827time202.118.  1.8133031.663763date:49 CST

(4) The local host can install the NTP service as a standalone time synchronization server

The Redhat server can download the RPM installation package and then perform

# RPM-IVH ntp-4.2.0.a.20040617-4.x86_64.rpm or # yum-y install ntp.x86_64

Reference blog: Linux system time and hardware time settings: http://www.linuxidc.com/Linux/2014-09/107029.htm

NTP server under Linux (time synchronization and timely zone related issues): http://gaoxingf.blog.51cto.com/612518/121959

Linux system time and hardware time settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.