Try   HackMD

NTP Server and Client

tags: IBM Linux Tools

台灣時區
GMT+8=UTC+8=CST

CST可能代表4個不同的時區:

  • Central Standard Time (USA) UT-6:00
  • Central Standard Time (Australia) UT+9:30
  • China Standard Time UT+8:00
  • Cuba Standard Time UT-4:00

設定時區顯示格式

開機時,依據/etc/sysconfig/clock的ZONE,系統會將/usr/share/zoneinfo/Asia/Taipei複製為/etc/localtime

# vi /etc/sysconfig/clock
ZONE="Asia/Taipei"

手動校時

# 查看Unix Time
date

# 查看系統時間/硬體時間
hwclock -r

# 手動修改Unix Time
date MMDDhhmmYYYY

# 將Unix Time改到系統時間/硬體時間
hwclock -w

yum install ntp

網路校時

# 透過NTP Client,修改Unix Time
ntpdate <Time Server IP>

# 確認Unix Time
date

# 將Unix Time改到系統時間/硬體時間
hwclock -w

架設Time Server

> yum install ntp

> which ntpd

> vi /etc/ntp.conf
# difference of its hardware time and its time server
driftfile /var/lib/ntp/drift

# not allow all
restrict default nomodify notrap nopeer noquery

# allow its time server
restrict tock.stdtime.gov.tw
restrict tick.stdtime.gov.tw
restrict time.stdtime.gov.tw

# allow itself
restrict 127.0.0.1
restrict ::1

# allow client
restrict 192.168.56.0 mask 255.255.255.0 nomodify

# time server
server tock.stdtime.gov.tw prefer
server tick.stdtime.gov.tw
server time.stdtime.gov.tw

> systemctl stop chronyd; systemctl disable chronyd
> systemctl restart ntpd

# check if it has synchronized with its time server (more than 15 minutes after restarting)
> ntpstat

# check its time server status
> ntpq -p

yum install chrony