Detailed explanation of 2 methods to synchronize network time in Linux/CentOS system

Detailed explanation of 2 methods to synchronize network time in Linux/CentOS system

Due to hardware reasons, the machines may not keep up with the standard time to a certain extent, with the error ranging from a few seconds to a few minutes in a month. If the server time is inaccurate, it will cause a lot of trouble. For example, when making a payment, you are unable to place an order or the game cannot be logged in.

Method 1: Use ntpdate to update the time from the time server

If the system does not have the ntpdate command, you can install it online:

yum -y install ntp

After installation, you don’t need to do any configuration, just test it directly

[root@snsgou-pc src]# date
Wednesday, May 20, 2015 22:42:19 CST
[root@snsgou-pc src]# ntpdate time.nist.gov 
20 May 22:42:38 ntpdate[26759]: step time server 131.107.13.100 offset 2.117558 sec
[root@snsgou-pc src]# date
Wednesday, May 20, 2015 22:43:17 CST

The above situation indicates that the network time synchronization is successful.

We can use scheduled tasks to synchronize time regularly

Use the crontab -e command to enter the crontab editing state and append the following scheduled task text

*/10 * * * * ntpdate time.nist.gov #domain name or IP

Indicates synchronization every ten minutes. Recommended time servers:

time.nist.gov
time.nuri.net
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org

Method 2: Use ntp to build your own time server

When we build our own time server, we don't need crontab to run it regularly.

1. Install the time server ntp

yum install ntp

2. Configure ntp

[root@localhost ~]# cat /etc/ntp.conf |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}'
restrict default ignore //By default, modification or query of ntp is not allowed, and special packets are not received restrict 127.0.0.1 //Give all permissions to the local machine restrict 192.168.1.0 mask 255.255.255.0 notrap nomodify //Give the LAN machine the permission to synchronize time server time.nist.gov prefer //Set the time server, add prefer to indicate priority server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys

3. Start ntp

[root@localhost ~]# /etc/init.d/ntpd start

4. Check and test

[root@localhost ~]# netstat -upnl |grep ntpd //View the schedule [root@localhost ~]# ntpq -pn //View the synchronized server IP
 remote refid st t when poll reach delay offset jitter
==============================================================================
 50.77.217.185 .INIT. 16 u - 64 0 0.000 0.000 0.000
 202.90.158.4 .INIT. 16 u - 64 0 0.000 0.000 0.000
 202.71.100.89 .INIT. 16 u - 64 0 0.000 0.000 0.000
 202.134.1.10 .INIT. 16 u - 64 0 0.000 0.000 0.000
*127.127.1.0 .LOCL. 10 l 18 64 377 0.000 0.000 0.001
 
[root@localhost ~]# ntpstat //Synchronised to local net at stratum 11
 time correct to within 12 ms
 Polling server every 512 seconds

remote: the IP or host name of the NTP host. Pay attention to the symbol on the far left. If it is a "+", it means that the upper-level NTP is currently in effect. If it is a "*", it means that it is also online, but it is a secondary NTP host.

refid: the address of the upper-layer NTP host to which reference is applied

st: stratum

when: The time synchronization update operation was performed a few seconds ago

poll: The next update will be in a few seconds

reach: The number of times the upper-level NTP server has been requested to update

Delay: The delay time of the network transmission process

offset: the result of time compensation

jitter: The difference between Linux system time and BIOS hardware time

The above are the two methods of synchronizing network time in Linux system that this article will talk about. I hope it will be helpful to everyone.

You may also be interested in:
  • How to intercept the specified Tomcat log to the specified file in CentOS7 according to the time period
  • How to modify server system time in CentOS7
  • How to change the CentOS server time to Beijing time
  • How to set accurate time in CentOS
  • How to modify the time in centos virtual machine
  • Tutorial on how to configure ntp service under CentOS 7
  • Detailed steps to build ntp clock server in CentOS 7
  • Centos 7.4 server time synchronization configuration method [based on NTP service]

<<:  A brief discussion on mysql backup and restore for a single table

>>:  How to use lodop print control in Vue to achieve browser compatible printing

Recommend

WeChat applet implements text scrolling

This article example shares the specific code for...

Detailed explanation of the difference between tinyint and int in MySQL

Question: What is the difference between int(1) a...

Detailed explanation of viewing and setting file permissions on Mac

Preface To modify file permissions in the termina...

Example code for implementing the wavy water ball effect using CSS

Today I learned a new CSS special effect, the wav...

Key knowledge summary of Vue development guide

Table of contents Overview 0. JavaScript and Web ...

Standard summary for analyzing the performance of a SQL statement

This article will introduce how to use explain to...

MySQL transaction analysis

Transaction A transaction is a basic unit of busi...

CSS to achieve fast and cool shaking animation effect

1. Introduction to Animate.css Animate.css is a r...

Vue implements login type switching

This article example shares the specific code of ...

The difference between the four file extensions .html, .htm, .shtml and .shtm

Many friends who have just started to make web pag...

Super simple implementation of Docker to build a personal blog system

Install Docker Update the yum package to the late...

Centos7.5 configuration java environment installation tomcat explanation

Tomcat is a web server software based on Java lan...

React implements double slider cross sliding

This article shares the specific code for React t...

Detailed explanation of Nginx process scheduling problem

Nginx uses a fixed number of multi-process models...