您好,登錄后才能下訂單哦!
本文小編為大家詳細介紹“l(fā)inux中怎么配置ntp服務(wù)器”,內(nèi)容詳細,步驟清晰,細節(jié)處理妥當,希望這篇“l(fā)inux中怎么配置ntp服務(wù)器”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。
一.安裝ntp軟件
1.檢查是否安裝了ntp相關(guān)包。
rpm -qa | grep ntp
2.安裝ntp軟件。
yum -y install ntp
二.參數(shù)講解
ignore :關(guān)閉所有的 ntp 聯(lián)機服務(wù)
nomodify:客戶端不能更改服務(wù)端的時間參數(shù),但是客戶端可以通過服務(wù)端進行網(wǎng)絡(luò)校時。
notrust :客戶端除非通過認證,否則該客戶端來源將被視為不信任子網(wǎng)
noquery :不提供客戶端的時間查詢:用戶端不能使用ntpq,ntpc等命令來查詢ntp服務(wù)器
notrap :不提供trap遠端登陸:拒絕為匹配的主機提供模式 6 控制消息陷阱服務(wù)。陷阱服務(wù)是 ntpdq 控制消息協(xié)議的子系統(tǒng),用于遠程事件日志記錄程序。
nopeer :用于阻止主機嘗試與服務(wù)器對等,并允許欺詐性服務(wù)器控制時鐘
kod : 訪問違規(guī)時發(fā)送 kod 包。
三.修改配置文件
1.查看未修改的配置文件
# grep ^[^#] /etc/ntp.conf driftfile /var/lib/ntp/drift restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict ::1 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 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor
1.設(shè)置允許任何ip的客戶機都可以進行時間同步(修改后的配置文件)
# grep ^[^#] /etc/ntp.conf driftfile /var/lib/ntp/drift restrict default nomodify notrap restrict 127.0.0.1 restrict ::1 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 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor
2.只允許192.168.1.0網(wǎng)段的客戶機進行時間同步(修改后的配置文件)
# grep ^[^#] /etc/ntp.conf driftfile /var/lib/ntp/drift restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict ::1 restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.ntp.org iburst server 3.centos.pool.ntp.org iburst includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor
四.啟動ntp服務(wù)和防火墻
systemctl start ntpd
systemctl enable ntpd
iptables -a input -p udp -i eno16777736 -s 192.168.1.0/24 --dport 123 -j accept
setsebool -p ntp_disable_trans 1#selinux設(shè)置
vi /etc/sysconfig/ntpd#允許bios與系統(tǒng)時間同步,添加下面一行。
sync_hwclock=yes
五.檢測ntp
1.檢測ntp服務(wù)是否運行
# netstat -tlunp | grep ntp udp 0 0 192.168.1.101:123 0.0.0.0:* 2563/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 2563/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 2563/ntpd udp6 0 0 fe80::20c:29ff:fe7b:123 :::* 2563/ntpd udp6 0 0 ::1:123 :::* 2563/ntpd udp6 0 0 :::123 :::* 2563/ntpd
2.查看ntp服務(wù)器有無和上層ntp連通
# ntpstat synchronised to ntp server (120.25.108.11) at stratum 3 time correct to within 99 ms polling server every 64 s
3.查看ntp服務(wù)器與上層ntp的狀態(tài)
# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== news.neu.edu.cn .init. 16 u - 64 0 0.000 0.000 0.000 x202.118.1.130 202.118.1.47 2 u 7 64 377 153.659 9.605 19.941 *time4.aliyun.co 10.137.38.86 2 u 10 64 377 39.666 -47.661 15.944 remote - 本機和上層ntp的ip或主機名,“+”表示優(yōu)先,“*”表示次優(yōu)先 refid - 參考上一層ntp主機地址 st - stratum階層 when - 多少秒前曾經(jīng)同步過時間 poll - 下次更新在多少秒后 reach - 已經(jīng)向上層ntp服務(wù)器要求更新的次數(shù) delay - 網(wǎng)絡(luò)延遲 offset - 時間補償 jitter - 系統(tǒng)時間與bios時間差
六.配置時間同步客戶機
1.執(zhí)行ntpdate命令:
ntpdate 192.168.1.101 #192.168.1.101為ntp服務(wù)器ip地址
2.寫入bios
hclock -w
3.crond服務(wù)
vi /etc/crontab
30 8 * * * root /usr/sbin/ntpdate 192.168.1.101; /sbin/hwclock -w
4.重啟crond服務(wù)
service crond restart
讀到這里,這篇“l(fā)inux中怎么配置ntp服務(wù)器”文章已經(jīng)介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領(lǐng)會,如果想了解更多相關(guān)內(nèi)容的文章,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。