[Linux] 서버 시간 동기화

2024. 7. 1. 11:50·🚀 from error to study/Server

 

 

 

🔥 포스팅 계기

 

서버 시간이 이상하게 나온다는 말에 서버 시간 동기화하는 법을 구글링했다 생각보다 쉬워서 일단 정리해 놓음

 

 

 

 

📍 서버 시간 확인 (로그 확인이라 쓰고 오류 확인이라 읽음)

👉🏻 정상 서버의 로그

👉🏻 비정상 서버의 로그

👉🏻 (참고) 한국 표준시간보다 9시간 느린 상태라면 그건 동기화가 됐음에도 UTC로 설정된 경우일 수 있음

👉🏻 나는 그 경우는 아니었기 때문에 동기화까지 진행

 

 

📍 동기화 상태 확인

👉🏻 우선 NTP(Network Time Protocol)가 설치되어 있는지 확인하는 게 우선임

👉🏻  리눅스 배포판에는 systemd-timesyncd 기본 제공된다고 함

$ timedatectl status

👉🏻  비정상 서버는 동기화가 이루어지지 않고 있었음

 

 

 

📍 설치된 NTP(Network Time Protocol) 종류 확인

👉🏻 기본 설치판 'systemd-timesyncd' 확인

$ systemctl status systemd-timesyncd

❌ Unit systemd-timesyncd.service could not be found.

❌ 뭐 모르는 사람이 봐도 선명한 찾을 수 없다는 문구 ;; 확인해 보니 기본 설치판으로 설정되어 있지 않았음

 

👉🏻 'chrony' 확인

$ systemctl status chronyd

혹은

-- Debian/Ubuntu의 경우
$ dpkg -l | grep chronyd

-- RHEL/CentOS의 경우
$ rpm -qa | grep chronyd

 

⭕️  chrony로 사용하는 것 확인

chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2024-05-25 16:10:15 KST; 3 months 1 days ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
  Process: 1119 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)
  Process: 1105 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 1114 (chronyd)
    Tasks: 1 (limit: 202064)
   Memory: 1.8M
   CGroup: /system.slice/chronyd.service
           └─1114 /usr/sbin/chronyd

 

👉🏻 'ntpd' 확인

$ systemctl status ntpd

혹은
-- Debian/Ubuntu의 경우
$ dpkg -l | grep ntp

-- RHEL/CentOS의 경우
$ rpm -qa | grep ntp

 

 

 

📍 chrony 동기화 상태 확인

👉🏻 현재 시간 소스를 어떻게 추적하고 있는지 확인하는 거라고 하는데... 사실 잘 모르겠음

$ chronyc tracking

 

Reference ID    : 27766CEA (39.118.108.234)
Stratum         : 4
Ref time (UTC)  : Mon Jul 01 02:03:22 2024
System time     : 4859916.500000000 seconds fast of NTP time
Last offset     : -0.000495664 seconds
RMS offset      : 0.000339157 seconds
Frequency       : 17.646 ppm slow
Residual freq   : -0.226 ppm
Skew            : 0.254 ppm
Root delay      : 0.007059325 seconds
Root dispersion : 0.004379482 seconds
Update interval : 1036.0 seconds
Leap status     : Normal

 

 

 


📍 동기화된 소스 시간 확인

👉🏻 현재 사용 중인 소스를 확인하고, chrony가 동기화에 사용하는 NTP 목록을 보여 줌

$ chronyc sources

 

👉🏻 chrony가 여러 NTP 서버와 통신하고 있으며 그 중 하나(39.118.108.234)와 성공적으로 동기화되고 있는 것을 확인

✔️  ^* 기호는 해당 서버가 현재 동기화에 사용되고 있는 주요 서버임을 나타냄

 

 

 

📍 시간 강제 동기화

$ sudo chronyc makestep

👉🏻 만약 timedatectl status 명령에서 여전히 System clock synchronized: no로 표시된다면, 강제로 시간을 동기화

 

 

 

 

👉🏻 동기화 이후 timedatectl status로 다시 확인해 보면 동기화 진행 중임을 확인 가능!

 

 

 

 

📍 전체 명령어 순차 정리

[@dev ~]$ timedatectl status
               Local time: Mon 2024-08-26 17:15:00 KST
           Universal time: Mon 2024-08-26 08:15:00 UTC
                 RTC time: Mon 2024-07-01 02:16:23
                Time zone: Asia/Seoul (KST, +0900)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no
[@dev ~]$ chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^- 121.174.142.81                3  10   377  1080   +479us[  -12us] +/-   54ms
^- 106.247.248.106               2  10   377   668   +755us[ +755us] +/-   27ms
^* 39.118.108.234                3  10   377   794  +1624ns[ -494us] +/- 6475us
^- 175.193.3.234                 3   8   377   195    -19ms[  -19ms] +/-   67ms
[@dev ~]$ timedatectl status
               Local time: Mon 2024-08-26 17:15:33 KST
           Universal time: Mon 2024-08-26 08:15:33 UTC
                 RTC time: Mon 2024-07-01 02:16:58
                Time zone: Asia/Seoul (KST, +0900)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no
[@dev ~]$ chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^- 121.174.142.81                3  10   377  1113   +479us[  -12us] +/-   54ms
^- 106.247.248.106               2  10   377   701   +755us[ +755us] +/-   27ms
^* 39.118.108.234                3  10   377   827  +1624ns[ -494us] +/- 6475us
^- 175.193.3.234                 3   8   377   228    -19ms[  -19ms] +/-   67ms
[@dev ~]$
[@dev ~]$
[@dev ~]$
[@dev ~]$
[@dev ~]$
[@dev ~]$ sudo chronyc makestep
[sudo] password for :
200 OK
[@dev ~]$ timedatectl status
               Local time: Mon 2024-07-01 11:18:05 KST
           Universal time: Mon 2024-07-01 02:18:05 UTC
                 RTC time: Mon 2024-07-01 02:18:05
                Time zone: Asia/Seoul (KST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

 

 

 

저작자표시 비영리 변경금지 (새창열림)
'🚀 from error to study/Server' 카테고리의 다른 글
  • [Windows] windows에서 로그 파일 실시간 확인하는 법
  • [Linux] 방화벽(firewall) 확인 및 실행/종료(firewalld)
  • [Linux] grep 시 윗줄, 아래줄 내용 같이 출력하기
  • 리눅스 별칭(alias) 등록/삭제
천재강쥐
천재강쥐
  • 천재강쥐
    디버거도 버거다
    천재강쥐
  • 전체
    오늘
    어제
    • Category (467)
      • 진짜 너무 궁금한데 이걸 나만 몰라...? (0)
      • 💾 Portfolio (2)
      • 🐤 CodingTest (28)
        • Java (20)
        • ᕕ(ꐦ°᷄д°᷅)ᕗ❌ (5)
      • 🚀 from error to study (142)
        • AI (1)
        • Cloud (2)
        • DB (12)
        • Front-End (16)
        • Github (14)
        • Java (39)
        • Mac (7)
        • Normal (29)
        • Server (22)
      • 📘 certificate (44)
        • 📘 리눅스마스터1급 (1)
        • 📘⭕️ 정보처리기사 (40)
        • 📘⭕️ SQLD (3)
      • 📗 self-study (234)
        • 📗 inflearn (35)
        • 📗 생활코딩 (8)
        • 📗 KH정보교육원 당산지원 (190)
      • 🎨 Scoop the others (0)
        • 📖 Peeking into other people.. (0)
        • 🇫🇷 (0)
        • 📘⭕️ 한국사능력검정시험 심화 (11)
        • 오블완 (4)
  • 인기 글

  • hELLO· Designed By정상우.v4.10.1
천재강쥐
[Linux] 서버 시간 동기화
상단으로

티스토리툴바