[Archive 1.0] 1. Time Zone and NTP - mata-elang-stable/MataElang-Platform GitHub Wiki
Time Synchronization
Time is of great importance.
If your servers are put on closed network, where the Internet is not available, you need to "Build a local NTP server" on your network.
If not, servers can refer to NTP servers on the Internet. In this case, You don't need "Build a local NTP server" but "Setup NTP clients" on all servers.
As for the time zone, this document assumes that you use "Asia/Jakarta" time zone. However, if you manage multiple sensors over different time zones, it is better to set the time zone to "UTC".
Setup NTP Client
1. Configure your time zone.
- Change according to your time zone.
- If you want to see the list of time zone, use
timedatectl list-timezones
command.
sudo timedatectl set-timezone Asia/Jakarta
2. RTC (Real Time Clock) is set to UTC.
sudo timedatectl set-local-rtc false
3. Enable NTP client for time synchronization.
sudo timedatectl set-ntp true
4. Edit "timesyncd.conf" to specify your NTP servers.
sudo nano /etc/systemd/timesyncd.conf
- Configuration: set your NTP server according to your environment.
#NTP=
NTP=0.id.pool.ntp.org
5. Restart the time synchronization service and confirm the service is active.
sudo systemctl restart systemd-timesyncd
systemctl status systemd-timesyncd
6. Check the time and date configuration at the end.
timedatectl
- Result
Local time: Mon 2021-08-23 20:14:02 WIB
Universal time: Mon 2021-08-23 13:14:02 UTC
RTC time: Mon 2021-08-23 13:14:02
Time zone: Asia/Jakarta (WIB, +0700)
System clock synchronized: yes
systemd-timesyncd.service active: yes
RTC in local TZ: no
Build a local NTP Server
(optional) If the Internet is not available, build the server on defence center
1. Configure your time zone.
- Change according to your time zone.
- If you want to see the list of time zone, use
timedatectl list-timezones
command.
sudo timedatectl set-timezone Asia/Jakarta
2. RTC (Real Time Clock) is set to UTC.
sudo timedatectl set-local-rtc false
3. Check the time and date configuration.
timedatectl
- Result
Local time: Mon 2021-08-23 20:14:02 WIB
Universal time: Mon 2021-08-23 13:14:02 UTC
RTC time: Mon 2021-08-23 13:14:02
Time zone: Asia/Jakarta (WIB, +0700)
System clock synchronized: yes
systemd-timesyncd.service active: yes
RTC in local TZ: no
4. Install NTP server for time synchronization.
sudo apt update && sudo apt -y upgrade
sudo apt -y install ntp
5. Edit "ntp.conf" for a closed network.
sudo nano /etc/ntp.conf
- Configuration: set your network configuration.
### Line 21-24: Comment out the default NTP servers.
#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
### Line 27: Comment out Ubuntu's NTP server
#pool ntp.ubuntu.com
### Line 52: Add a restriction of time synchronization
restrict <YOUR_NETWORK_ADDRESS (e.g. 172.20.1.0)> mask <NETMASK (e.g. 255.255.255.0)> notrap nomodify
### Line 71-73: Add the local clock settings at the end of file
server 127.127.1.0 prefer
fudge 127.127.1.0 stratum 10
6. Start the NTP service and confirm the service is active.
sudo systemctl restart ntp
systemctl status ntp
7. Confirm that NTP server is working with its own clock.
ntpq -p
- Result
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 10 l 19 64 1 0.000 0.000 0.000