Micro channel set water drop nickname, personality with a bit cute

In Windows OS, the system time setting is very simple, interface operation, easy to understand, and after setting, restart, shutdown is ok. The system time will be automatically saved in the BIOS clock, when the computer is started, the system will automatically take the hardware time in the BIOS, in order to ensure the uninterrupted time. However, under Linux, system time and hardware time are not automatically synchronized by default. In Linux, system time and hardware time run asynchronously without interfering with each other. Hardware time is maintained by the BIOS battery, and system time is maintained by the CPU Tick. When the system is powered on, the system automatically obtains the hardware time from the BIOS and sets it to the system time.

1. Set the Linux system time

To set the system time on Linux, run the date command:

2 [root@node1 ~]# date 3 Tue Feb 25 20:15:18 CST 2014 4 [root@node1 ~]# date -s "20140225 20:16:00" # YYYYMMDD hh:mm:ss 6 Tue Feb 25 20:16:00 CST 2014Copy the code

2. Set the Linux hardware time

You can run the hwclock or clock command to set the hardware time. The clock command supports Alpha hardware as well as x86 hardware.

1 // Check the hardware time using hwclock, Hwclock --show or hwclock -r 2 [root@node1 ~]# hwclock --show 3 Tue 25 Feb 2014 08:21:14pm cST-0.327068 seconds 4 5 [root@node1 ~]# hwclock --set --date "20140225 20:23:00" 6 [root@node1 ~]# hwClock Tue 25 Feb 2014 08:23:04 PM CST - 0.750440 secondsCopy the code

3. Synchronize system time with hardware time

To synchronize the system time and hardware time, run the hwclock command.

1 // Based on system time, 2 [root@node1 ~]# hwclock -- systoHC <== sys (system time) to (write) hc (Hard Clock) 3 // or 4 [root@node1 ~]# hwclock -w 5 // Change the system time 6 [root@node1 ~]# hwclock --hctosys 7 // or 8 [root@node1 ~]# hwclock -sCopy the code

4. Time synchronization between different machines

To avoid time deviation caused by a host running for a long time, it is necessary to perform time synchronization. In Linux, the NTP server is used to synchronize the time of different machines. A machine can serve as both the NTP server and NTP client. In production systems, it is recommended to use a hierarchical time server like a DNS server to synchronize time.

You can use the ntpdate command or the NTPD service to synchronize time between different machines.

4.1 ntpdate command

Using nTPDate is simpler. The format is as follows:

1 [root@node1 ~]# ntpdate [NTP IP/hostname]
2 [root@node1 ~]# ntpdate 192.168.0.1
3 [root@node1 ~]# ntpdate time.ntp.org
Copy the code

In this case, the system time must be set to that of the NTP server. If there is a CPU Tick problem, it only treats the symptoms rather than the root cause. Therefore, the cron command is generally used to perform periodic synchronization Settings. For example, in crontab add:

0 12 * * * /usr/sbin/ntpdate 192.168.0.1
Copy the code

In this way, the time will be synchronized at 12 o ‘clock every day. The NTP server is 192.168.0.1.

Hourly synchronization can be performed by adding the following scripts to /etc/cron.hourly:

#! / bin/bash # # Id: sync – clock, v1.62009/12/2315: jmatesExpId are: Sync – clock, v 1.6 2009/12/23 15:41:29 jmates Exp Id: sync – clock, v1.62009/12/2315: darts jmatesExp # # Use ntpdate to get rough clock sync with department of Genome Sciences # time server.

NTPDATE = / usr/sbin/NTPDATE SERVER = “192.168.0.1”

# if running from cron (no tty available), sleep a bit to space # out update requests to avoid slamming a server at a particular time if ! test -t 0; then MYRAND=
R A N D O M M Y R A N D = RANDOM MYRAND=
{MYRAND:=$$}

If [MYRAND – gt9]; Thensleep ‘echoMYRAND – gt 9]; Then sleep ` echo MYRAND – gt9]; Thensleep ‘echoMYRAND | sed’ s /. * (..) $/\1/’ | sed ‘s/^0//’` fi fi

−suNTPDATE -su NTPDATE−suSERVER # update Hardware clock on Linux (RedHat?) systems if [ -f /sbin/hwclock ]; then /sbin/hwclock –systohc fi

4.2 the NTPD service

Using the NTPD service is better than the combination of NTPDate and CRon. Ntpdate synchronization can cause time mutations and jumps, which can affect some time-dependent programs and services. Sleep, timer, etc. Moreover, the NTPD service can correct the CPU Tick at the same time as the time. Therefore, it is desirable to use ntpDate to force time synchronization at boot time and the NTPD service to synchronize time at other times.

Note that NTPD has a self-protection mechanism: if the time difference between the local host and the upper source is too large, NTPD will not perform time synchronization. Therefore, the new time server must first obtain the initial time value from the upper source and then start the NTPD service. After the NTPD service is running, it synchronizes with the upper-source NTP server every 64 seconds. After complex calculation, the NTPD service gradually adjusts its time based on the error value measured during each synchronization. As the error decreases, the synchronization interval is gradually increased. This adjustment process is repeated with each beat.

4.3. Setting of NTPD service

The configuration files of the NTPD service are as follows:

(1) /etc/ntp.conf: this is the main configuration file of the NTP daemon and the only configuration file of NTP.

(2)/usr/share/zoneinfo: files in this directory is set file defines the major time zones, such as in Beijing time zone setting files in/usr/share/zoneinfo/Asia/Shanghai. The files in this directory are related to the next two files (clock and localtime).

(3) /etc/sysconfig/clock: this file is not included in the NTP daemon because it is the main time zone setting file for Linux. After each startup, Linux automatically reads this file to set its own default display time.

(4) /etc/localtime: this file is the “localtime configuration file”. Just the clock setting rules for use of time inside file (ZONE) for/usr/share/zoneinfo/Asia/Shanghai, so, this is the local time, at this time, Linux will save the Shanghai file as a /etc/localtime file, so our time display will be based on the Beijing time setting file in the future.

The following describes how to configure the /etc/ntp.conf file. As for the NTP Server configuration, it is recommended not to open the Internet unlimitedly, but to provide only clients within the LAN for online network time calibration. In addition, THE NTP Server always needs a more accurate host on the network to update its own Time ah, so in our NTP Server to find a closest to their own Time Server for self-correction. In fact, NTP service is also a Server/Client mode.

[root@linux ~]# vi /etc/ntp.conf # 1. The restrict parameter is mainly used to set permissions. The main syntax is as follows: Restrict IP mask netmask_IP parameter # restrict IP mask netmask_IP parameter Nomodify: Indicates that the Client cannot change the time parameter of the Server. However, the Client can still perform network time correction through the Server.

#noquery: no time query is provided on the Client side

#notrap: Trap is not provided for remote event logins

# If paramter is not set at all, then the IP (or domain) has “no limits”

Restrict default nomodify notrap noquery# restrict default nomodify notrap noquery# disable all NTP request packets

Restrict 127.0.0.1 # This allows native queries

Restrict 192.168.0.1 Mask 255.255.255.0 nomodify

192.168.0.1/24 network segment can synchronize time with this NTP Server. The upper HOST set # to set the upper HOST mainly by the server to set this parameter, grammar is: # server IP [| HOST Name] [–] # server is followed by the upper Time server, and if the server parameter

If perfer is added after #, it means that our NTP host is mainly based on this host

# as the corresponding time correction. In addition, in order to solve the transmission delay of update time packets,

So we can use DriftFile to specify how much Time our host takes to communicate with the Time Server. This can be recorded in a file following driftfile, such as the following example. The time our NTP server spent online with #cn.pool.ntp.org is recorded in the /etc/nt/drift file server 0.pool.ntp.org

server 1.pool.ntp.org

server 2.pool.ntp.org

server cn.pool.ntp.org prefer

Use the default values for other Settings

Server 127.127.1.0 # local clock

Fudge 127.127.1.0 stratum 10

Driftfile/var/lib/NTP/drift broadcastdelay 0.008

keys /etc/ntp/keys

To sum up, RESTRICT is used to set access permissions, Server is used to set the upper-layer time server, and DriftFile is used to set the files that save the drift time.

4.4 Starting and querying the NTPD service

Before starting the NTP service, manually calibrate the time on the host. The time cannot be manually synchronized because the port will be occupied by the server after the server is started.

[root@node1 ~]# ntpdate cn.pool.ntp.org 25 Feb 21:10:52 ntpdate[9549]: Adjust Time Server 202.112.31.197 Offset 0.000101 SECCopy the code

Then, start the NTPD service:

[root@node1 ~]# /etc/init.d/ntpd start
Starting ntpd: [ OK ]
[root@node1 ~]# date
Tue Feb 25 21:11:07 CST 2014
Copy the code

View port (NTPD service uses UDP port 123) :

/ root @ node1 ~ # netstat – ln | grep: 123 udp 0 0 12.12.12.100:123 0.0.0.0: * udp 0 0 192.168.0.100:123 0.0.0.0: * udp 0 0 172.18.226.174:123 0.0.0.0:* udp 00 10.10.10.100:123 0.0.0.0:* udp 00 127.0.0.1:123 0.0.0.0:* udp 00 0.0.0.0:123 Udp 0.0.0.0: * 0 0 fe80: : 225-90 ff: fe98:61 ff: 123: : : * udp 0 0 fe80: : 225:90 ff: fe98:61 fe: 123: : : * udp 0 0 fe80::202:c903:1b:afa1:123 :::* udp 0 0 ::1:123 :::* udp 0 0 :::123 :::*

How do WE verify that our NTP server has updated its time?

[root@node1 ~]# ntpstat synchronised to NTP server (202.120.2.101) at stratum 4 time correct to within 557 ms polling Server every 64 s # This command lists whether the NTP server is connected to the upper layer. As can be seen from the above output results, the time correction is about 557*10(-6) seconds, and the time is actively updated every 64 seconds.

Common mistakes:

Unsynchronized time server re-starting polling server every 64 s // or 25 Apr 15:30:17 ntpDate [11520]: no server suitable for synchronization foundCopy the code

Well, that’s not a mistake. It takes about 3-5 minutes for the client to establish a normal communication connection with the NTP server after each NTP server restart. This message is reported when the client is connected to the server. It usually takes a few minutes.

[root@node1 ~] # ntptrace — n 127.0.0.1:stratum 11, offset 0.000000, synch distance 0.950951 222.73.214.125: Stratum 2, offset — 0.003087, synch distance 0.108575 209.81.9.7:stratum 1, offset 0.000028, synch distance 0.00436, stratum 2, offset — 0.003087, synch distance 0.108575 209.81.9.7:stratum 1, offset 0.000028, synch distance 0.00436 Refid ‘GPS’ # This command lists the relationship between the current NTP server (layer 1) and the upper-layer NTP server (layer 2) #. Note that this command requires the ntp-Perl package to be installed

Copy the code

NTPQ command:

[root@node1 ~]# ntpq -p
Copy the code

The command “NTPQ -p” can list the status of our NTP and related upper-layer NTP. The above fields have the following meanings:

Remote: specifies the IP address or host name of the NTP host. Note the symbol on the left. If the symbol is “+”, it indicates the upper-layer NTP that is currently working. If the symbol is “*”, it indicates that the NTP host is also online, but as a secondary NTP host.

Refid: indicates the IP address of the upper-layer NTP host

St: Stratum stratum

When: Time synchronization was performed a few seconds ago

Poll: The next update is in a few seconds

Reach: indicates the number of times that the upper-layer NTP server has requested updates

Delay: indicates the delay time of the network transmission clock

Offset: indicates the result of time compensation

Jitter: Indicates the time difference between the Linux system time and BIOS hardware time

Finally, the NTP service only synchronizes system time by default. If you want NTP to synchronize hardware time, you can set the /etc/sysconfig/ntpd file.

To synchronize hardware time with system time, add SYNC_HWCLOCK=yes to /etc/sysconfig/ntpd.

5. Example of time synchronization in the HPC cluster

5.1 Cluster Environment Overview

Management nodes: 192.168.0.100, 192.168.0.101

Compute node: 192.168.0.1 to 192.168.0.50

I/O node: 192.168.0.51 to 192.168.0.54

Internet NTP server: cn.pool.ntp.org

5.2 Time synchronization Scheme Design

Figure 1 NTP time synchronization scheme design

Detailed explanation of the scheme:

(1) Management node 1 acts as the active NTP server and synchronizes time with the Internet NTP server. As the standby NTP server, management node 2 synchronizes time with the Internet NTP server. The two management nodes serve as the Heartbeat services, set a floating IP address 192.168.0.103, and implement high availability for the NTPD service on both nodes.

(2) The compute nodes and I/O nodes in the cluster synchronize time with the virtual IP address 192.168.0.103 of the management node through the NTPD service.

(3) On all nodes, set the hardware time to be the same as the system time when the NTP time is synchronized;

(4) When all compute nodes and I/O nodes are started, use ntpDate to synchronize time with 192.168.0.103, and then enable the NTPD service.

Micro channel set water drop nickname, personality with a bit cute