您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“Centos7怎么部署NTP時(shí)間服務(wù)器”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
NTP(Network Time Protocol)網(wǎng)絡(luò)時(shí)間協(xié)議基于UDP,用于網(wǎng)絡(luò)時(shí)間同步的協(xié)議,使網(wǎng)絡(luò)中的計(jì)算機(jī)時(shí)鐘同步到UTC,再配合各個(gè)時(shí)區(qū)的偏移調(diào)整就能實(shí)現(xiàn)精準(zhǔn)同步對(duì)時(shí)功能。
OS:Linux Centos 7.4 x86_64
1.查看當(dāng)前服務(wù)器時(shí)區(qū)&列出時(shí)區(qū)并設(shè)置時(shí)區(qū)(如已是正確時(shí)區(qū),請(qǐng)略過):
# timedatectl# timedatectl list-timezones# timedatectl set-timezone Asia/Shanghai
GMT、UTC、CST、DST
UTC:
整個(gè)地球分為二十四時(shí)區(qū),每個(gè)時(shí)區(qū)都有自己的本地時(shí)間,在國(guó)際無線電通信場(chǎng)合,為了統(tǒng)一起見,使用一個(gè)統(tǒng)一的時(shí)間,稱為通用協(xié)調(diào)時(shí)(UTC:Universal Time Coordinated)。
GMT:
格林威治標(biāo)準(zhǔn)時(shí)間 (Greenwich Mean Time)指位于英國(guó)倫敦郊區(qū)的皇家格林尼治天文臺(tái)的標(biāo)準(zhǔn)時(shí)間,因?yàn)楸境踝游缇€被定義在通過那里的經(jīng)線(UTC與GMT時(shí)間基本相同)。
CST:
中國(guó)標(biāo)準(zhǔn)時(shí)間 (China Standard Time)
GMT + 8 = UTC + 8 = CST
DST:
夏令時(shí)(Daylight Saving Time) 指在夏天太陽升起的比較早時(shí),將時(shí)間撥快一小時(shí),以提早日光的使用(中國(guó)不使用)。
2.使用 NTP 公共時(shí)間服務(wù)器池(NTP Public Pool Time Servers)http://www.pool.ntp.org 同步你的服務(wù)器時(shí)間。
查看是否安裝:
# rpm -q ntpntp-4.2.6p5-25.el7.centos.2.x86_64
如已安裝請(qǐng)略過此步,否則請(qǐng)執(zhí)行以下命令安裝:
# yum install ntpdate ntp -y
修改NTP配置:
注:綠色為原有我注釋掉的內(nèi)容,紅色為新增代替之前注釋內(nèi)容,其他默認(rèn)。
# 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#這一行的含義是授權(quán)172.16.128.0網(wǎng)段上的所有機(jī)器可以從這臺(tái)機(jī)器上查詢和同步時(shí)間.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#新增:時(shí)間服務(wù)器列表.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#新增:當(dāng)外部時(shí)間不可用時(shí),使用本地時(shí)間.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#新增:允許上層時(shí)間服務(wù)器主動(dòng)修改本機(jī)時(shí)間.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
# systemctl enable ntpd# systemctl enable ntpdate# systemctl is-enabled ntpd
在ntpd服務(wù)啟動(dòng)時(shí),先使用ntpdate命令同步時(shí)間:
# ntpdate -u 1.cn.pool.ntp.org
原因之一:當(dāng)服務(wù)端與客戶端之間的時(shí)間誤差過大時(shí),此時(shí)修改時(shí)間可能對(duì)系統(tǒng)或應(yīng)用帶來不可預(yù)知問題,NTP會(huì)停止時(shí)間同步。若檢查NTP啟動(dòng)后時(shí)間未同步時(shí),應(yīng)考慮可能是時(shí)間誤差過大所致,此時(shí)需要先手動(dòng)進(jìn)行時(shí)間同步。
啟動(dòng)NTP服務(wù)器:
# systemctl start ntpdate# systemctl start ntpd
# firewall-cmd --permanent --add-service=ntp# firewall-cmd --reload
# ss -tlunp | grep ntp# ntpq -p# hwclock -w
5.1.系統(tǒng)時(shí)間與硬件時(shí)間
硬件時(shí)間:
RTC(Real-Time Clock)或CMOS時(shí)間,一般在主板上靠電池供電,服務(wù)器斷電后也會(huì)繼續(xù)運(yùn)行。僅保存日期時(shí)間數(shù)值,無法保存時(shí)區(qū)和夏令時(shí)設(shè)置。
系統(tǒng)時(shí)間:
一般在服務(wù)器啟動(dòng)時(shí)復(fù)制RTC時(shí)間,之后獨(dú)立運(yùn)行,保存了時(shí)間、時(shí)區(qū)和夏令時(shí)設(shè)置。
以服務(wù)進(jìn)程方式實(shí)時(shí)同步(需安裝NTP):
# vim /etc/ntp.confserver 172.16.128.171
重要:修改任意節(jié)點(diǎn)服務(wù)器的NTP配置文件都需要重起ntpd服務(wù):
# systemctl restart ntpd
以crontab任務(wù)計(jì)劃同步時(shí)間(需安裝ntpdate,每天24點(diǎn)更新同步時(shí)間):
# crontab -e0 0 * * * /usr/sbin/sntp -P no -r 172.16.128.171;hwclock -w
已部署完畢。這樣集群會(huì)自動(dòng)定期進(jìn)行服務(wù)的同步,如此以來集群的時(shí)間就保持一致了。
“Centos7怎么部署NTP時(shí)間服務(wù)器”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。