4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Linux】サーバーの時刻合わせをやってみた

Posted at

dateコマンドを叩いてみた

[root@localhost ~]# date
2093年  2月 13日 月曜日 20:25:22 JST

ちょww
2093年って僕はいないよw
ということでサーバーの時刻が現時刻と合っていないので直していきたいと思います。

環境

CentOS7

時刻合わせをやっていく

date -s "2023/1/1 12:34:56"
date: 日時を設定できません: 無効な引数です

う〜ん。これでできるとネットに書いているけど出来ないな。
timedatectlを使う方法もあるな試してみよう。

timedatectl set-time "2023-02-13 20:25:00"
Failed to set time: Automatic time synchronization is enabled

お、ちょっと違うことが書かれている。
これは行けそう。
調べるとNTP enabledがyesだとエラーになる。

timedatectl status
      Local time: 月 2093-02-13 20:25:18 JST
  Universal time: 月 2093-02-13 11:25:18 UTC
        RTC time: 月 2093-02-13 11:25:18
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

それじゃ変更しちゃいましょ。

timedatectl set-ntp no

そして本題の時刻合わせをやっちゃおう。
NTPの設定も戻しておくよ。

timedatectl set-time "2023-02-13 20:25:00"
timedatectl set-ntp yes

エラーは出てないから出来たんじゃないかな。

timedatectl status
      Local time: 月 2023-02-13 20:25:18 JST
  Universal time: 月 2023-02-13 11:25:18 UTC
        RTC time: 月 2023-02-13 11:25:18
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

大丈夫そうだ!
dateも確認してみよう。

date
2023年  2月 13日 月曜日 20:25:22 JST

やった〜できた〜!

注意

timedatectl statusの内容で時間に関しては適当に変更しています。

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?