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

Detailed graphic explanation of how to use svg in vue3+vite project

Today, in the practice of vue3+vite project, when...

Detailed explanation of HTML form elements (Part 1)

HTML forms are used to collect different types of...

Simple implementation of html hiding scroll bar

1. HTML tags with attributes XML/HTML CodeCopy co...

Object-Oriented Programming with XHTML and CSS

<br />If only XHTML and CSS were object-orie...

How to use ElementUI pagination component Pagination in Vue

The use of ElementUI paging component Pagination ...

jQuery Ajax chatbot implementation case study

Chatbots can save a lot of manual work and can be...

How to implement one-click deployment of nfs in linux

Server Information Management server: m01 172.16....

How to install and modify the initial password of mysql5.7.18 under Centos7.3

This article shares with you the installation of ...

JavaScript canvas to achieve scratch lottery example

This article shares the specific code of JavaScri...

JavaScript pie chart example

Drawing EffectsImplementation Code JavaScript var...

Tutorial on installing Tomcat server under Windows

1 Download and prepare First, we need to download...