Sinkronisasi Jam dan Tanggal Untuk Server FreeBSD Dengan NTP Time Server

· 2 min read

FreeBSD menggunakan Network Time Protocol (NTP) untuk menyinkronkan jam sistem komputer melalui jaringan data latensi variabel yang dirutekan melalui

Jam pada komputer cenderung tidak akurat, sewaktu-waktu selalu berubah, terutama pada sistem berbasis Windows, jika tidak disinkronisasikan dengan baik akan menyebabkan beberapa aplikasi tidak dapat berjalan dengan sempurna. Pada program WEB Browser, jika jam pada komputer tidak akurat, maka browser seperti Chrome, Mozilla dan lainnya tidak akan dapat dibuka.

Solusinya, Network Time Protocol (NTP) menyediakan cara untuk menjaga keakuratan jam sistem komputer. NTP merupakan protokol internet yang digunakan untuk melakukan sinkronisasi waktu di beberapa server. FreeBSD menyertakan program daemon NTP (ntpd) yang mengatur dan menjaga waktu sistem dengan melakukan sinkronisasi dengan server NTP.

Untuk melakukan pengaturan daemon NTP kita harus menginstalnya terlebih dahulu. Pada pembahasan kali ini kita akan membahas tentang cara menginstal dan melakukan sinkronisasi daemon NTP.

Untuk menggunakan daemon NTP, dalam pembahasan ini server yang digunakan adalah:

  1. Processor: AMD Phenom(tm) II X4 955 Processor (K8-class CPU).
  2. OS: 14.1-STABLE.
  3. IP Server: 192.168.5.234.
  4. Hostname: router2.
  5. NTP version: 4.2.8p18.
FreeBSD menggunakan Network Time Protocol (NTP) untuk menyinkronkan jam sistem komputer melalui jaringan data latensi variabel yang dirutekan melalui paket UDP. NTP menggunakan port UDP 123. Jika Anda memiliki satu komputer atau satu server, Anda dapat dengan mudah menyinkronkan waktu dengan server NTP lainnya. Yang Anda butuhkan hanyalah klien ntp yang disebut ntpdate. Klien ini digunakan untuk mengatur tanggal dan waktu melalui server NTP. Mari kita praktikkan cara mengatur Sinkronisasi Jam NTP di FreeBSD dengan ntpd dan ntpdate.

Sebagai langkah pertama, kita instal program zoneinfo.
root@router2:~ # cd /usr/ports/misc/zoneinfo
root@router2:/usr/ports/misc/zoneinfo # make install clean
Setelah info zona berhasil dipasang, salin zona waktu Jakarta ke waktu setempat.
root@router2:~ # cp /usr/share/zoneinfo/Asia/Jakarta /etc/localtime
Berikutnya, instal daemon NTP.
root@router2:~ # cd /usr/ports/net/ntp
root@router2:/usr/ports/net/ntp # make install clean
Jika Anda ingin menggunakan paket PKG untuk menginstal "NTP", jalankan perintah berikut.
root@router2:~ # pkg install net/ntp
Membuat file log dan drift.
root@router2:~ # touch /var/db/ntpd.drift
root@router2:~ # touch /var/log/ntpd.log
Dalam file loder.conf, masukkan skrip berikut.
root@router2:~ # ee /boot/loader.conf
mac_ntpd_load="YES"
Masukkan juga skrip berikut dalam file sysctl.conf di folder /etc.
root@router2:~ # ee /etc/sysctl.conf
security.mac.ntpd.enabled=1
security.mac.ntpd.uid=123
Agar daemon NTP dapat langsung terhubung ke salah satu server waktu, buat skrip berikut dalam file crontab.
root@router2:~ # ee /etc/crontab
* */12 * * * /usr/local/sbin/ntpdate time.cloudflare.com
Agar daemon NTP terus aktif, Anda harus menambahkan skrip ke file periodic.conf di folder /etc/defaults. Cari nomor 480 dan tambahkan skrip berikut.
root@router2:~ # ee /etc/defaults/periodic.conf
daily_status_ntpd_enable="YES"
daily_ntpd_leapfile_enable="YES"
Untuk memutar berkas log, Anda dapat menambahkan skrip berikut ke file /etc/syslog.conf dan file /etc/newsyslog.conf.
root@router2:~ # ee /etc/syslog.conf
!ntpdate
*.*                     /var/log/ntpd.log
!ntpdate
*.*                     /var/log/ntpd.log
root@router2:~ # ee /etc/newsyslog.conf
/var/log/ntp.log         600   10     300     *     J
Agar daemon NTP selalu berjalan saat server dihidupkan ulang/di-boot ulang atau dimatikan, tambahkan skrip berikut ke file /etc/rc.conf.
root@router2:~ # ee /etc/rc.conf
ntpd_enable="YES"
ntpdate_enable="YES"
ntpd_config="/etc/ntp.conf"
ntpd_program="/usr/local/sbin/ntpd"
ntpdate_program="/usr/local/sbin/ntpdate"
ntpdate_flags="time.cloudflare.com"
ntpd_sync_on_start="YES"
ntpd_oomprotect="YES"
ntpd_flags="-f /var/db/ntpd.drift -l /var/log/ntpd.log"
Konfigurasi akhir daemon NTP adalah mengedit file /etc/ntp.conf. Berdasarkan skrip asli atau default dari file /etc/ntp.conf, ada beberapa hal yang harus diaktifkan dan ada skrip yang dapat ditambahkan. Di akhir artikel ini akan diberikan contoh lengkap skrip /etc/ntp.conf. Dalam file /etc/ntp.conf, server waktu yang digunakan adalah:

server time.cloudflare.com iburst
server time.windows.com iburst
server time.nist.gov iburst
server time-a.nist.gov iburst
server time-b.nist.gov iburst
server clock.sjc.he.net iburst
server hydrogen.constant.com iburst
server t1.timegps.net iburst


Jika Anda ingin IP server Anda sebagai alamat server NTP, tambahkan skrip berikut dalam file "/etc/conf".

interface ignore wildcard
interface listen 192.168.5.234

Setelah kita edit file /etc/ntp.conf, lakukan RESTART pada daemon NTP.
root@router2:~ # service ntpd restart
Biasanya daemon NTP tidak langsung tersinkronisasi, tunggu hingga 2 atau 4 jam, bahkan hingga 1 hari, maka daemon NTP sudah SINKRONIS dan siap digunakan.

Untuk lebih memastikan apakah daemon NTP sudah BERJALAN atau belum, lakukanlah pengujian.
root@router2:~ # ps ax | grep ntpd
root@router2:~ # sockstat | grep ntp
root@router2:~ # date
root@router2:~ # ntpq -pn
root@router2:~ # ntpq -p 192.168.9.3
root@router2:~ # ntpdate -q 192.168.9.3
root@router2:~ # ntpdate -q time.cloudflare.com
root@router2:~ # ntpq -p
Saat pengujian menggunakan skrip ntpq -p, gambar yang muncul akan seperti ini:


NTP -p command


Perhatikan garis merah, ikon tersebut menjelaskan:
Sekarang sedikit tentang ikon yang mencari nama rekan:
  1. "*" : The last peer to synchronize.
  2. "+" : "Good" The server is carrying out the update process.
  3. "-" : "Bad" The server does not update.
  4. "x" : Server is not responding
Untuk mengatur sinkronisasi pada Windows XP/7/8, klik kanan pada ikon jam tanggal di kanan bawah, lalu klik Sesuaikan tanggal/waktu, pilih tab Waktu Internet lalu klik Ubah pengaturan.


Setup NTP Server on Windows


Jam berhasil disinkronisasikan dengan 192.168.5.234 yang berarti daemon NTP yang kita konfigurasikan sudah RUNNING, buktinya komputer Windows kita sudah bisa sinkron dengan IP Time Server yang sudah kita konfigurasikan di FreeBSD Server.

Berikut ini adalah skrip lengkap dari file /etc/ntp.conf.
#
# $FreeBSD$
#
# Default NTP servers for the FreeBSD operating system.
#
# Don't forget to enable ntpd in /etc/rc.conf with:
# ntpd_enable="YES"
#
# The driftfile is by default /var/db/ntpd.drift, check
# /etc/defaults/rc.conf on how to change the location.
#
interface ignore wildcard
interface listen 192.168.9.3
#
# Set the target and limit for adding servers configured via pool statements
# or discovered dynamically via mechanisms such as broadcast and manycast.
# Ntpd automatically adds maxclock-1 servers from configured pools, and may
# add as many as maxclock*2 if necessary to ensure that at least minclock
# servers are providing good consistent time.
#
tos minclock 3 maxclock 6

#
# The following pool statement will give you a random set of NTP servers
# geographically close to you.  A single pool statement adds multiple
# servers from the pool, according to the tos minclock/maxclock targets.
# See http://www.pool.ntp.org/ for details.  Note, pool.ntp.org encourages
# users with a static IP and good upstream NTP servers to add a server
# to the pool. See http://www.pool.ntp.org/join.html if you are interested.
#
# The option `iburst' is used for faster initial synchronization.
#
#pool 0.freebsd.pool.ntp.org iburst

#
# If you want to pick yourself which country's public NTP server
# you want to sync against, comment out the above pool, uncomment
# the next one, and replace CC with the country's abbreviation.
# Make sure that the hostname resolves to a proper IP address!
#
#pool 0.nettime.pool.ntp.org iburst

#
# To configure a specific server, such as an organization-wide local
# server, add lines similar to the following.  One or more specific
# servers can be configured in addition to, or instead of, any server
# pools specified above.  When both are configured, ntpd first adds all
# the specific servers, then adds servers from the pool until the tos
# minclock/maxclock targets are met.
#
server time.cloudflare.com iburst
server time.windows.com iburst
server time.nist.gov iburst
server time-a.nist.gov iburst
server time-b.nist.gov iburst
server clock.sjc.he.net iburst
server hydrogen.constant.com iburst
server t1.timegps.net iburst


#
# Security:
#
# By default, only allow time queries and block all other requests
# from unauthenticated clients.
#
# The "restrict source" line allows peers to be mobilized when added by
# ntpd from a pool, but does not enable mobilizing a new peer association
# by other dynamic means (broadcast, manycast, ntpq commands, etc).
#
# See http://support.ntp.org/bin/view/Support/AccessRestrictions
# for more information.
#
#restrict default limited kod nomodify notrap noquery nopeer
#restrict source  limited kod nomodify notrap noquery

#
# Alternatively, the following rules would block all unauthorized access.
#
#restrict default ignore
#
# In this case, all remote NTP time servers also need to be explicitly
# allowed or they would not be able to exchange time information with
# this server.
#
# Please note that this example doesn't work for the servers in
# the pool.ntp.org domain since they return multiple A records.
#
#restrict 0.pool.ntp.org nomodify nopeer noquery notrap
#restrict 1.pool.ntp.org nomodify nopeer noquery notrap
#restrict 2.pool.ntp.org nomodify nopeer noquery notrap
#
# The following settings allow unrestricted access from the localhost
restrict 192.168.9.0 mask 255.255.255.0 nomodify notrap nopeer
restrict ::1
broadcast 192.168.9.255
#
# If a server loses sync with all upstream servers, NTP clients
# no longer follow that server. The local clock can be configured
# to provide a time source when this happens, but it should usually
# be configured on just one server on a network. For more details see
# http://support.ntp.org/bin/view/Support/UndisciplinedLocalClock
# The use of Orphan Mode may be preferable.
#
#server 127.127.1.0
#fudge 127.127.1.0 stratum 10

# See http://support.ntp.org/bin/view/Support/ConfiguringNTP#Section_6.14.
# for documentation regarding leapfile. Updates to the file can be obtained
# from ftp://time.nist.gov/pub/ or ftp://tycho.usno.navy.mil/pub/ntp/.
# Use either leapfile in /etc/ntp or periodically updated leapfile in /var/db.
#leapfile "/etc/ntp/leap-seconds"
leapfile "/var/db/ntpd.leap-seconds.list"
driftfile "/var/db/ntpd.drift"
logfile "/var/log/ntpd.log"


# Specify the number of megabytes of memory that should be allocated and
# locked. -1 (default) means "do not lock the process into memory".
# 0 means "lock whatever memory the process wants into memory". Any other
# number means to lock up to that number of megabytes into memory.
# 0 may result in a segfault when ASLR with stack gap randomization
# is enabled.
#rlimit memlock 32
Selamat!. Anda telah berhasil memasang server NTP di FreeBSD. Sekarang server FreeBSD Anda telah disinkronkan dengan waktu internasional.
Subscribe on LinkedIn Sinkronisasi Jam dan Tanggal Untuk Server FreeBSD Dengan NTP Time Server

Enclosures Link: Sinkronisasi Jam dan Tanggal Untuk Server FreeBSD Dengan NTP Time Server

Silahkan Berkomentar, Kakak...! Bunda...!

Posting Komentar