Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the methods of synchronizing network time in Linux/CentOS system

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail the methods of synchronizing network time in Linux/CentOS system. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Method 1: update the time from the time server with ntpdate

If the system does not have the ntpdate command, it can be installed online:

Yum-y install ntp

After the installation, you don't have to do any configuration, and you don't need to test it directly.

[root@snsgou-pc src] # date2015 20 May 2000 Wednesday 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] # date2015 20 May 20 Wednesday 22:43:17 CST

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

We can use scheduled tasks to synchronize time periodically.

Enter the crontab editing state with the crontab-e command, and append the following timed task text

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

Means to synchronize every ten minutes. Several time servers are recommended:

Time.nist.govtime.nuri.net0.asia.pool.ntp.org1.asia.pool.ntp.org2.asia.pool.ntp.org3.asia.pool.ntp.org

Method 2: build your own time server with ntp

When we build our own time server, we don't use crontab to run 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 / / is not allowed to modify or query ntp by default And do not receive the special packet 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 local network 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.orgserver 1.asia.pool.ntp.orgserver 2.asia.pool.ntp.orgserver 127.127.1.0 # local clockfudge 127.127.1.0 stratum 10driftfile / var/lib/ntp/driftkeys / etc/ntp/keys

3. Start ntp

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

4. View and test

[root@localhost ~] # netstat-upnl | grep ntpd / / View time history [root@localhost ~] # ntpq-pn / / View synchronized server IP remote refid st t when poll reach delay offset jitter==== 50.77.217.185.INIT .16u-64 0 0.000 0.000 0.000 202.90.158.4 .INIT .16u-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 time correct to within 127.127.1.0 .LOCL. 10 l 18 64 377 0.000 0.000 0.000 [root@localhost ~] # ntpstat / / synchronous result synchronised to local net at stratum 11 time correct to within 12 ms polling server every 512s

Remote: that is, the IP or host name of the NTP host. Pay attention to the leftmost symbol. If "+" represents the upper NTP that is currently working on the clock, if it is "*", it means that it is also connected, but as a secondary online NTP host.

Refid: the address of the upper-level NTP host referenced

St: the stratum class

When: time synchronization update was done a few seconds ago

Poll: the next update is in a few seconds

Reach: the number of updates that have been requested from the upper NTP server

Delay: the time of clock delay during network transmission

Offset: the result of time compensation

Difference time between jitter:Linux system time and BIOS hardware time

This is the end of this article on "what are the methods of synchronizing network time in Linux/CentOS system?". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report