본문으로 바로가기

CentOS7 NTP 시간동기화

category Gift/Linux 2017. 8. 23. 16:31


시간을 동기화하는 방법으로는 NTP와 rdate를 이용하는 방법이 있습니다.

소수점까지 정확한 단위의 동기화가 필요하다면 원자단위의 NTP를 이용하는게 좋습니다.


NTP(Network Time Protocol)이란?

  • 네트웍으로 연결되어 있는 컴퓨터들끼리 클록 시각을 동기화시키는데 사용되는 프로토콜이다.
  • 미국 델라웨어 대학의 데이빗 밀스에 의해 처음 개발되었으나, 이제는 인터넷 표준이 되었다.
  • 컴퓨터 클록 시간을 1/1000 초 이하까지 동기화시키기 위해 협정 세계시각(UTC)을 사용하게 됩니다. 

우리나라에서 운영되고 있는 NTP 서버
  • kr.pool.ntp.org
  • time.bora.net
  • time.nuri.net

1. NTP 설치
[root@localhost ~] rpm -qa | grep ntp
[root@localhost ~] yum install ntp

  ================================================================================
   Package             Arch       Version                       Repository   Size
  ================================================================================
  Installing:
   ntp                 x86_64     4.2.6p5-25.el7.centos.2       updates     547 k
  Installing for dependencies:
  autogen-libopts     x86_64     5.18-5.el7                    base         66 k
  ntpdate             x86_64     4.2.6p5-25.el7.centos.2       updates      86 k

  Transaction Summary
  ================================================================================
  Install  1 Package (+2 Dependent packages)


2. NTP 설정

[root@localhost ~] firewall-cmd --permanent --add-service=ntp
success
[root@localhost ~] iptables -L | grep ntp
ACCEPT     udp  --  anywhere             anywhere             udp dpt:ntp ctstate NEW

NTP는 UDP 123Port 를 기본으로 사용합니다. 따라서 방화벽에서 UDP/123 을 허용해주세요.
--permanent 옵션을 줘야 재부팅후에도 적용이됩니다.


[root@localhost ~] vi /etc/ntp.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
  server kr.pool.ntp.org
  server time.bora.net
  server time.kornet.net

기본으로 입력돼있는 서버리스트들은 주석처리 해주시고 우리나라 NTP 서버 작성해줍니다.



3. NTP 실행

NTP 서비스를 재부팅시 자동으로 시작되게 해주고, NTP 서비스를 시작 및 작동확인

[root@localhost ~] chkconfig ntpd on
  Note: Forwarding request to 'systemctl enable ntpd.service'.
  Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@localhost ~] systemctl start ntpd.service
[root@localhost ~] systemctl status ntpd.service
  [0m ntpd.service - Network Time Service
     Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
     Active: active (running) since Wed 2017-08-23 09:40:36 EDT; 5s ago

[root@localhost ~] ntpq -p
       remote           refid      st t when poll reach   delay   offset  jitter
  ==============================================================================
  *send.mx.cdnetwo 204.123.2.5      2 u   16   64  377    1.841  1167.17 617.926
  +time.bora.net   220.117.243.35   3 u    3   64  367   15.622  1207.32 666.328
동기화까지는 5~10분정도 시간이 소요됩니다.
*  : 현재 해당서버와 동기화중임
:  ntp 알고리즘에 의해 접속은 가능하지만 동기화를 하고 있지는 않음
-  :  ntp 알고리즘에 의해 접속은 가능하지만 동기화 가능 리스트에서 제외
blank : 연결 불가능