본문 바로가기
리눅스(Linux)

[Linux] 리눅스 시간 동기화 방법

by virusuk 2025. 3. 23.
반응형

서버들 간 클러스터링 또는 통신하는 경우, 서로 시간 동기화를 통해 시간을 맞춰야하는 경우가 있습니다.

그래서, 서버들 간 시간을 동기화하기 위해 자체 타임서버를 구축하여 동기화하는 방법을 알아보겠습니다.

 

NTP(Network Time Protocol)을 이용하여 시스템의 시각을 현재 시각으로 설정하여 시간 동기화를 해보겠습니다.

 

NTP란?

  • NTP(Network Time Protocol)는 네트워크 환경으로 구성되는 시스템들의 시간을 동기화하기 위한 규약(Protocol)입니다.

공용 NTP서버로는 time.bora.net 등을 많이 사용하는데, 해당 공용 NTP 서버를 이용해보겠습니다.

 

리눅스에서 시간 동기화 설정

1. KST (Korea Standard Time) 국가로 타임존 설정

[root@localhost ~]# timedatectl set-timezone Asia/Seoul

 

2. chrony 데몬인 chronyd으로 시간 동기화

[root@localhost ~]# vi /etc/chrony.conf

 

3. 7행과 같이 server <NTP 주소> iburst 입력

  • time.bora.net는 공용 NTP 서버로 많이 사용되는 타임서버입니다.

 

4. chronyd 서비스 stop 및 start 합니다.

[root@localhost ~]# systemctl stop chronyd.service
[root@localhost ~]# systemctl start chronyd.service

 

5. chronyc 서비스 상태 확인

  • chronyc sources 명령은 chronyd 가 액세스하는 현재 시간 sources에 대한 정보를 표시합니다.
[root@localhost ~]# chronyc sources

 

 

6. H/W 장비 시간 동기화 설정

  • hwclock 유틸리티를 이용
  • 'hwclock'은 하드웨어 시계에 액세스하기 위한 유틸리티이며, RTC(Real Time Clock)라고도 부릅니다.
[root@localhost ~]# hwclock -w
[root@localhost ~]# hwclock -v


# 아래는 hwclock의 function 설명
[root@localhost ~]# hwclock -h
Usage:
 hwclock [function] [option...]

Functions:
 -h, --help           show this help text and exit
 -r, --show           read hardware clock and print result
     --set            set the RTC to the time given with --date
 -s, --hctosys        set the system time from the hardware clock
 -w, --systohc        set the hardware clock from the current system time
     --systz          set the system time based on the current timezone
     --adjust         adjust the RTC to account for systematic drift since
                        the clock was last set or adjusted
 -c, --compare        periodically compare the system clock with the CMOS clock
     --getepoch       print out the kernel's hardware clock epoch value
     --setepoch       set the kernel's hardware clock epoch value to the
                        value given with --epoch
     --predict        predict RTC reading at time given with --date
 -V, --version        display version information and exit

 

7. 마지막으로 설정한 시간을 date로 현재 시간 확인

[root@localhost ~]# date

 

 

반응형