NTP Time sync between computers - githeim/windheim_archive GitHub Wiki
Time sync between computers
Like a robot system, it can contain multiple processors in it. In that case the time sync should be achieved to communicate each others. In this page, introduce how to get time sync between multiple processors by using NTP server.
What we do here
- The master connects to NTP server through internet, master system will synchronize to the internet time.
- In the system there are master and slave(s). Slaves synchronize to the master.
Install NTP server
$ sudo apt install ntp
$ sudo apt install ntpdate
Version check of NTP
$ sntp --version
sntp [email protected] (1)
NTP server(master) settings
edit /etc/ntp.conf
$ sudo vim /etc/ntp.conf
in the /etc/ntp.conf
...
# Specify one or more NTP servers.
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst
# Additional servers
server 0.kr.pool.ntp.org
server 3.asia.pool.ntp.org
server 0.asia.pool.ntp.org
server 127.127.1.0 minpoll 3 maxpoll 3 prefer
fudge 127.127.1.0 stratum 10
...
์์์
server 127.127.1.0 minpoll 3 maxpoll 3 prefer
mipoll 3 / maxpoll 3 ๊ฐ์ ๋ฃ์ด์ฃผ์ง ์์ผ๋ฉด client๊ฐ ๋๊ธฐํํ๋๋ฐ ์๊ฐ์ด ์ค๋๊ฑธ๋ฆฐ๋ค. ๋ก๋ด๊ณผ ๊ฐ์ ์ ํ๋ฆฌ์ผ์ด์ ์์๋ ๋ถํ ์๊ฐ์ด ๋์ด๋๋๋ฑ์ ๋จ์ ์ด ์์ผ๋ ์ถ๊ฐํ๋ ๊ฒ์ด ์ข๋ค.
NTP server(slave) settings
$ sudo vim /etc/ntp.conf
in the /etc/ntp.conf
...
# Specify one or more NTP servers.
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
server 192.168.10.100 prefer iburst # <---your master IP
or
server 192.168.10.100 minpoll 3 maxpoll 3 iburst # <---your master IP
minpoll / maxpoll ์ ๋ํด์๋ ์์์๋ 2^3 = 8์ด ์ด๋ด๋ก polling ์ ์๋ํด ๋๊ธฐํ๋ฅผ ๋ง์ถ๋ค. ntp์์๋ 3๊ฐ์ด ์ต์๊ฐ.(chrony์์๋ ์ข ๋ ์์ ๊ฐ ๊ฐ๋ฅ)
๋ง์ฝ slave๊ฐ ์ธํฐ๋ท์ด ์๋๊ณ master์๋ง ์์กดํ ๊ฒฝ์ฐ ntp.conf์ pool ํญ๋ชฉ์ ๋ค์๊ณผ ๊ฐ์ด ์ฃผ์์ฒ๋ฆฌํ๋ฉด ๋น ๋ฅด๊ฒ master์ ๋๊ธฐํํ ์ ์๋ค
# pool 0.ubuntu.pool.ntp.org iburst
# pool 1.ubuntu.pool.ntp.org iburst
# pool 2.ubuntu.pool.ntp.org iburst
# pool 3.ubuntu.pool.ntp.org iburst
#
# # Use Ubuntu's ntp server as a fallback.
# pool ntp.ubuntu.com
check the delay & offset
in the slave console
$ ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
+xxx.aaa.com 133.243.238.164 2 u 565 1024 377 21.171 1.178 1.587
-yyy.yyy.yyy.yyy 220.73.142.66 3 u 545 1024 377 27.889 -0.713 1.114
*xxx.xxx.xxx.xxx 17.253.114.253 2 u 996 1024 277 48.699 11.319 4.876
you can check the delay / offset /jitter the * mark in the first raw is the master ntp server
check the ntp pool servers for your time zone
https://support.ntp.org/bin/view/Servers/NTPPoolServers
https://www.pool.ntp.org/zone/asia
In case of (south) Korea
https://www.pool.ntp.org/zone/kr
restart & check ntp server state
$ sudo systemctl restart ntp
$ sudo systemctl status ntp
โ ntp.service - Network Time Service
Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-08-29 10:22:53 KST; 6s ago
Docs: man:ntpd(8)
Process: 8089 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS)
Main PID: 8097 (ntpd)
Tasks: 2 (limit: 36425)
Memory: 804.0K
CGroup: /system.slice/ntp.service
โโ8097 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 116:134
Aug 29 10:22:53 udr-62149 ntpd[8097]: Listen normally on 5 eth0 [fe80::f58:6b2c:7525:4d29%3]:123
Aug 29 10:22:53 udr-62149 ntpd[8097]: Listening on routing socket on fd #22 for interface updates
Aug 29 10:22:53 udr-62149 ntpd[8097]: kernel reports TIME_ERROR: 0x2041: Clock Unsynchronized
Aug 29 10:22:53 udr-62149 ntpd[8097]: kernel reports TIME_ERROR: 0x2041: Clock Unsynchronized
Aug 29 10:22:54 udr-62149 ntpd[8097]: Soliciting pool server 185.125.190.57
Aug 29 10:22:55 udr-62149 ntpd[8097]: Soliciting pool server 91.189.91.157
Aug 29 10:22:56 udr-62149 ntpd[8097]: Soliciting pool server 91.189.94.4
Aug 29 10:22:57 udr-62149 ntpd[8097]: Soliciting pool server 185.125.190.58
Aug 29 10:22:58 udr-62149 ntpd[8097]: Soliciting pool server 185.125.190.56
Aug 29 10:22:59 udr-62149 ntpd[8097]: Soliciting pool server 2620:2d:4000:1::40
$
How to sync ntp immediately
sudo service ntp stop
sudo ntpd -gq
sudo service ntp start