環境構築/仮想環境/06.CentOSにおける時刻設定


CentOSにおける時刻設定

CentOS7からはntpdではなくchronyを使用するように推奨されているので、インストールして常駐させるように設定する。


chronyのインストール

yum install を実行してchronyをインストールし、常駐させる。
  • PuTTYから以下のコマンドを入力する。
  1. [vagrant@localhost ~]$ sudo yum install chrony
  2. Loaded plugins: fastestmirror
  3. Loading mirror speeds from cached hostfile
  4. * base: ftp.yz.yamagata-u.ac.jp
  5. * extras: ftp.yz.yamagata-u.ac.jp
  6. * updates: ftp.yz.yamagata-u.ac.jp
  7. Resolving Dependencies
  8. --> Running transaction check
  9. ---> Package chrony.x86_64 0:1.29.1-1.el7.centos will be installed
  10. --> Finished Dependency Resolution
  11.  
  12. Dependencies Resolved
  13.  
  14. ================================================================================
  15. Package Arch Version Repository Size
  16. ================================================================================
  17. Installing:
  18. chrony x86_64 1.29.1-1.el7.centos base 253 k
  19.  
  20. Transaction Summary
  21. ================================================================================
  22. Install 1 Package
  23.  
  24. Total download size: 253 k
  25. Installed size: 554 k
  26. Is this ok [y/d/N]: y
  27. Downloading packages:
  28. chrony-1.29.1-1.el7.centos.x86_64.rpm | 253 kB 00:00
  29. Running transaction check
  30. Running transaction test
  31. Transaction test succeeded
  32. Running transaction
  33. Installing : chrony-1.29.1-1.el7.centos.x86_64 1/1
  34. Verifying : chrony-1.29.1-1.el7.centos.x86_64 1/1
  35.  
  36. Installed:
  37. chrony.x86_64 0:1.29.1-1.el7.centos
  38.  
  39. Complete!
  40.  

  • chronyを常駐させる。
  1. [vagrant@localhost ~]$ sudo systemctl enable chronyd
  2. [vagrant@localhost ~]$ sudo systemctl status chronyd
  3. chronyd.service - NTP client/server
  4. Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled)
  5. Active: inactive (dead)
  6.  

  • /etc/chrony.conf を書き換え、参照するサーバーを日本のNTPサーバーに設定する。
  1. [vagrant@localhost ~]$ sudo vi /etc/chrony.conf
  2.  

[/etc/chrony.conf]
  1. # Use public servers from the pool.ntp.org project.
  2. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  3. server 0.centos.pool.ntp.org iburst
  4. server 1.centos.pool.ntp.org iburst
  5. server 2.centos.pool.ntp.org iburst
  6. server 3.centos.pool.ntp.org iburst
  7.  
  1. # Use public servers from the pool.ntp.org project.
  2. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
  3. # server 0.centos.pool.ntp.org iburst
  4. # server 1.centos.pool.ntp.org iburst
  5. # server 2.centos.pool.ntp.org iburst
  6. # server 3.centos.pool.ntp.org iburst
  7. server ntp.nict.jp iburst
  8. server ntp1.jst.mfeed.ad.jp iburst
  9. server ntp2.jst.mfeed.ad.jp iburst
  10. server ntp3.jst.mfeed.ad.jp iburst
  11.  

  • chronyを起動する。
  1. [vagrant@localhost ~]$ sudo systemctl start chronyd
  2.  

  • chronyの状態を確認する。
  1. [vagrant@localhost ~]$ chronyc sources -v
  2. 210 Number of sources = 4
  3.  
  4. .-- Source mode '^' = server, '=' = peer, '#' = local clock.
  5. / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
  6. | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
  7. || .- xxxx [ yyyy ] +/- zzzz
  8. || / xxxx = adjusted offset,
  9. || Log2(Polling interval) -. | yyyy = measured offset,
  10. || \ | zzzz = estimated error.
  11. || | |
  12. MS Name/IP address Stratum Poll Reach LastRx Last sample
  13. ===============================================================================
  14. ^- ntp-b3.nict.go.jp 1 6 77 27 +19ms[ +19ms] +/- 32ms
  15. ^* ntp1.jst.mfeed.ad.jp 2 6 77 27 +14ms[ +17ms] +/- 30ms
  16. ^+ ntp2.jst.mfeed.ad.jp 2 6 77 28 +11ms[ +14ms] +/- 55ms
  17. ^- ntp3.jst.mfeed.ad.jp 2 6 77 27 +15ms[ +15ms] +/- 34ms
  18.  

タイムゾーンの設定

日本人らしく、日本標準時(JST)で時刻が確認できるように設定する。
  • PuTTYから以下のコマンドを入力して、現状の設定を確認する。
  1. [vagrant@localhost ~]$ timedatectl
  2. Local time: Sun 2015-05-17 06:53:47 UTC
  3. Universal time: Sun 2015-05-17 06:53:47 UTC
  4. Timezone: UTC (UTC, +0000)
  5. NTP enabled: yes
  6. NTP synchronized: yes
  7. RTC in local TZ: no
  8. DST active: n/a
  9.  

  • 設定できるタイムゾーンの一覧を確認する。
  1. [vagrant@localhost ~]$ timedatectl list-timezones
  2. Africa/Abidjan
  3. Africa/Accra
  4. Africa/Addis_Ababa
  5.  
  6. --- 中略 ---
  7.  
  8. Asia/Thimphu
  9. Asia/Tokyo
  10. Asia/Ulaanbaatar
  11.  
  12. --- 中略 ---
  13.  
  14. Pacific/Tongatapu
  15. Pacific/Wake
  16. Pacific/Wallis
  17.  

  • タイムゾーンを Asia/Tokyo に設定する。
  1. [vagrant@localhost ~]$ sudo timedatectl set-timezone Asia/Tokyo
  2.  

  • 念のため、確認する。
  1. [vagrant@localhost ~]$ timedatectl
  2. Local time: Sun 2015-05-17 15:59:51 JST
  3. Universal time: Sun 2015-05-17 06:59:51 UTC
  4. Timezone: Asia/Tokyo (JST, +0900)
  5. NTP enabled: yes
  6. NTP synchronized: yes
  7. RTC in local TZ: no
  8. DST active: n/a
  9. [vagrant@localhost ~]$ date
  10. Sun May 17 16:00:05 JST 2015
  11.  


タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2015年05月17日 16:31