2 methods of linux time synchronization

Due to hardware reasons, the root standard time of the machine is more or less inconsistent, and the error varies from a few seconds to a few minutes a month. For the server time is not accurate, there will be a lot of trouble. For example, when paying, the order cannot be placed, the game cannot be logged in, etc. It doesn't matter what PC you use, you can just change it manually.

One, use ntpdate to update the time from the time server

If your linux system does not have the ntpdate command at all

yum install ntp  

After the installation is complete, you don't need to do any configuration, and you don't need it, just test it directly

[root@localhost ~]# ntpdate time.nist.gov  

22 Oct 21:11:43 ntpdate[5014]: adjust time server 207.200.81.113 offset -0.018788 sec  

If the above content indicates that the synchronization is successful. Then add the following in crontab.

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

Sync every ten minutes. Several time servers are recommended.

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

Second, use ntp to build your own time server

Above, we use other people's time servers to synchronize the time. These time servers are relatively authoritative. When we build our own time server, we don't need crontab to run regularly.

1. Install time server ntp

yum install ntp  

2, configure ntp

View Copy Print?

[root@localhost ~]# cat /etc/ntp.conf |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}'  

restrict default ignore //By default, no modification or query of ntp is allowed, and special packets are not received  

restrict 127.0.0.1 //Give all permissions to this machine  

restrict 192.168.1.0 mask 255.255.255.0 notrap nomodify //Give the machine on the LAN the permission to synchronize the time  

server time.nist.gov prefer //Set the time server, plus prefer means 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  

operation file / var / lib / ntp / operation  

keys /etc/ntp/keys  

3, start ntp

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

4. Check and test

View Copy Print?

[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 //The result of synchronization  

synchronised to local net at stratum 11  

 time correct to within 12 ms  

 polling server every 512 s  

remote: The IP or host name of the NTP host. Pay attention to the leftmost symbol. If it is "+", it means the upper-layer NTP that is currently operating the clock. If it is "*", it means that there is also a connection line, but it is the NTP host that is the secondary connection.

refid: the address of the referenced upper-layer NTP host

st: the stratum class

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

poll: next update in a few seconds

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

delay: the time delay in the network transmission process

offset: the result of time compensation

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

The first method is recommended. Although it is relatively simple to build a time server, I don't think it is necessary. If you use someone else's time server to synchronize every 10 minutes, it can be accurate to milliseconds.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326573150&siteId=291194637