In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to achieve linux time synchronization, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
There are two ways for Linux to achieve time synchronization. One is to update time from the time server using ntpdate without any configuration, and the other is to use ntp to build your own time server.
Due to hardware reasons, the machine is more or less out of line with the standard time, and the error varies from a few seconds to a few minutes. There will be a lot of trouble for the server when the time is not right. For example, when paying, the order cannot be placed, the game cannot log in, and so on. Next, I will share with you how to achieve time synchronization in Linux system. I hope it will be helpful to you.
Method 1: update the time from the time server with ntpdate
If the linux system does not have the command ntpdate, you can enter the following code to install it
Yum install ntp
After the installation, you don't have to do any configuration, and you don't need to test it directly.
Vi / etc/ntp.confadd below:server 1.cn.pool.ntp.orgserver 3.asia.pool.ntp.orgserver 2.asia.pool.ntp.org
Restart service and sync the time
[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 shows that the synchronization is successful, then add the following to the crontab.
* / 10 * ntpdate time.nist.gov # domain name or IP
Synchronize every ten minutes. Recommend several 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. Build your own time server with ntp
The above is to use other people's time servers to synchronize time, these time servers are more authoritative. 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.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. 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. 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 / / result of synchronization 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
Recommend the first method, although set up a time server, relatively simple, but I do not think this is necessary. If you use someone else's time server, synchronize every 10 minutes, which can be accurate to milliseconds.
The above is all the content of how to achieve time synchronization in linux. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.