NTP 설정은 어떻게 하나요?
💡 요약 정리
- NTP(Network Time Protocol) 설정은 서버 시간 동기화를 위해 중요합니다.
- ntp 패키지 설치 여부를 확인하고, 필요시 yum으로 설치하세요.
- 부팅 시 ntpd 데몬이 자동으로 실행되도록 설정합니다.
- ntpd.conf 파일에 NTP 서버 정보를 추가해야 합니다.
- 데몬 실행 후
ntpq -p명령으로 동기화 상태를 확인하세요. - 로그 파일(
/var/log/messages)을 통해 정상 동작 여부를 확인할 수 있습니다.
1. ntp 패키지 설치 여부 확인
서버에 ntp 패키지가 설치되어 있는지 확인합니다.
[root@localhost etc]# rpm -qa | grep ntp
ntp-4.2.0.a.20040617-4
[root@localhost etc]#
- ntp 패키지가 설치되어 있지 않은 경우에는
yum명령을 이용해 설치해야 합니다.
2. 서버 부팅 시 ntp 활성화 여부 확인
chkconfig 명령어로 ntpd 데몬의 실행 레벨을 확인합니다.
[root@localhost etc]# chkconfig --list | grep ntp
ntpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost etc]#
chkconfig명령으로 3, 5 runlevel에on으로 설정하여 부팅 시 ntpd 데몬이 자동 실행되도록 구성합니다.
[root@localhost etc]# chkconfig --level 3 ntpd on
[root@localhost etc]# chkconfig --level 5 ntpd on
[root@localhost etc]# chkconfig --list | grep ntp
ntpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@localhost etc]#
3. ntpd.conf 파일 설정
ntp 서버 정보를 /etc/ntpd.conf 파일에 추가합니다.
[root@localhost etc]#vi /etc/ntpd.conf
restrict default nomodify notrap noquery아래에 다음 내용의 NTP 서버를 추가합니다.
server kr.pool.ntp.org
server asia.pool.ntp.org
server pool.ntp.org
4. ntpd 데몬 실행
[root@localhost etc]#/etc/rc.d/init.d/ntp start
5. ntpd 시간 확인
[root@localhost etc]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
58.73.137.250 .INIT. 16 u - 64 0 0.000 0.000 4000.00
58.73.137.250 .INIT. 16 u - 64 0 0.000 0.000 4000.00
218.234.23.44 .INIT. 16 u - 64 0 0.000 0.000 4000.00
+218.234.23.44 211.115.194.21 3 u 4 64 377 6.229 18.609 5.512
58.73.137.250 .INIT. 16 u - 64 0 0.000 0.000 4000.00
*58.73.137.250 .GPS. 1 u 60 64 377 11.497 13.709 7.218
LOCAL(0) LOCAL(0) 10 l 53 64 377 0.000 0.000 0.001
[root@localhost etc]#
*표시된 IP 주소가 현재 시간을 가져오고 있는 NTP 서버입니다.
6. /var/log/messages 확인
[root@reyad etc]# tail -f /var/log/messages
Mar 18 09:40:18 reyad ntpd: ntpd shutdown succeeded
Mar 18 09:40:20 reyad ntpd[12506]: ntpd 4.2.0a@1.1190-r Mon Oct 11 09:10:20 EDT 2004 (1)
Mar 18 09:40:20 reyad ntpd[12506]: precision = 1.000 usec
Mar 18 09:40:20 reyad ntpd[12506]: Listening on interface wildcard, 0.0.0.0#123
Mar 18 09:40:20 reyad ntpd[12506]: Listening on interface wildcard, ::#123
Mar 18 09:40:20 reyad ntpd[12506]: Listening on interface lo, 127.0.0.1#123
Mar 18 09:40:20 reyad ntpd[12506]: Listening on interface eth0, 192.168.0.222#123
Mar 18 09:40:20 reyad ntpd[12506]: kernel time sync status 0040
Mar 18 09:40:20 reyad ntpd: ntpd startup succeeded
Mar 18 09:40:24 reyad ntpd[12506]: frequency initialized 0.000 PPM from /var/lib/ntp/drift