# (六)NTP Server ## Server部分 ``` $ yum install chrony (先安裝chrony) ``` ``` $ vim /etc/chrony.conf ``` 進去編輯, 加入以下5-10行內容 ```dockerfile= #執行結果 # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). pool 2.centos.pool.ntp.org iburst allow 192.168.1.0/24 allow 172.24.10.0/24 server time.stdtime.gov.tw server tock.stdtime.gov.tw server watch.stdtime.gov.tw # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. #allow 192.168.0.0/16 # Serve time even if not synchronized to a time source. #local stratum 10 # Specify file containing keys for NTP authentication. keyfile /etc/chrony.keys # Get TAI-UTC offset and leap seconds from the system tz database. leapsectz right/UTC # Specify directory for log files. logdir /var/log/chrony # Select which information is logged. #log measurements statistics tracking ``` ``` $ systemctl enable chronyd.service ``` ``` $ systemctl start chronyd.service ``` (防火牆設定) ``` $ firewall-cmd --permanent --add-service=ntp ``` ``` $ firewall-cmd –reload ``` ``` $ chronyc -a makestep ``` ```dockerfile= #執行結果 200 OK ``` ``` $ chronyc tracking ``` ```dockerfile= #執行結果 Reference ID : 76A3513F (118.163.81.63) Stratum : 2 Ref time (UTC) : Tue Aug 10 11:53:23 2021 System time : 0.000000000 seconds slow of NTP time Last offset : -0.000961502 seconds RMS offset : 0.029450445 seconds Frequency : 6.557 ppm slow Residual freq : -0.139 ppm Skew : 11.140 ppm Root delay : 0.039108839 seconds Root dispersion : 0.011422600 seconds Update interval : 260.1 seconds Leap status : Normal ``` ``` $ chronyc sources ``` ```dockerfile= #執行結果 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^- 114.35.131.27 2 8 377 81 -12ms[ -12ms] +/- 67ms ^- 59-125-122-217.HINET-IP.> 2 8 373 209 +6882us[+6882us] +/- 33ms ^- mail.iongchun.tw 2 8 357 215 +1512us[+1512us] +/- 64ms ^- time.cloudflare.com 3 8 337 94 +2936us[+2936us] +/- 103ms ^- 118-163-81-61.HINET-IP.h> 2 8 357 32 -1251us[-1251us] +/- 48ms ^- 211-22-103-157.HINET-IP.> 2 8 375 484 +1036us[-1396us] +/- 76ms ^* 118-163-81-63.HINET-IP.h> 1 8 325 224 +7331us[+6370us] +/- 33ms ``` ``` $ systemctl status chronyd.service ``` (查看 chronyd運行狀態) ```dockerfile= #執行結果 ● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor pre> Active: active (running) since Tue 2021-08-10 19:14:14 CST; 44min ago Docs: man:chronyd(8) man:chrony.conf(5) Process: 897 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exi> Process: 878 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCC> Main PID: 892 (chronyd) Tasks: 1 (limit: 23548) Memory: 1.8M CGroup: /system.slice/chronyd.service └─892 /usr/sbin/chronyd ``` :::success 顯示active即開啟成功 ::: ## Client部分 ``` $ yum install chrony ``` ``` $ vim /etc/chrony.conf ``` 輸入自己server的hostname(第4行) ```dockerfile= #執行結果 # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). server chuck.im.shu iburst pool chuck.im.shu iburst #pool server.deyu.wang iburst #pool 2.centos.pool.ntp.org iburst #server tock.stdtime.gov.tw #server watch.stdtime.gov.tw #server time.stdtime.gov.tw #server clock.stdtime.gov.tw #server tick.stdtime.gov.tw # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. #allow 192.168.1.0/24 # Serve time even if not synchronized to a time source. #local stratum 10 # Specify file containing keys for NTP authentication. keyfile /etc/chrony.keys # Get TAI-UTC offset and leap seconds from the system tz database. leapsectz right/UTC # Specify directory for log files. logdir /var/log/chrony # Select which information is logged. #log measurements statistics tracking ``` ``` $ systemctl enable chronyd.service ``` ``` $ systemctl start chronyd.service ``` ``` $ chronyc -a makestep ``` ``` $ chronyc tracking ``` ```dockerfile= #執行結果 Reference ID : AC180A08 (chuck.im.shu) Stratum : 3 Ref time (UTC) : Tue Aug 10 12:01:47 2021 System time : 0.000127929 seconds slow of NTP time Last offset : -0.000024072 seconds RMS offset : 0.000654462 seconds Frequency : 12.988 ppm slow Residual freq : -0.014 ppm Skew : 4.335 ppm Root delay : 0.050861713 seconds Root dispersion : 0.005647538 seconds Update interval : 64.3 seconds Leap status : Normal ``` ``` $ chronyc sources ``` ```dockerfile= #執行結果 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* chuck.im.shu 2 6 377 54 +128us[ +191us] +/- 29ms ``` ``` $ systemctl status chronyd.service ``` ```dockerfile= #執行結果 ● chronyd.service - NTP client/server Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor pre> Active: active (running) since Tue 2021-08-10 19:49:39 CST; 16min ago Docs: man:chronyd(8) man:chrony.conf(5) Process: 838 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exi> Process: 829 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCC> Main PID: 835 (chronyd) Tasks: 1 (limit: 23663) Memory: 1.5M CGroup: /system.slice/chronyd.service └─835 /usr/sbin/chronyd Aug 10 19:49:39 kvm8.chuck.im.shu systemd[1]: Starting NTP client/server... Aug 10 19:49:39 kvm8.chuck.im.shu chronyd[835]: chronyd version 4.1 starting (+> Aug 10 19:49:39 kvm8.chuck.im.shu chronyd[835]: Frequency -20.870 +/- 14.741 pp> Aug 10 19:49:39 kvm8.chuck.im.shu chronyd[835]: Using right/UTC timezone to obt> Aug 10 19:49:39 kvm8.chuck.im.shu systemd[1]: Started NTP client/server. Aug 10 19:54:15 kvm8.chuck.im.shu chronyd[835]: Selected source 172.24.10.8 (ch> Aug 10 19:54:15 kvm8.chuck.im.shu chronyd[835]: System clock wrong by 1.371979 > ``` :::success 顯示active即開啟成功 :::
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up