CentOS 8系統時間校准


本地搭建chrony服務器+所有客戶端同步服務器時間

# 安裝
yum install -y chrony
# 啟動
systemctl start chronyd
# 注冊成開機啟動
systemctl enable chronyd

如上配置好了以后,現行配置文件的修改

vim  /etc/chrony.conf

配置文件如下:

# 使用pool.ntp.org項目中的公共服務器。以server開,理論上你想添加多少時間服務器都可以。
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# 注釋掉 server 0.centos.pool.ntp.org iburst
# 新增
server cn.ntp.org.cn iburst
server time.windows.com iburst

# 根據實際時間計算出服務器增減時間的比率,然后記錄到一個文件中,在系統重啟后為系統做出最佳時間補償調整。
driftfile /var/lib/chrony/drift

# chronyd根據需求減慢或加速時間調整,
# 在某些情況下系統時鍾可能漂移過快,導致時間調整用時過長。
# 該指令強制chronyd調整時期,大於某個閥值時步進調整系統時鍾。
# 只有在因chronyd啟動時間超過指定的限制時(可使用負值來禁用限制)沒有更多時鍾更新時才生效。
makestep 1.0 3

# 將啟用一個內核模式,在該模式中,系統時間每11分鍾會拷貝到實時時鍾(RTC)。
rtcsync

# Enable hardware timestamping on all interfaces that support it.
# 通過使用hwtimestamp指令啟用硬件時間戳
#hwtimestamp eth0
#hwtimestamp eth1
#hwtimestamp *

# Increase the minimum number of selectable sources required to adjust
# the system clock.
#minsources 2

# 指定一台主機、子網,或者網絡以允許或拒絕NTP連接到扮演時鍾服務器的機器
#allow 192.168.0.0/16
#deny 192.168/16
allow 0.0.0./0 # 允許所有

# Serve time even if not synchronized to a time source.
local stratum 10

# 指定包含NTP驗證密鑰的文件。
#keyfile /etc/chrony.keys

#從system tz數據庫中獲取TAI-UTC偏移量和閏秒。
leapsectz right/UTC

# 指定日志文件的目錄。
logdir /var/log/chrony

# Select which information is logged.
#log measurements statistics tracking

或者添加如下兩行

server 210.72.145.44 iburst
server ntp.aliyun.com iburst

重新加載文件,同步時間,就能看到時間是正常的

systemctl restart chronyd.service    
chronyc sources -y

命令timedatectl

# 查看
timedatectl 
# 刪除 localtime
rm /etc/locatime
# 從/usr/share/zoneinfo/中創建軟連接以替換當前的時區信息
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 再次查看系統時間
timedatectl

 


免責聲明!

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



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