How to use the command to synchronize the clock under Linux

  

If the hardware clock and system clock in the Linux system are not synchronized, it may cause some errors, so the synchronization between the system clock and the hardware clock is very important. The following small series will give you everyone. Describes how to use commands to synchronize the clocks of Linux systems.

linux system clock should be used in many places, and if allowed, there will be some strange questions;

In Linux, for view and set the clock The commands mainly include date, hwclock, and clock. The Linux clock is divided into a system clock (System Clock) and a hardware (Real Time Clock (RTC) clock. System clock: refers to the clock in the current Linux Kernel, hardware clock: is the battery-powered clock on the motherboard, this hardware clock can be set in the BIOS.

When Linux boots, the hardware clock reads the system clock settings, and the system clock runs independently of the hardware.

All commands (including functions) in Linux are system clock settings. In Linux, the commands for clock viewing and setting are mainly date, hwclock, and clock. Among them, the clock and hwclock usage are similar, only one is used, but the clock command supports the Alpha hardware system in addition to the x86 hardware system.

1, date

View system time

# date

Set system time

# date –set “07/07/06 10:19″ //(month/day/year hour:minute:second)

2, hwclock/clock

View hardware time

# hwclock &ndash ;show //or

# clock –show

Set hardware time

# hwclock –set –date=”07/07/06 10:19&Prime ; (month/day/year hour: minute: second) or

# clock –set –date=”07/07/06 10:19″ (month/day/year hour: minute: Second)

3, hardware time and system time synchronization

According to the previous statement, restart the system, hardware time will read the system time, to achieve synchronization,

When you do not restart, you need to use the hwclock or clock command to achieve synchronization.

The hardware clock is synchronized with the system clock:

# hwclock –hctosys //(hc stands for hardware time, sys stands for system time) or

# clock –hctosys< Br>

System clock and hardware clock synchronization:

# hwclock –systohc //or

# clock –systohc

4. and external NTP time Server Synchronization

$ service ntpd stop

This step is required, otherwise it appears:

25 Nov 18:10:34 ntpdate[2106]: the NTP socket is In use, exiting

failure prompt;

$ ntpdate ntp.sjtu.edu.cn

Normal return is as follows:

25 Nov 18:14 :34 ntpdate[2164]: adjust time server 202.120.2.101 offset -0.006107 sec

Error returning as:

25 Nov 18:13:44 ntpdate[2158]: no server suitable for synchronization Found

$ service ntpd start

$ chkconfig ntpd on

$ clock -w

can also write In the timing task, to make the timing of the clock synchronization:

$ crontab -e

05 * * * * /usr/sbin/ntpdate ntp.sjtu.edu.cn 》 /dev/Null 2》&1

05 17 * * * /sbin/clock -w

Attach NTP time server address that can be used in China

server 133.100.11.8 Prefer

server 210.72.145.44

server 203.117.180.36

server 131.107.1.10

server time.asia.apple.com

server 64.236.96.53

server 130.149.17.21

server 66.92.68.246

server www.freebsd.org

server 18.145.0.30

server clock.via.net

server 137.92.140.80

server 133.100.9.2

server 128.118.46.3

server ntp.nasa. Gov

server 129.7.1.66

server ntp-sop.inria.frserver 210.72.145.44 (China National Time Service Center Server IP Address)

server ntp.sjtu.edu. Cn (Shanghai Jiaotong University Network Center NTP server site Address)

The above is the method of using the command to synchronize the Linux clock, generally use the data, hwclock and clock commands, and the data command is a more common command, if your system clock is not synchronized, then quickly change come on.

Copyright © Windows knowledge All Rights Reserved