Pazartesi, Ekim 14, 2024

Yüksek Performanslı NTP Sunucusu Nasıl Kurulur?

Burada sizlere pek çok NTP sunucusu kurulum şeklini anlattım, tabi bunlar tamamı yerelde kişisel amaçlar için kullanmaya yönelikti. Şimdi ise halka açık bir şekilde NTP nasıl yapılandırırız ve kullanıma açarız onu göstermek istiyorum.

Gerekenler

  • Ubuntu 22.04/24.04 işletim sistemli 2 core 2gb ram bir makine
  • chrony uygulaması

Makineyi güncelleyin NTP sunucusu olarak klasik ntp yapılandırmayacağız onun yerine daha performanslı olan chrony kullanıcaz. DDoS saldırıları dışında performans sorunu çekmeyeceksiniz.

apt install chrony
ShellScript

Bu sisteme iki adet uygulama ekleyecek

  • chronyd – Ağ Zaman Protokolü aracılığıyla senkronize edilecek ve hizmet verecek gerçek daemon
  • chronyc – chrony daemon için komut satırı arayüzü

Yüklediğiniz an kullanabilirsiniz onda sıkıntı yok. Ancak genele açık bir sunucu olarak yapılandırmak isterseniz /etc/chrony/chrony.conf dosyasını düzenlemeniz gerekiyor. Ben sizin için hazırladım aşağıdakini direk kullanabilirsiniz.

# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usable directives.

# Include configuration files found in /etc/chrony/conf.d.
confdir /etc/chrony/conf.d

# Pools
pool ntp.ubuntu.com        iburst maxsources 4
pool 0.ubuntu.pool.ntp.org iburst maxsources 1
pool 1.ubuntu.pool.ntp.org iburst maxsources 1
pool 2.ubuntu.pool.ntp.org iburst maxsources 2

# Servers
server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburst
server time.windows.com iburst
server time.apple.com iburst
server time.google.com iburst
server time.facebook.com iburst
server time.cloudflare.com iburst
server time.nist.gov iburst

# Dirs
sourcedir /run/chrony-dhcp
sourcedir /etc/chrony/sources.d
keyfile /etc/chrony/chrony.keys
driftfile /var/lib/chrony/chrony.drift
ntsdumpdir /var/lib/chrony
logdir /var/log/chrony

rtcsync
allow
clientloglimit 100000000
leapsectz right/UTC
maxupdateskew 100.0
makestep 1.0 3
fallbackdrift 16 19

# Rate limit
ratelimit interval 1 burst 16
ntsratelimit interval 3 burst 1
ShellScript

Kayıt edip çıkış yapın sonrasında deamon’u yeniden systemctl restart chrony komutu ile başlatın. Biraz bekledikten sonra kendisine gelir aşağıdaki gibi bir çıktı görürseniz çalışıyor demektir.

root@app:~# systemctl status chrony
chrony.service - chrony, an NTP client/server
     Loaded: loaded (/lib/systemd/system/chrony.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2024-06-07 21:59:02 UTC; 1 week 2 days ago
       Docs: man:chronyd(8)
             man:chronyc(1)
             man:chrony.conf(5)
    Process: 1060 ExecStart=/usr/lib/systemd/scripts/chronyd-starter.sh $DAEMON_OPTS (code=exited, status=0/SUCCESS)
   Main PID: 1069 (chronyd)
      Tasks: 2 (limit: 2218)
     Memory: 38.5M
        CPU: 3d 5h 36min 54.341s
     CGroup: /system.slice/chrony.service
             ├─1069 /usr/sbin/chronyd -F 1
             └─1070 /usr/sbin/chronyd -F 1

Jun 07 21:59:02 app systemd[1]: Starting chrony, an NTP client/server...
Jun 07 21:59:02 app chronyd[1069]: chronyd version 4.2 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +NTS +SECHASH +IPV6 -DEBUG)
Jun 07 21:59:02 app chronyd[1069]: Frequency -26.534 +/- 0.179 ppm read from /var/lib/chrony/chrony.drift
Jun 07 21:59:02 app chronyd[1069]: Using right/UTC timezone to obtain leap second data
Jun 07 21:59:02 app chronyd[1069]: Loaded seccomp filter (level 1)
Jun 07 21:59:02 app systemd[1]: Started chrony, an NTP client/server.
Jun 07 21:59:13 app chronyd[1069]: Selected source 2a03:2880:ff0c::123 (time.facebook.com)
Jun 07 21:59:13 app chronyd[1069]: System clock TAI offset set to 37 seconds
Jun 12 20:32:23 app chronyd[1069]: Source 2a0f:6580:110:171::66 replaced with 2a03:2100:0:2a::3c0:2 (2.pool.ntp.org)
ShellScript

Bakalım hakikaten sağlıklı çalışıyor mu

root@app:~# chronyc -n tracking
Reference ID    : 44A63DFF (2a03:2880:ff0c::123)
Stratum         : 2
Ref time (UTC)  : Mon Jun 17 15:34:28 2024
System time     : 0.000000002 seconds slow of NTP time
Last offset     : -0.000081798 seconds
RMS offset      : 0.000074264 seconds
Frequency       : 26.423 ppm slow
Residual freq   : -0.010 ppm
Skew            : 0.032 ppm
Root delay      : 0.014898589 seconds
Root dispersion : 0.001159322 seconds
Update interval : 1036.6 seconds
Leap status     : Normal
ShellScript

Gayet güzel gözüküyor, zamanı yavaşlatmış ve ilk güncellemesini de yapmış, ayrıca aradaki senkron süreside oldukça kısa peki hangi kaynakları kullanıyor buna da bir bakalım.

root@app:~# chronyc -N 'sources -a -v'

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current best, '+' = combined, '-' = not combined,
| /             'x' = may be in error, '~' = too variable, '?' = unusable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^- 0.pool.ntp.org                2   8   377   449  -6379us[-6379us] +/-   61ms
^+ 1.pool.ntp.org                3   9   377   428  -2709ns[-2709ns] +/- 8952us
^? 2.pool.ntp.org                0  10   377     -     +0ns[   +0ns] +/-    0ns
^? 3.pool.ntp.org                0  10   377     -     +0ns[   +0ns] +/-    0ns
^- time.windows.com              3  10   377  1003    +73us[-8987ns] +/-   55ms
^- time.apple.com                1  10   377   543  +1268us[+1268us] +/-   24ms
^- time.google.com               1  10   377   488  +1266us[+1266us] +/-   28ms
^* time.facebook.com             1  10   177   987    +11us[  -70us] +/- 7602us
^- time.cloudflare.com           3  10   377   894  -2859us[-2859us] +/-   36ms
^- time.nist.gov                 1  10   377   472  +5300us[+5300us] +/-   74ms
^- ntp.ubuntu.com                2  10   377   402   +428us[ +428us] +/-   31ms
^- ntp.ubuntu.com                2  10   377     4  +1540us[+1540us] +/-   32ms
^- ntp.ubuntu.com                2  10   377   853   -197us[ -197us] +/-   31ms
^- ntp.ubuntu.com                2  10   377    86   +970us[ +970us] +/-   31ms
^- 0.ubuntu.pool.ntp.org         2  10   377   958   +976us[ +976us] +/-   39ms
^- 1.ubuntu.pool.ntp.org         3   8   377    69   -863us[ -863us] +/-  121ms
^- 2.ubuntu.pool.ntp.org         3   9   377   253    +97us[  +97us] +/-   30ms
^- 2.ubuntu.pool.ntp.org         3   8   377   170  +6883us[+6883us] +/-  236ms
ShellScript

Artık halka açık bir şekilde kullanabileceğiniz NTP sunucunuz hazır, istediğiniz gibi kullanılmasını sağlayabilirsiniz. Burada DDoS harici sıkıntı yaşayacağınızda bir sıkıntı bulunmuyor.