본문 바로가기
SW 프로그래밍/센토스(CenTOS)

센토스7 시간동기화

by N2info 2020. 4. 26.

시간을 동기화하기 위해 과거에는 ntpd 데몬을 사용했지만, 이제는 좀 더 좋은 chrony를 사용할 수 있다.

먼저 chrony 패키지를 설치한다.

[root@localhost /var/lib/php]# yum install -y chrony
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                 | 6.1 kB  00:00:00
 * base: mirror.kakao.com
 * epel: ftp.jaist.ac.jp
 * extras: mirror.kakao.com
 * updates: mirror.kakao.com
base                                                                                                 | 3.6 kB  00:00:00
epel                                                                                                 | 4.7 kB  00:00:00
extras                                                                                               | 2.9 kB  00:00:00
updates                                                                                              | 2.9 kB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package chrony.x86_64 0:3.4-1.el7 will be installed
--> Processing Dependency: libseccomp.so.2()(64bit) for package: chrony-3.4-1.el7.x86_64
--> Running transaction check
---> Package libseccomp.x86_64 0:2.3.1-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================
 Package                        Arch                       Version                           Repository                Size
============================================================================================================================
Installing:
 chrony                         x86_64                     3.4-1.el7                         base                     251 k
Installing for dependencies:
 libseccomp                     x86_64                     2.3.1-3.el7                       base                      56 k

Transaction Summary
============================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 306 k
Installed size: 788 k
Downloading packages:
(1/2): chrony-3.4-1.el7.x86_64.rpm                                                                   | 251 kB  00:00:00
(2/2): libseccomp-2.3.1-3.el7.x86_64.rpm                                                             |  56 kB  00:00:00
----------------------------------------------------------------------------------------------------------------------------
Total                                                                                       2.3 MB/s | 306 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libseccomp-2.3.1-3.el7.x86_64                                                                            1/2
  Installing : chrony-3.4-1.el7.x86_64                                                                                  2/2
  Verifying  : libseccomp-2.3.1-3.el7.x86_64                                                                            1/2
  Verifying  : chrony-3.4-1.el7.x86_64                                                                                  2/2

Installed:
  chrony.x86_64 0:3.4-1.el7

Dependency Installed:
  libseccomp.x86_64 0:2.3.1-3.el7

Complete!
[root@localhost /var/lib/php]#

 

패키지는 chrony이지만, 실행 데몬 이름은 chronyd이다. 먼저 상태를 보면, 아직 실행 중은 아니다.

[root@localhost /var/lib/php]# systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:chronyd(8)
           man:chrony.conf(5)

chronyd를 실행후 확인

[root@localhost /var/lib/php]# systemctl start chronyd
[root@localhost /var/lib/php]# systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-04-26 18:25:26 KST; 2s ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
  Process: 11852 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)
  Process: 11848 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 11850 (chronyd)
   CGroup: /system.slice/chronyd.service
           └─11850 /usr/sbin/chronyd

Apr 26 18:25:26 localhost.localdomain systemd[1]: Starting NTP client/server...
Apr 26 18:25:26 localhost.localdomain chronyd[11850]: chronyd version 3.4 starting (+CMDMON +NTP +REFCLOCK +RTC +PRIV...BUG)
Apr 26 18:25:26 localhost.localdomain systemd[1]: Started NTP client/server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost /var/lib/php]# 

부팅 이후에도 실행되도록 설정한다. timedatectl 커맨드로 시간 정보를 확인하고, NTP 동기되어 있는지 확인한다. 

[root@localhost /var/lib/php]# systemctl enable chronyd
[root@localhost /var/lib/php]# timedatectl
      Local time: Sun 2020-04-26 18:26:13 KST
  Universal time: Sun 2020-04-26 09:26:13 UTC
        RTC time: Sun 2020-04-26 18:26:13
       Time zone: Asia/Seoul (KST, +0900)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
[root@localhost /var/lib/php]# 

[root@localhost /var/lib/php]# timedatectl  | grep "NTP synchronized"
NTP synchronized: yes
[root@localhost /var/lib/php]#

만약 NTP synchronized: no라면 다음 명령어를 사용한다.

 

$ sudo timedatectl set-ntp yes

 

chrony가 시간 동기화를 제대로 진행하고 있는지 확인한다.

[root@localhost /var/lib/php]# chronyc tracking
Reference ID    : 0DD15432 (ec2-13-209-84-50.ap-northeast-2.compute.amazonaws)
Stratum         : 3
Ref time (UTC)  : Sun Apr 26 09:30:59 2020
System time     : 0.000062582 seconds slow of NTP time
Last offset     : -0.000211937 seconds
RMS offset      : 0.000590429 seconds
Frequency       : 7.488 ppm slow
Residual freq   : -0.083 ppm
Skew            : 3.242 ppm
Root delay      : 0.004435404 seconds
Root dispersion : 0.000844962 seconds
Update interval : 65.2 seconds
Leap status     : Normal
[root@localhost /var/lib/php]#

chrony가 동기화에 사용되는 네트워크를 확인한다.

[root@localhost /var/lib/php]# chronyc sources
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^- 106.247.248.106               2   6   377    24   +498us[ +519us] +/-   28ms
^- dadns.cdnetworks.co.kr        2   6   377    23  +2238us[+2259us] +/-   49ms
^- send.mx.cdnetworks.com        2   6   377    24   -596us[ -575us] +/-   75ms
^* ec2-13-209-84-50.ap-nort>     2   6   377    22    +52us[  +73us] +/- 3287us
[root@localhost /var/lib/php]#


출처: https://knight76.tistory.com/entry/centos7-시간-동기화-하기-chrony [김용환 블로그(2004-2020)]

 

 

http://gosu250.blog.me/221119593871

 

 

NTP 가동/중지/확인

* ntp 패키지 설치#yum install ntp 1. NTP 상태 확인(서비스가 시작되어 있어야 조회됨)[root@UCS-...

blog.naver.com