CentOS set system time to synchronize with network time

Linux time is divided into System Clock (system time) and Real Time Clock (hardware time, RTC for short).
System time: refers to the time in the current Linux Kernel.
Hardware time: Time when there is battery power on the motherboard.
Command to view system time: #date Command to
set system time: #date –set (month/day/year hour: minute: second)
Example: #date –set “10/11/10 10:15” to
view hardware time Command: # hwclock command to
set hardware time: # hwclock –set –date = (month/day/year hour: minute: second)
The above mentioned is to manually set the time to a point in time, which may be different from the current network time . Here's how to synchronize with the time on the time server
1. Install the ntpdate tool
# yum -y install ntp ntpdate
2. Set the system time to synchronize with the network time
# ntpdate cn.pool.ntp.org
3. Write the system time to the hardware Time
# hwclock --systohc
4. Force the system time to be written into CMOS to prevent restart failure
  hwclock -w
  or clock -w
After installing the Centos Linux operating system, we found that the time when we clicked the system was inconsistent with the time we are using now, and the difference was 8 hours. When we installed the system, the time zone we chose was Shanghai, but the default bios time of CentOS Linux was utc. Time (UTC is the abbreviation of Universal Time Coordinated), which is a second-based time scale specified and recommended by the International Radio Advisory Committee and maintained by the International Bureau of Time (BIH). UTC is equivalent to the beginning of the The mean solar time on the meridian (ie, 0 degrees longitude) used to be expressed in Greenwich Mean Time (GMT). Beijing time is 8 hours ahead of UTC time. Taking January 1, 1999, 0000 UTC as an example, the UTC time is 0:00, Beijing time is 8:00 am on January 1, 1999.), so we are 8 hours apart in time. At this time, the bios time and the system time are of course inconsistent, one represents utc time, and the other represents cst (+8 time zone), that is, Shanghai time.
Let's synchronize the time of the operating system!
Execute the following command in the terminal command in CentOS Linux:
1. vi /etc/sysconfig/clock #Edit the time configuration file
ZONE="Asia/Shanghai"
UTC=false #Set it to false, the hardware clock is not consistent with utc time
ARC=false
2, ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #linux time zone is set to Shanghai time zone
3, ntpdate 192.43.244.18 #align the time
if There is no ntp server installed, just need to execute the following command first:
yum install ntp #Install ntp server
4, /sbin/hwclock --systohc #Set the hardware time and system time to be consistent and calibrated
, our CentOS linux system time and computer hardware time are finally cst time, and both are in Shanghai The time zone is finally normal.

Guess you like

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