環境構築/仮想環境/06.CentOSにおける時刻設定
CentOSにおける時刻設定
CentOS7からはntpdではなくchronyを使用するように推奨されているので、インストールして常駐させるように設定する。
chronyのインストール
yum install を実行してchronyをインストールし、常駐させる。
[vagrant@localhost ~]$ sudo yum install chrony
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.yz.yamagata-u.ac.jp
* extras: ftp.yz.yamagata-u.ac.jp
* updates: ftp.yz.yamagata-u.ac.jp
Resolving Dependencies
--> Running transaction check
---> Package chrony.x86_64 0:1.29.1-1.el7.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
chrony x86_64 1.29.1-1.el7.centos base 253 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 253 k
Installed size: 554 k
Is this ok [y/d/N]: y
Downloading packages:
chrony-1.29.1-1.el7.centos.x86_64.rpm | 253 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : chrony-1.29.1-1.el7.centos.x86_64 1/1
Verifying : chrony-1.29.1-1.el7.centos.x86_64 1/1
Installed:
chrony.x86_64 0:1.29.1-1.el7.centos
Complete!
[vagrant@localhost ~]$ sudo systemctl enable chronyd
[vagrant@localhost ~]$ sudo systemctl status chronyd
chronyd.service - NTP client/server
Loaded
: loaded
(/usr
/lib
/systemd
/system/chronyd
.service
; enabled
) Active: inactive (dead)
- /etc/chrony.conf を書き換え、参照するサーバーを日本のNTPサーバーに設定する。
[vagrant@localhost ~]$ sudo vi /etc/chrony.conf
[/etc/chrony.conf]
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
↓
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst
server ntp.nict.jp iburst
server ntp1.jst.mfeed.ad.jp iburst
server ntp2.jst.mfeed.ad.jp iburst
server ntp3.jst.mfeed.ad.jp iburst
[vagrant@localhost ~]$ sudo systemctl start chronyd
[vagrant@localhost ~]$ chronyc sources -v
210 Number of sources = 4
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state
'*' = current synced
, '+' = combined
, '-' = not combined
, | / '?' = unreachable
, 'x' = time may be in error
, '~' = time too variable
. || .- xxxx [ yyyy ] +/- zzzz
|| / xxxx = adjusted offset,
|| Log2(Polling interval) -. | yyyy = measured offset,
|| \ | zzzz = estimated error.
|| | |
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^- ntp-b3.nict.go.jp 1 6 77 27 +19ms[ +19ms] +/- 32ms
^* ntp1.jst.mfeed.ad.jp 2 6 77 27 +14ms[ +17ms] +/- 30ms
^+ ntp2.jst.mfeed.ad.jp 2 6 77 28 +11ms[ +14ms] +/- 55ms
^- ntp3.jst.mfeed.ad.jp 2 6 77 27 +15ms[ +15ms] +/- 34ms
タイムゾーンの設定
日本人らしく、日本標準時(JST)で時刻が確認できるように設定する。
- PuTTYから以下のコマンドを入力して、現状の設定を確認する。
[vagrant@localhost ~]$ timedatectl
Local
time: Sun
2015-05-17 06:53:47 UTC
Universal
time: Sun
2015-05-17 06:53:47 UTC
Timezone: UTC (UTC, +0000)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
[vagrant@localhost ~]$ timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
--- 中略 ---
Asia/Thimphu
Asia/Tokyo
Asia/Ulaanbaatar
--- 中略 ---
Pacific/Tongatapu
Pacific/Wake
Pacific/Wallis
- タイムゾーンを Asia/Tokyo に設定する。
[vagrant@localhost ~]$ sudo timedatectl set-timezone Asia/Tokyo
[vagrant@localhost ~]$ timedatectl
Local
time: Sun
2015-05-17 15:59:51 JST
Universal
time: Sun
2015-05-17 06:59:51 UTC
Timezone: Asia/Tokyo (JST, +0900)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
[vagrant
@localhost ~
]$
date Sun May 17 16:00:05 JST 2015
最終更新:2015年05月17日 16:31