【Linuxメモ】サーバーの時刻がずれていたのでntpdateコマンドで自動で調整するようにした。

P1030055

Linuxサーバーの時刻の調整はntpdateを使うわけです。

# cat /etc/redhat-release
CentOS release 6.3 (Final)
#

OSは上のとおりで、Cent OS release 6.3です。

SaaSesのVPSなわけですが、2台借りています。そのうち1台は時刻がずれないので新しく借りた方も大丈夫なのだろうと思ってたら、今日見たら5分位ずれてました。

なので、ntpdateで調整しようとしたら、入ってなかったので、yumからインストールしました。

# yum info ntpdate
Loaded plugins: downloadonly, fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
base                                                                                                   | 3.7 kB     00:00
extras                                                                                                 | 3.5 kB     00:00
updates                                                                                                | 3.4 kB     00:00
Available Packages
Name        : ntpdate
Arch        : i686
Version     : 4.2.4p8
Release     : 3.el6.centos
Size        : 57 k
Repo        : base
Summary     : Utility to set the date and time via NTP
URL         : http://www.ntp.org
License     : (MIT and BSD and BSD with advertising) and GPLv2
Description : ntpdate is a program for retrieving the date and time from
            : NTP servers.

#

yum info ntpdateまたはyum info ntpで行けると思います。

# yum install ntpdate
Loaded plugins: downloadonly, fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package ntpdate.i686 0:4.2.4p8-3.el6.centos will be installed
–> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================
Package                     Arch                     Version                                  Repository                Size
==============================================================================================================================
Installing:
ntpdate                     i686                     4.2.4p8-3.el6.centos                     base                      57 k

Transaction Summary
==============================================================================================================================
Install       1 Package(s)

Total download size: 57 k
Installed size: 70 k
Is this ok [y/N]: y
Downloading Packages:
ntpdate-4.2.4p8-3.el6.centos.i686.rpm                                                                  |  57 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : ntpdate-4.2.4p8-3.el6.centos.i686                                                                          1/1
  Verifying  : ntpdate-4.2.4p8-3.el6.centos.i686                                                                          1/1

Installed:
  ntpdate.i686 0:4.2.4p8-3.el6.centos

Complete!
#

yum install ntpdateでインストール出来ました。

ntpdateで見つからないと時は単にntpで行けると思います。

# crontab -e

そして毎日自動で時刻を調整するようにcrontabに追加。

00  09 * * * /usr/sbin/ntpdate -s -b -u ntp.jst.mfeed.ad.jp > /dev/null 2>&1

cronに上の行を追加して毎日9時に時刻を調整するようにしました。

ntpサーバーは下記ページの推奨公開サーバを指定しました。SaaSesのntpサーバがわからなかったので。

NTP/推奨公開サーバ – wiki@nothing

# /usr/sbin/ntpdate -u ntp.jst.mfeed.ad.jp
10 Jun 13:56:41 ntpdate[4357]: adjust time server 210.173.160.57 offset 0.003855 sec

コマンドラインから実行してみると上の様になります。

オプションとしては詳細はmanコマンドで見るとして、-sはサイレントでcronに登録するときには基本的に指定。 -bはファイヤーウォールを超えるのに必要だったと思いますが、最近はいるのかどうかイマイチわかりません。うまくいかない時は付けてみるくらいの感じ。

(Visited 90 times, 1 visits today)

タグ :