溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Centos7怎么部署NTP時間服務器

發布時間:2022-02-17 10:06:07 來源:億速云 閱讀:232 作者:iii 欄目:開發技術

本篇內容介紹了“Centos7怎么部署NTP時間服務器”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

NTP(Network Time Protocol)網絡時間協議基于UDP,用于網絡時間同步的協議,使網絡中的計算機時鐘同步到UTC,再配合各個時區的偏移調整就能實現精準同步對時功能。

Centos7怎么部署NTP時間服務器

實驗環境:

OS:Linux Centos 7.4 x86_64

1.查看當前服務器時區&列出時區并設置時區(如已是正確時區,請略過):

# timedatectl# timedatectl list-timezones# timedatectl set-timezone Asia/Shanghai
2.時間時區概念理解:

GMT、UTC、CST、DST

UTC:

整個地球分為二十四時區,每個時區都有自己的本地時間,在國際無線電通信場合,為了統一起見,使用一個統一的時間,稱為通用協調時(UTC:Universal Time Coordinated)。

GMT:

格林威治標準時間 (Greenwich Mean Time)指位于英國倫敦郊區的皇家格林尼治天文臺的標準時間,因為本初子午線被定義在通過那里的經線(UTC與GMT時間基本相同)。

CST:

中國標準時間 (China Standard Time)

GMT + 8 = UTC + 8 = CST

DST:

夏令時(Daylight Saving Time) 指在夏天太陽升起的比較早時,將時間撥快一小時,以提早日光的使用(中國不使用)。

2.使用 NTP 公共時間服務器池(NTP Public Pool Time Servers)http://www.pool.ntp.org 同步你的服務器時間。

查看是否安裝:

# rpm -q ntpntp-4.2.6p5-25.el7.centos.2.x86_64

如已安裝請略過此步,否則請執行以下命令安裝:

# yum install ntpdate ntp -y

修改NTP配置:

注:綠色為原有我注釋掉的內容,紅色為新增代替之前注釋內容,其他默認。

# vim /etc/ntp.conf# For more information about this file, see the man pages# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift#新增:日志目錄.logfile /var/log/ntpd.log# Permit time synchronization with our time source, but do not# permit the source to query or modify the service on this system.restrict default nomodify notrap nopeer noquery# Permit all access over the loopback interface. This could# be tightened as well, but to do so would effect some of# the administrative functions.restrict 127.0.0.1
restrict ::1#這一行的含義是授權172.16.128.0網段上的所有機器可以從這臺機器上查詢和同步時間.restrict 172.16.128.0 mask 255.255.255.0 nomodify notrap# Hosts on local network are less restricted.#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.# Please consider joining the pool (http://www.pool.ntp.org/join.html).#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#新增:時間服務器列表.server 0.cn.pool.ntp.org iburst
server 1.cn.pool.ntp.org iburst
server 2.cn.pool.ntp.org iburst
server 3.cn.pool.ntp.org iburst#新增:當外部時間不可用時,使用本地時間.server 172.16.128.171 iburst
fudge 127.0.0.1 stratum 10#broadcast 192.168.1.255 autokey # broadcast server#broadcastclient # broadcast client#broadcast 224.0.1.1 autokey # multicast server#multicastclient 224.0.1.1 # multicast client#manycastserver 239.255.254.254 # manycast server#manycastclient 239.255.254.254 autokey # manycast client#新增:允許上層時間服務器主動修改本機時間.restrict 0.cn.pool.ntp.org nomodify notrap noquery
restrict 1.cn.pool.ntp.org nomodify notrap noquery
restrict 2.cn.pool.ntp.org nomodify notrap noquery# Enable public key cryptography.#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating# with symmetric key cryptography.keys /etc/ntp/keys# Specify the key identifiers which are trusted.#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.#requestkey 8# Specify the key identifier to use with the ntpq utility.#controlkey 8# Enable writing of statistics records.#statistics clockstats cryptostats loopstats peerstats# Disable the monitoring facility to prevent amplification attacks using ntpdc# monlist command when default restrict does not include the noquery flag. See# CVE-2013-5211 for more details.# Note: Monitoring will not be disabled with the limited restriction flag.disable monitor
3.設置系統開機自啟動:
# systemctl enable ntpd# systemctl enable ntpdate# systemctl is-enabled ntpd

在ntpd服務啟動時,先使用ntpdate命令同步時間:

# ntpdate -u 1.cn.pool.ntp.org

原因之一:當服務端與客戶端之間的時間誤差過大時,此時修改時間可能對系統或應用帶來不可預知問題,NTP會停止時間同步。若檢查NTP啟動后時間未同步時,應考慮可能是時間誤差過大所致,此時需要先手動進行時間同步。

啟動NTP服務器:

# systemctl start ntpdate# systemctl start ntpd
4.加入防火墻:
# firewall-cmd --permanent --add-service=ntp# firewall-cmd --reload
5.查看ntp連接狀態如果沒有問題,將正確時間寫入硬件:
# ss -tlunp | grep ntp# ntpq -p# hwclock -w

5.1.系統時間與硬件時間

硬件時間:

RTC(Real-Time Clock)或CMOS時間,一般在主板上靠電池供電,服務器斷電后也會繼續運行。僅保存日期時間數值,無法保存時區和夏令時設置。

系統時間:

一般在服務器啟動時復制RTC時間,之后獨立運行,保存了時間、時區和夏令時設置。

6.客戶端:

以服務進程方式實時同步(需安裝NTP):

# vim /etc/ntp.confserver 172.16.128.171

重要:修改任意節點服務器的NTP配置文件都需要重起ntpd服務:

# systemctl restart ntpd

以crontab任務計劃同步時間(需安裝ntpdate,每天24點更新同步時間):

# crontab -e0 0 * * * /usr/sbin/sntp -P no -r 172.16.128.171;hwclock -w

已部署完畢。這樣集群會自動定期進行服務的同步,如此以來集群的時間就保持一致了。

“Centos7怎么部署NTP時間服務器”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女