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.
After installing centos, I found that the time does not match the local time. I found a lot of ways on the Internet, but it never worked. After the restart, I restored it to the original time. I'm wondering. Finally, I added the command with a try: ln-sf/usr/share/zoneinfor/Asia/Shanghai/etc/localtime. After restarting, I changed the command, A sigh of relief. The detailed commands are listed below, hoping to help you.
1: Display system Time: # date
Modify the system time: date-s '2017-08-02 '# set the system time to the local time
2: Display hardware Time: # hwclock -- show
Set hardware Time: # hwclock -- set -- date '2017/24/60 12:00:00'
3: Hardware time synchronization system Time: hwclock -- hctosys
4: this command forces the system time to be written into the CMOS: clock-w
If you only need the above four steps and the changes take effect after the restart, congratulations, you don't have to look at the following steps. If the changes do not take effect yet, then you must use this critical step 5th.
5: ln-sf/usr/share/zoneinfor/Asia/Shanghai/etc/localtime # change the time zone
Restart and you will find that the modification has been made.
After the Centos Linux operating system is installed, we click the system time and find that the time is different from the time currently used. The difference is 8 hours, when installing the system, the Time zone we selected is Shanghai, but the default bios Time for CentOS Linux is utc (UTC is the abbreviation of Universal Time Coordinated, it is a second-based time scale defined and recommended by the International Radio Advisory Board and maintained by the international time agency (BIH. UTC is equivalent to the average solar time on the primary meridian (I .e. 0 degrees longitude), which was previously expressed in Greenwich Mean Time (GMT. beijing time is 8 hours earlier than UTC time. For example, UTC on January 1, January 1, 1999, UTC time is eight o'clock, and Beijing time is on January 1, January 1, 1999 .), So we are 8 hours apart in time. At this time, the bios time and system time are of course inconsistent. One represents utc time, and the other represents cst (+ 8 time zone), that is, Shanghai time.
Let's start to synchronize the operating system time!
In CentOS Linux, run the following command:
1. vi/etc/sysconfig/clock # Edit the time configuration file
ZONE = "Asia/Shanghai"
UTC = false # set to false, and the hardware clock is not consistent with utc time
ARC = false
2. ln-sf/usr/share/zoneinfo/Asia/Shanghai/etc/localtime # set the linux time zone to the Shanghai Time zone
3. ntpdate 192.43.244.18 # aligning time
If the ntp server is not installed, run the following command:
Yum install ntp # install the ntp server
4./sbin/hwclock -- systohc # set the hardware time to be consistent with the system time and calibrate
Now, our CentOS linux system time and computer hardware time are both cst time and Shanghai time zone, and it is normal at last.