서버/Linux III 2016. 4. 19. 11:23

Linux III - 14. NTP 서버 & 클라이언트

 

 

 

login as: root
root@192.168.1.100's password:
Last login: Tue Apr 19 09:39:28 2016 from 192.168.1.1
[root@main /root]#

 

 

login as: root
root@192.168.1.101's password:
Last login: Tue Apr 19 09:47:50 2016 from 192.168.1.1
[root@clone1 /root]#

 

 

 

 

1. NTP(Network Time Protocol)

 

NTP는 네트워크를 통하여 서버와 클라이언트 및 장비간에 시간을 동기화하는 기능을 수행한다. 이때, NTP 메세지는 UDP 123번 포트 번호를 사용한다.

 

 

 

 

2. NTP 서비스 필요성

 

네트워크를 통하여 상호 연동하는 서비스간에 시간이 일치하지 않으면, 장애 처리, 성능 분석, 로그 확인 등 문제점을 갖게된다. 그렇기 때문에 다음과 같은 서비스 환경에서는 NTP 서비스를 무조건 사용하는 것을 권장한다.

 

 - 자원 공유 서버(NFS Server)

 - 데이터베이스 서버(DB Server)

 - 로그 서버(Logging Server)

 - NMS(Networm Management Solutiono)

 - 암호화/인증/키 교환 환경

 

 

 

 

3. NTP 용어

 

 용어

내용 

 xntpd

 NTP 서버/클라이언트 데몬

 ntp.conf

 NTP 서버/클라이언트 설정 파일

 Reference Clock

 GMT, UTC와 같은 표준 시간 및 참고 시간

 Stratum

 NTP 계층적 구조 참조 값(1~15), 값이 작을수록 상위 NTP 서버

 Drift File

 PPM(Parts Per Million) 단위로 오프셋에 일치하는 단일 부동 소수점

 Resolution

 시간 제공 장치에서 사용하는 시간의 최소 단위

 Precision

 컴퓨터 프로그램에서 사용하는 시간의 최소 단위

 Accuracy

 시간의 정확도, 기준 시간과 얼마나 근접한지를 표기함

 Jitter

 시간을 측정했을 때 발생하는 오차 중 작은 값

 Wander

 시간을 측정했을 때 발생하는 오차 중 큰 값

 

 

 

 

4. NTP 서버 & 클라이언트 구성

 

 - main과 clone1에서 NTP 패키지 설치를 실시한다.

 

[root@main /root]# rpm -qa | grep ntp
fontpackages-filesystem-1.41-1.1.el6.noarch
ntpdate-4.2.6p5-1.el6.centos.x86_64
ntp-4.2.6p5-1.el6.centos.x86_64

 

 

[root@main /root]# yum -y install ntp

~ 중간 생략 ~

 

Updated:
  ntp.x86_64 0:4.2.6p5-5.el6.centos.4

Dependency Updated:
  ntpdate.x86_64 0:4.2.6p5-5.el6.centos.4

Complete!

 


[root@main /root]# rpm -qa | grep ntp
ntpdate-4.2.6p5-5.el6.centos.4.x86_64
fontpackages-filesystem-1.41-1.1.el6.noarch
ntp-4.2.6p5-5.el6.centos.4.x86_64

 

 

 

 - main과 clone1에서 ntp 서비스 활성화 상태를 확인한다.


[root@main /root]# service ntpd status
ntpd (pid  11213)를 실행하고 있습니다..

 

 

[root@main /root]# chkconfig --list ntpd
ntpd            0:해제  1:해제  2:활성  3:활성  4:활성  5:활성  6:해제

 

 

 

 - main에서 '/etc/ntp.conf' 설정 파일을 vi 편집기를 이용하여 실행한다.

 

[root@main /root]# vi /etc/ntp.conf

~ 중간 생략 ~

 

 17 # Hosts on local network are less restricted.
 18 #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
 19 restrict 172.20.0.0 mask 255.255.0.0 nomodify notrap
 20
 21 # Use public servers from the pool.ntp.org project.
 22 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
 23 # server 0.centos.pool.ntp.org iburst
 24 # server 1.centos.pool.ntp.org iburst
 25 # server 2.centos.pool.ntp.org iburst
 26 # server 3.centos.pool.ntp.org iburst
 27 server 127.127.1.0

 

~ 중간 생략 ~

 

: wq! 

 

 

 -  테스트를 하기 위해서 main에서 시간을 수동으로 변경하도록 한다.

 

[root@main /root]# date 122514002014

2014. 12. 25. () 14:00:00 KST

[

[root@main /root]# date

2014. 12. 25. () 14:00:04 KST

 

 

 

 - main에서 ntp 서비스를 재시작하고, NTP 서비스 실시 내용을 확인한다.


[root@main /root]# service ntpd restart
ntpd 종료 중:                                              [  OK  ]
ntpd (을)를 시작 중:                                       [  OK  ]

 

[root@main /root]# pgrep -lf ntpd
11367 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g

 


[root@main /root]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(0)        .LOCL.           5 l   14   64    1    0.000    0.000   0.000

 

 

 

 - clone1에서 다음과 같이 '/etc/ntp.conf'에서 NTP 서버를 지정하도록 한다.

 

 

[root@clone1 /root]# vi /etc/ntp.conf

 ~ 중간 생략 ~

 

 19
 20 # Use public servers from the pool.ntp.org project.
 21 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
 22 # server 0.centos.pool.ntp.org iburst
 23 # server 1.centos.pool.ntp.org iburst
 24 # server 2.centos.pool.ntp.org iburst
 25 # server 3.centos.pool.ntp.org iburst
 26 server 172.20.1.1 prefer       

~ 중간 생략 ~


: wq! 

 

 

[참고] prefer

 

 - Stratum 값이 동일한 NTP 서버가 다수인 경우, 'prefer' 명령어를 이용하여 NTP 서버를 지정한다.

 

 

 

 - clone1에서 ntp 서비스를 재시작하고, NTP 동기화 내용을 확인한다.


[root@clone1 /root]# service ntpd restart
ntpd 종료 중:                                              [  OK  ]
ntpd (을)를 시작 중:                                       [  OK  ]

 


[root@clone1 /root]# pgrep -lf ntpd
4014 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g

 

 

[root@clone1 /root]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter

=========================================================

 main            LOCAL(0)         6 u    6   64    1    0.414  -601467   0.000

 

 

[root@clone1 /root]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter

=========================================================

*main            LOCAL(0)         6 u   58   64  377    0.245    0.224   0.102


 

[참고] remote 기호

 

공백 : NTP 서버 없음

* : 동기화 됨

+ : NTP 서버 연결 가능, 단 동기화 안된 상태

 

 

 

실제 환경에서는 다음과 같이 실제 NTP 서버로부터 동기화 받아서 사용하는 것을 권장한다. (clone1에서도 실시)

 

[root@main /root]# rdate -s time.bora.net

[root@main /root]# date

2016. 11. 20. () 16:22:42 KST

 

[root@main /root]# ntpdate -b time.bora.net

20 Nov 16:23:02 ntpdate[23539]: the NTP socket is in use, exiting

 

Posted by 김정우 강사(카카오톡 : kim10322)
,


Q