Skip to content

Alignment datetime on specific sever

Overview

This space control the datetime in a specific server which run on Linux

Methodology

There are 2 styles of control the datetime in the system.

Methodology
Manual
NFS alignment

Method 1: Chain the service

Using following command to updated the current

CURRENT=$(wget -qSO- --max-redirect=0 www.google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z
sudo date -s "$CURRENT"

Detail on NFS alginemtn

Step 1: Validate status

Validate the status of server with your current timestamp. Make sure you align to one timezone.

Following the server has been configuration in Asia/Ho_Chi_Minh and currently it's different 21 min at the time I writed this.

timedatectl status
#       Local time: Sun 2024-06-16 00:01:46 +07
#   Universal time: Sat 2024-06-15 17:01:46 UTC
#         RTC time: Sat 2024-06-15 17:01:47
#        Time zone: Asia/Ho_Chi_Minh (+07, +0700)
#      NTP enabled: n/a
# NTP synchronized: no
#  RTC in local TZ: no
#       DST active: n/a

https://ubuntu.com/server/docs/how-to-serve-the-network-time-protocol-with-chrony

This will provide two binaries:

chronyd - the actual daemon to sync and serve via the Network Time Protocol

chronyc - command-line interface for the chrony daemon

https://ubuntu.com/server/docs/how-to-serve-the-network-time-protocol-with-chrony

● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2024-06-16 01:51:44 +07; 18min ago Docs: man:chronyd(8) man:chrony.conf(5) Process: 13765 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS) Process: 13761 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS) Main PID: 13763 (chronyd) CGroup: /system.slice/chronyd.service └─13763 /usr/sbin/chronyd

Jun 16 01:51:44 localhost.localdomain systemd[1]: Starting NTP client/server... Jun 16 01:51:44 localhost.localdomain chronyd[13763]: chronyd version 3.4 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIVDROP +SCFILTER +SIGND +ASYNCDNS +SECHASH +IPV6 +DEBUG) Jun 16 01:51:44 localhost.localdomain systemd[1]: Started NTP client/server. Jun 16 01:51:53 localhost.localdomain chronyd[13763]: Selected source 103.130.217.41 Jun 16 01:51:53 localhost.localdomain chronyd[13763]: System clock wrong by 1086.272151 seconds, adjustment started Jun 16 02:09:59 localhost.localdomain chronyd[13763]: System clock was stepped by 1086.272151 seconds

How do I use pool.ntp.org? If you just want to synchronise your computers clock to the network, the configuration file (for the ntpd program from the ntp.org distribution, on any supported operating system - Linux, *BSD, Windows and even some more exotic systems) is really simple:

https://www.ntppool.org/en/use.html

https://bugs.launchpad.net/cloud-init/+bug/1885952


https://serverfault.com/questions/1016318/ntp-disable-timesyncd-and-enable-ntp

systemctl disable --now systemd-timesyncd systemctl enable --now ntp Or as Ubuntu and Red Hat are dismissing ntpd as legacy for some reason, chrony is an option

systemctl enable --now chrony Read the timedatectl man page, (this version of) set-ntp only controls systemd-timesyncd. Being a SNTP client, it won't discipline the system clock like a proper NTP. I consider this command a little misleading, and manage the time sync service units directly.


NTP can be installed and configured on Linux in a few simple steps:

Install the NTP service. Modify the NTP configuration file, ‘/etc/ntp.conf’, with required options. Add reference clock peers to the configuration file. Add drift file location to the configuration file . Add optional statistics directory to the configuration file . Enable and start the NTP service. Check operation and synchronization status.


https://timetoolsltd.com/ntp/how-to-install-and-configure-ntp-on-linux/

Examples of Time Setting BAD: setting the time daily at midnight; GOOD: Setting the time at boot and every 36 hours after boot (rather than at a specific time);

BAD: Setting the time every 90 minutes at the “top of the minute” (0 seconds); BETTER: Setting the time every 89 minutes plus random number of seconds between 0 and 120;

BAD – Setting the time every 2 minutes; GOOD – Setting the time according to needs, for example every 4 hours or daily (or less often)

https://www.ntppool.org/tos.html

Source Reference

-o --output=STRING Change journal output mode (short, short-iso, short-precise, short-monotonic, verbose, export, json, json-pretty, json-sse, cat)