環境全体ですべてのサーバーの正しい時刻を維持することは、正確性、認証、およびトラブルシューティングに役立ちます。この記事では、 timedatectl
の基本的なコマンドについて説明します。 これを行うのに役立つユーティリティ。
timedatectl
を使用するには、次の前提条件を満たしている必要があります :
- Secure Shell(SSH)の基本を理解している。
- サーバーへのsudoまたは管理アクセス権を持っている。
- サーバーでRedHat®EnterpriseLinux®7または8、またはUbuntu®16または18を実行している。
現在の日時を確認するには、次のコマンドを実行します。
$ timedatectl
Local time: Wed 2020-04-22 09:09:19 EDT
Universal time: Wed 2020-04-22 13:09:19 UTC
RTC time: Wed 2020-04-22 13:09:20
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
systemd-timesyncd.service active: yes
RTC in local TZ: no
日付または時刻を設定するには、 YYYY-MM-DD hh:mm:ss
を使用します コマンドでフォーマットします。必要に応じて日付または時刻を省略します。
日付または時刻を設定するには、次のようなコマンドを実行します。
$ timedatectl set-time <YYYY-MM-DD> <hh:mm:ss>
例:日時:
$ timedatectl set-time 2020-04-22 16:32:05
例:日付のみ:
$ timedatectl set-time 2020-10-03
例:時間のみ:
$ timedatectl set-time 7:00:00
タイムゾーンを設定するには、正しい形式を知っている必要があります。パブリックInternetAssignedNumbers Authority(IANA®)タイムゾーンデータベースに基づいて、タイムゾーンの複数ページのリストを表示できます。次に、 timedatectl set-timezone
を使用して希望のタイムゾーンを入力できます コマンド。
タイムゾーンを一覧表示するには、次のコマンドを実行します。
$ timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
lines 1-47
...
スペースバーを使用して次のページに進みます。最後に到達したら、 Ctrl-Cで終了できます 。
インタラクティブな質疑応答ツールを使用して、使用可能なタイムゾーンの選択肢を確認することもできます。このアクションでは変更が行われないため、 timedatectlset-timezone<を使用して希望のタイムゾーンを入力する必要があります。 / code> コマンド。
インタラクティブツールを使用するには、次のコマンドを実行します。
$ tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
1) Africa
2) Americas
3) Antarctica
4) Asia
5) Atlantic Ocean
6) Australia
7) Europe
8) Indian Ocean
9) Pacific Ocean
10) coord - I want to use geographical coordinates.
11) TZ - I want to specify the time zone using the Posix TZ format.
#?
お住まいの地域で夏時間が採用されている場合は、サーバーの時刻が正確になるように、適切なタイムゾーンを選択してください。
タイムゾーンを設定するには、次のようなコマンドを実行します。
$ timedatectl set-timezone <timezone>
例:中部標準時への変更:
timedatectl set-timezone America/Chicago
timedatectl
でステータスを確認してください タイムゾーンの変更を確認するコマンド:
$ timedatectl
Local time: Wed 2020-04-22 08:38:49 CDT
Universal time: Wed 2020-04-22 13:38:49 UTC
RTC time: Wed 2020-04-22 13:38:51
Time zone: America/Chicago (CDT, -0500)
System clock synchronized: yes
systemd-timesyncd.service active: yes
RTC in local TZ: no
NTP同期を有効または無効にします
ネットワークタイムプロトコル(NTP)同期を追加して、正しい時刻を自動的に維持できます。 timedatectl set-ntp
を実行します。 true
を使用したコマンド またはfalse
次の例に示すような引数:
$ timedatectl set-ntp true
以前のNTPステータスは次のとおりです。
$ timedatectl
Local time: Wed 2020-04-22 09:09:19 EDT
Universal time: Wed 2020-04-22 13:09:19 UTC
RTC time: Wed 2020-04-22 13:09:20
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
systemd-timesyncd.service active: no
RTC in local TZ: no
後のNTPステータスは次のとおりです。
$ timedatectl
Local time: Wed 2020-04-22 09:09:19 EDT
Universal time: Wed 2020-04-22 13:09:19 UTC
RTC time: Wed 2020-04-22 13:09:20
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
systemd-timesyncd.service active: yes
RTC in local TZ: no