準(zhǔn)備搭建環(huán)境
主機(jī) IP OS 備注 NTP Server 192.168.5.180 CentOS 6 NTP Client 192.168.5.181 CentOS 6
[root@node1~]# rpm-qa| grep ntp #查詢是否安裝ntp服務(wù)程序
[root@node1~]# yum install-y ntp #安裝ntp服務(wù)程序
紅色為添加的配置,其它都是默認(rèn)配置
[root@node1~]# cp/etc/ntp.conf{,.bak}#備份ntp配置文件
[root@node1~]# vim/etc/ntp.conf #編輯ntp配置文件
[root@node1~]# grep-Ev'^$|^#'/etc/ntp.conf
driftfile/var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict-6 default kod nomodify notrap nopeer noquery
restrict127.0.0.1
restrict-6::1
restrict192.168.5.0 mask255.255.255.0 nomodify notrap #允許該網(wǎng)段內(nèi)的主機(jī)可以進(jìn)行校時(shí)
restrict0.0.0.0 mask0.0.0.0 nomodify notrap
server time.nist.gov prefer #上層NTP服務(wù)器地址,prefer表示優(yōu)先
server0.centos.pool.ntp.org iburst
server1.centos.pool.ntp.org iburst
server2.centos.pool.ntp.org iburst
server3.centos.pool.ntp.org iburst
includefile/etc/ntp/crypto/pw
keys/etc/ntp/keys
# chkconfig ntpd on# /etc/init.d/ntpd start# /etc/init.d/ntpd stop# /etc/init.d/ntpd restart查看NTP啟動(dòng)的端口
[root@node1~]# netstat-tlunp| grep ntp
udp00192.168.5.180:123 0.0.0.0:* 28331/ntpd
udp00127.0.0.1:123 0.0.0.0:* 28331/ntpd
udp000.0.0.0:123 0.0.0.0:* 28331/ntpd
udp00 fe80::20c:29ff:fe2b:9990:123:::* 28331/ntpd
udp00::1:123 :::* 28331/ntpd
udp00:::123 :::* 28331/ntpd
現(xiàn)在ntp服務(wù)器已經(jīng)啟動(dòng)了,不過與上層服務(wù)器連接則還需要一些時(shí)間,通常啟動(dòng)NTP后在15分鐘內(nèi)才會(huì)和上層NTP服務(wù)器順利連接上。如何確定NTP服務(wù)器順利地更新了自己的時(shí)間呢?可以使用以下幾個(gè)命令查看
[root@node1~]# ntpstat
synchronised to NTP server(94.237.64.20) at stratum3
time correct to within362 ms
polling server every64 s
這個(gè)命令列出NTP服務(wù)器是否已經(jīng)與上層NTP服務(wù)器連接,由上述的輸出結(jié)果可以知道,時(shí)間已經(jīng)校正約362ms,且每隔64秒會(huì)主動(dòng)去更新
[root@node1~]# ntpq-p
remote refid st t when poll reach delay offset jitter
==============================================================================
time-a.nist.gov.INIT. 16 u-12800.0000.0000.000
*makaki.miuku.ne218.186.3.362 u1664377269.21544.74469.262
+ntp1.ams1.nl.le130.133.1.102 u2164377271.981-32.49066.809
+ntp.wdc1.us.lea130.133.1.102 u2264337308.368-6.92390.300
61-216--104.62.161.56.1583 u38642180.450-33.73323.397
注意:,
ntpq -p命令可以列出當(dāng)前我們的NTP服務(wù)器與上層NTP服務(wù)器的連接狀態(tài),以上幾個(gè)字段的意義如下:
remote: NTP主機(jī)的IP或主機(jī)名;注意左邊的符號(hào):*:表示正在使用的NTP服務(wù)器refid: 上層NTP服務(wù)器地址;+:表示已經(jīng)連接成功,但是作為備用提供時(shí)間更新的NTP服務(wù)器;st: 就是stratum階層
when:幾秒鐘前做過時(shí)間同步更新操作;pool:下次更新在幾秒鐘之后;reach:已經(jīng)向上層NTP服務(wù)器要求更新的次數(shù);delay: 網(wǎng)絡(luò)傳輸過程中延遲的時(shí)間,單位為10-6秒;offset:時(shí)間補(bǔ)償結(jié)果,單位為10-3秒;jitter:系統(tǒng)時(shí)間與BIOS硬件時(shí)間的差異時(shí)間,單位為10-6秒;
Client:192.168.5.181
[root@node2 tools]# ntpdate 192.168.5.18015 Jun 14:36:19 ntpdate[24881]: adjust time server 192.168.5.180 offset -0.002062 sec[root@node2 tools]# hwclock -w #將系統(tǒng)時(shí)間寫入BIOS硬件時(shí)間[root@node2 tools]# hwclockThu 15 Jun 2017 03:46:26 PM CST -0.860434 seconds[root@node2 tools]# dateThu Jun 15 15:46:38 CST 2017[root@node2 tools]# crontab -e #配置計(jì)劃任務(wù),系統(tǒng)第隔3分鐘自動(dòng)與NTP服務(wù)器192.168.5.180進(jìn)行校時(shí)*/3 * * * * (/usr/sbin/ntpdate 192.168.5.180 && /sbin/hwclock -w) &> /dev/null
新聞名稱:NTP服務(wù)器搭建和客戶端配置
文章源于:http://chinadenli.net/article48/giiehp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、網(wǎng)站維護(hù)、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、微信公眾號(hào)、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)