新聞中心
大家好,今天小編關注到一個比較有意思的話題,就是關于如何在CentOS中搭建NTP服務器,于是小編就整理了幾個相關介紹詳細的解答,讓我們一起看看吧。

- 本文目錄導讀:
- 1、前置知識
- 2、Step 1:安裝 NTP 軟件包
- 3、Step 2:配置防火墻規(guī)則
- 4、Step 3:配置 NTP
- 5、Step4:啟動和測試 NTP
作為網絡時間協(xié)議(NTP)的一種實現,NTP服務器可以提供高精度、可靠的時間同步服務。在企業(yè)級應用場景下,時鐘同步顯得尤為重要,因此搭建一個屬于自己的NTP服務器是非常有必要的。本文將介紹如何在CentOS系統(tǒng)上快速構建一個基礎版NTP服務器。
前置知識
- CentOS 7.x 系統(tǒng)安裝
- 基本 Linux 命令行操作
Step 1:安裝 NTP 軟件包
首先,在命令行界面下執(zhí)行以下命令:
```
sudo yum install ntp -y
該命令將會安裝 NTP 軟件包及其依賴項。
Step 2:配置防火墻規(guī)則
默認情況下,CentOS 防火墻可能會禁止外部主機訪問到您的 NTP 服務器。因此需要添加相應規(guī)則來允許其他主機通過 UDP 協(xié)議進行連接和數據傳輸。
運行以下兩個命令以開放相關端口:
sudo firewall-cmd --permanent --add-port=123/udp
sudo firewall-cmd --reload
這里我們打開了 UDP 協(xié)議中使用的標準 NTP 端口 123。
Step 3:配置 NTP
接下來,我們需要修改 /etc/ntp.conf 文件的一些默認設置。打開該文件并編輯以下內容:
# Use public servers from the pool.ntp.org project.
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
# Allow LAN clients to synchronize with this server.
restrict default nomodify notrap nopeer noquery
restrict -6 default nomodify notrap nopeer noquery
# Enable monitoring of NTP statistics and status information.
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
# Ignore stratum changes less than one step (default: off).
tinker panic 0
這里我們使用了 CentOS 公共服務器池中提供的四個時間服務器作為參考源(也可以自行指定其他可信任的公共服務器);同時我們允許局域網內主機同步此NTP服務器,并啟用監(jiān)控統(tǒng)計信息功能。
最后,保存更改并關閉文件。
Step4:啟動和測試 NTP
現在啟動 ntpd 守護進程:
sudo systemctl start ntpd.service
然后檢查它是否已成功運行:
sudo systemctl status ntpd.service
```
如果您看到 "active (running)" 的字樣,則表示 NTP 服務已經成功啟動。接著,我們可以通過以下命令測試 NTP 服務器的功能:
ntpq -p
該命令將會顯示您配置的參考源及其與本地時鐘之間的偏差。
到此,一個基礎版NTP服務器就搭建完成了。當然,在實際應用場景中,我們還需要進一步優(yōu)化和完善該服務器以保證時間同步效果更加穩(wěn)定、準確。希望這篇文章能夠為大家提供一些參考和指導。
網站題目:如何在CentOS中搭建NTP服務器——詳細教程
網站路徑:http://m.5511xx.com/article/djeicpi.html


咨詢
建站咨詢
