Introduction to Linux TimeZones Setting
In Linux, the timezone is a setting that determines the time offset from the Coordinated Universal Time (UTC) for a specific location. The timezone settings are stored in the file "/etc/localtime" and it can be changed by linking it to the correct timezone file in the "/usr/share/zoneinfo" directory. The command "date" can be used to check the current timezone settings and the command "timedatectl" can be used to set and manage the timezone.
It's important to note that changing the timezone settings will affect all the software and services that rely on the system clock. Therefore, it's recommended to do this during a maintenance window or when the system is not in use.
In summary, Timezone setting in Linux determines the time offset from the Coordinated Universal Time (UTC) for a specific location, the timezone settings are stored in the file "/etc/localtime" and can be changed by linking it to the correct timezone file in the "/usr/share/zoneinfo" directory and can be set and managed by using "timedatectl" command.
Infrastructure
Signup to KodeKloud - Engineer for practicing this task hands-on.
Task Details
During the daily standup, it was pointed out that the timezone across Nautilus Application Servers in Stratos Datacenter doesn't match with that of the local datacenter's timezone, which is America/Blanc-Sablon.
Perform the below commands based on your question server, user name & other details might differ. So please read the task carefully before executing it. All the Best 👍
Solution:
1. At first login on App server & Switch to the root user
Server Name | IP | Hostname | User | Password | Purpose |
stapp01 | 172.16.238.10 | stapp01.stratos.xfusioncorp.com | tony | Ir0nM@n | Nautilus App 1 |
stapp02 | 172.16.238.11 | stapp02.stratos.xfusioncorp.com | steve | Am3ric@ | Nautilus App 2 |
stapp03 | 172.16.238.12 | stapp03.stratos.xfusioncorp.com | banner | BigGr33n | Nautilus App 3 |
thor@jump_host ~$ ssh tony@stapp01
The authenticity of host 'stapp01 (172.16.238.10)' can't be established.
ECDSA key fingerprint is SHA256:2DbVbI7xvrQSSIOQD502dx7BHfADaJEecTxNIX/MmQs.
ECDSA key fingerprint is MD5:c6:8e:51:2e:28:dd:bd:cc:e4:b6:b5:c4:d3:dc:13:e6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'stapp01,172.16.238.10' (ECDSA) to the list of known hosts.
tony@stapp01's password: Ir0nM@n
[tony@stapp01 ~]$ sudo su -
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for tony: Ir0nM@n
[root@stapp01 ~]#
A brief Description about commands "ssh" and "sudo su-" is given in Essential Linux Commands.
2. Check the existing Time Zone set for the server
[root@stapp01 ~]# timedatectl
Local time: Sat 2021-06-12 15:22:41 UTC
Universal time: Sat 2021-06-12 15:22:41 UTC
RTC time: n/a
Time zone: UTC (UTC, +0000)
NTP enabled: n/a
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
[root@stapp01 ~]#
timedatectl
"timedatectl" command is used to manage the system time and date settings, including the timezone. It can be used to check the current time and date settings, as well as to change them.
For example, "timedatectl set-timezone America/New_York" will set the timezone to Eastern Time (ET).
In summary, "timedatectl" is a command that is used to manage the system time and date settings, including the timezone, it can be used to check the current time and date settings, as well as to change them, it also allows checking the NTP (Network Time Protocol) synchronization status.
3. Set the time zone & verify it
[root@stapp01 ~]# timedatectl set-timezone America/Blanc-Sablon
[root@stapp01 ~]# timedatectl
Local time: Sat 2021-06-12 11:25:38 AST
Universal time: Sat 2021-06-12 15:25:38 UTC
RTC time: n/a
Time zone: America/Blanc-Sablon (AST, -0400)
NTP enabled: n/a
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
[root@stapp01 ~]#
You have to do this in all app servers stapp01,stapp02, stapp03. I have shown only for Stapp01
Thank you so much for taking your valuable time to read
I took the initiative to learn in public and share my work with others. I tried my level best in squeezing as much information as possible in the easiest manner. Hope you learned something new today :)
Learn Essential Linux Commands
Signup to KodeKloud - Engineer for practicing these tasks hands-on.
In the next part of this blog, we will study 👇