CentOS8時間同步


CentOS8中默認已經不再支持ntpd軟件包,同時也無法通過官方軟件倉庫安裝, CentOS8上使用Chrony配置NTP服務器,用於同步時間。 它有兩個程序,chrony和chronyd, chronyd是守護進程 ,chrony是一個命令行界面程序,可以用來監控chronyd的性能,並修改各種操作參數。

安裝chrony
系統會默認安裝並啟動,如果系統不存在則需要安裝此工具庫。

倉庫中直接安裝

dnf -y install chrony

 啟動守護進程

systemctl enable –now chronyd

時間同步配置

設置時區
聯網的情況下一般設置時區后會通過網絡同步時間

timedatectl set-timezone "Asia/Shanghai"

配置chrony.conf

修改配置加入aliyun pool網絡時間,也可以加入多個pool服務器
vim /etc/chrony.conf

# 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

pool ntp.aliyun.com iburst

# 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 restart chronyd.service

時間同步

執行時間同步命令

chronyc sources -v

[root@k8smaster ~]# chronyc sources -v

210 Number of sources = 5

.-- Source mode ‘^’ = server, ‘=’ = peer, ‘#’ = local clock.
/ .- Source state ‘*’ = current synced, ‘+’ = combined , ‘-’ = not combined,
| / ‘?’ = unreachable, ‘x’ = time may be in error, ‘~’ = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | |
MS Name/IP address Stratum Poll Reach LastRx Last sample

^- ntp5.flashdance.cx 2 6 377 6 +8255us[+8255us] +/- 139ms
^- 185.216.231.25 2 7 13 6 +10ms[ +10ms] +/- 98ms
^- 119.28.206.193 2 6 377 9 +1016us[+1001us] +/- 62ms
^* dns1.synet.edu.cn 2 6 377 8 -1423us[-1438us] +/- 9294us
^+ 203.107.6.88 2 6 377 7 +2107us[+2107us] +/- 17ms

驗證查看時間
查看當前系統時間
date


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM