Centos8 -- 搭建本地 NTP 校時服務器搭建

步驟:

1. 放行防火牆、2.安裝chrony服務、3.配置chrony服務器端

1:放行防火牆

firewall-cmd --add-service=ntp --permanent && firewall-cmd --reload

也可以選擇關閉防火牆 or 永久關閉。

臨時關閉:systemctl stop firewalld.service
永久禁用:systemctl disable firewalld.service

2:安裝chrony服務

dnf install chrony -y

3:配置chrony服務器端

# vi /etc/chrony.conf

進入配置文件,刪除或註釋掉官方 NTP 上游服務器地址,手動配置爲 國內校時server 或 配置爲 自己本地server_ip地址,

配置國內server:校時上游ntp時間到本地,再作爲ntp_server發出去,確保了時間穩定性,前提!!!服務器能連接internet,

配置本地server:直接將本地server作爲上游,並作爲ntp_server發出去,時間自己可控,但不能100%保障時間正確性(此處對比北京時間).

綜上所述,也就是說,想要讓服務器client爲客戶端同步上游,只需將 ip 配置爲上游 ip 即可!

#上游NTP服務器,推薦阿里雲:
server time1.aliyun.com iburst     
server time2.aliyun.com iburst
server time3.aliyun.com iburst     

#上游服務器,本地:
server 本地server_ip iburst

配置完成後,重啓並設置開機啓動;

systemctl restart chronyd.service 
&& 
systemctl enable chronyd.service --now

查看同步狀態

# chronyc sources -v

210 Number of sources = 1

  .-- 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
===============================================================================
^* 192.168.1.66                3   6    17    16  +3424ns[ +110us] +/-   31ms

ip 爲 ntp_server 地址。

附錄:

  1. 查看日期時間、時區及NTP狀態:
# timedatectl

2. 修改時區爲上海

# timedatectl set-timezone Asia/Shanghai

3.修改本地日期時間

# timedatectl set-time "2021-03-14 23:00:00"(可以只修改其中一個)

4.開啓ntp

# timedatectl set-ntp true/flase

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章