도커 컨테이너를 이용하여 NTP 서버 구성
- NTP 서버를 간단하게 구성하기 위해 도커 이미지 사용 (https://hub.docker.com/r/cturra/ntp)
https://hub.docker.com/r/cturra/ntp
hub.docker.com
1. docker-compose.yml 파일 작성
services:
ntp:
image: cturra/ntp:latest
container_name: ntp
restart: always
ports:
- 123:123/udp
environment:
- NTP_SERVERS=kr.pool.ntp.org
- LOG_LEVEL=0
- TZ=Asia/Seoul
그냐 도커로 실행 할 겨우..
더보기
docker run -d --name ntp \
-p 123:123/udp \
-e NTP_SERVERS=kr.pool.ntp.org \
-e LOG_LEVEL=0 \
-e TZ=Asia/Seoul \
--restart unless-stopped \
cturra/ntp:latest
2. 컨테이너 실행
$ docker-compose up -d ntp
[+] Running 4/4
✔ ntp Pulled 8.5s
✔ 38a8310d387e Pull complete 2.1s
✔ 82cb68750db5 Pull complete 2.5s
✔ d01c8cd51586 Pull complete 2.6s
[+] Running 1/1
✔ Container ntp Started
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b3d840f44d2a cturra/ntp:latest "/bin/sh /opt/startu…" 35 seconds ago Up 35 seconds (healthy) 0.0.0.0:123->123/udp ntp
3. 서비스 확인
- Chrony가 현재 사용하는 시간 소스의 상태와 품질 정보 확인
$ docker exec ntp chronyc sources
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 121.174.142.81 3 6 377 23 -13us[+1459us] +/- 43ms
- Chrony의 현재 동기화 상태 및 로컬 시스템 시간의 상태를 확인
$ docker exec ntp chronyc tracking
Reference ID : 79AE8E51 (121.174.142.81)
Stratum : 4
Ref time (UTC) : Mon Jan 20 00:45:09 2025
System time : 0.007815700 seconds slow of NTP time
Last offset : +0.001472252 seconds
RMS offset : 0.001237791 seconds
Frequency : 4.165 ppm fast
Residual freq : +4.040 ppm
Skew : 13.636 ppm
Root delay : 0.021306863 seconds
Root dispersion : 0.033071119 seconds
Update interval : 64.5 seconds
Leap status : Normal
- 123/udp 포트 상태 확인
$ netstat -lnu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
udp 0 0 0.0.0.0:123 0.0.0.0:*
udp 0 0 127.0.0.53:53 0.0.0.0:*
- docker-compose.yml 파일에 설정했던 NTP_SERVERS의 값이 제대로 설정되었는지 확인
$ docker exec ntp cat /etc/chrony/chrony.conf
# https://github.com/cturra/docker-ntp
# chrony.conf file generated by startup script
# located at /opt/startup.sh
# time servers provided by NTP_SERVER environment variables.
server kr.pool.ntp.org iburst
driftfile /var/lib/chrony/chrony.drift
makestep 0.1 3
allow all
4. 시간 동기화 확인
- 다른 서버에서 시간 동기화 진행 (docker2 - ntp 컨테이너가 구성 된 서버)
# ntpdate -u docker2
20 Jan 09:52:24 ntpdate[2903]: adjust time server 192.168.100.149 offset +0.004635 sec