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

- 本文目錄導(dǎo)讀:
- 1、前置知識(shí)
- 2、Step 1:安裝 NTP 軟件包
- 3、Step 2:配置防火墻規(guī)則
- 4、Step 3:配置 NTP
- 5、Step4:?jiǎn)?dòng)和測(cè)試 NTP
作為網(wǎng)絡(luò)時(shí)間協(xié)議(NTP)的一種實(shí)現(xiàn),NTP服務(wù)器可以提供高精度、可靠的時(shí)間同步服務(wù)。在企業(yè)級(jí)應(yīng)用場(chǎng)景下,時(shí)鐘同步顯得尤為重要,因此搭建一個(gè)屬于自己的NTP服務(wù)器是非常有必要的。本文將介紹如何在CentOS系統(tǒng)上快速構(gòu)建一個(gè)基礎(chǔ)版NTP服務(wù)器。
前置知識(shí)
- CentOS 7.x 系統(tǒng)安裝
- 基本 Linux 命令行操作
Step 1:安裝 NTP 軟件包
首先,在命令行界面下執(zhí)行以下命令:
```
sudo yum install ntp -y
該命令將會(huì)安裝 NTP 軟件包及其依賴項(xiàng)。
Step 2:配置防火墻規(guī)則
默認(rèn)情況下,CentOS 防火墻可能會(huì)禁止外部主機(jī)訪問(wèn)到您的 NTP 服務(wù)器。因此需要添加相應(yīng)規(guī)則來(lái)允許其他主機(jī)通過(guò) UDP 協(xié)議進(jìn)行連接和數(shù)據(jù)傳輸。
運(yùn)行以下兩個(gè)命令以開(kāi)放相關(guān)端口:
sudo firewall-cmd --permanent --add-port=123/udp
sudo firewall-cmd --reload
這里我們打開(kāi)了 UDP 協(xié)議中使用的標(biāo)準(zhǔn) NTP 端口 123。
Step 3:配置 NTP
接下來(lái),我們需要修改 /etc/ntp.conf 文件的一些默認(rèn)設(shè)置。打開(kāi)該文件并編輯以下內(nèi)容:
# 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 公共服務(wù)器池中提供的四個(gè)時(shí)間服務(wù)器作為參考源(也可以自行指定其他可信任的公共服務(wù)器);同時(shí)我們?cè)试S局域網(wǎng)內(nèi)主機(jī)同步此NTP服務(wù)器,并啟用監(jiān)控統(tǒng)計(jì)信息功能。
最后,保存更改并關(guān)閉文件。
Step4:?jiǎn)?dòng)和測(cè)試 NTP
現(xiàn)在啟動(dòng) ntpd 守護(hù)進(jìn)程:
sudo systemctl start ntpd.service
然后檢查它是否已成功運(yùn)行:
sudo systemctl status ntpd.service
```
如果您看到 "active (running)" 的字樣,則表示 NTP 服務(wù)已經(jīng)成功啟動(dòng)。接著,我們可以通過(guò)以下命令測(cè)試 NTP 服務(wù)器的功能:
ntpq -p
該命令將會(huì)顯示您配置的參考源及其與本地時(shí)鐘之間的偏差。
到此,一個(gè)基礎(chǔ)版NTP服務(wù)器就搭建完成了。當(dāng)然,在實(shí)際應(yīng)用場(chǎng)景中,我們還需要進(jìn)一步優(yōu)化和完善該服務(wù)器以保證時(shí)間同步效果更加穩(wěn)定、準(zhǔn)確。希望這篇文章能夠?yàn)榇蠹姨峁┮恍﹨⒖己椭笇?dǎo)。
網(wǎng)頁(yè)標(biāo)題:如何在CentOS中搭建NTP服務(wù)器——詳細(xì)教程
分享網(wǎng)址:http://fisionsoft.com.cn/article/djeicpi.html


咨詢
建站咨詢
