linux配置ntp服務(wù)器的方法
一.安裝ntp軟件
1.檢查是否安裝了ntp相關(guān)包。
rpm -qa | grep ntp
2.安裝ntp軟件。
yum -y install ntp
二.參數(shù)講解
ignore :關(guān)閉所有的 NTP 聯(lián)機(jī)服務(wù)
nomodify:客戶端不能更改服務(wù)端的時(shí)間參數(shù),但是客戶端可以通過(guò)服務(wù)端進(jìn)行網(wǎng)絡(luò)校時(shí)。
notrust :客戶端除非通過(guò)認(rèn)證,否則該客戶端來(lái)源將被視為不信任子網(wǎng)
noquery :不提供客戶端的時(shí)間查詢:用戶端不能使用ntpq,ntpc等命令來(lái)查詢ntp服務(wù)器
notrap :不提供trap遠(yuǎn)端登陸:拒絕為匹配的主機(jī)提供模式 6 控制消息陷阱服務(wù)。陷阱服務(wù)是 ntpdq 控制消息協(xié)議的子系統(tǒng),用于遠(yuǎn)程事件日志記錄程序。
nopeer :用于阻止主機(jī)嘗試與服務(wù)器對(duì)等,并允許欺詐性服務(wù)器控制時(shí)鐘
kod : 訪問(wèn)違規(guī)時(shí)發(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的客戶機(jī)都可以進(jìn)行時(shí)間同步(修改后的配置文件)
# 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)段的客戶機(jī)進(jìn)行時(shí)間同步(修改后的配置文件)
# 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
四.啟動(dòng)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)時(shí)間同步,添加下面一行。
SYNC_HWCLOCK=yes
五.檢測(cè)NTP
1.檢測(cè)NTP服務(wù)是否運(yùn)行
# 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ù)器有無(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 - 本機(jī)和上層ntp的ip或主機(jī)名,“+”表示優(yōu)先,“*”表示次優(yōu)先 refid - 參考上一層ntp主機(jī)地址 st - stratum階層 when - 多少秒前曾經(jīng)同步過(guò)時(shí)間 poll - 下次更新在多少秒后 reach - 已經(jīng)向上層ntp服務(wù)器要求更新的次數(shù) delay - 網(wǎng)絡(luò)延遲 offset - 時(shí)間補(bǔ)償 jitter - 系統(tǒng)時(shí)間與bios時(shí)間差
六.配置時(shí)間同步客戶機(jī)
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
以上就是小編為大家?guī)?lái)的linux配置ntp服務(wù)器的方法全部?jī)?nèi)容了,希望大家多多支持腳本之家~
相關(guān)文章
詳解linux下的.net/mvc/cms程序結(jié)構(gòu)
本片文章給大家詳細(xì)分析了在linux下.net/mvc/cms程序詳細(xì)結(jié)構(gòu)說(shuō)明,了解這個(gè)對(duì)在linux下程序開發(fā)非常有用,有興趣的參考學(xué)習(xí)下吧。2017-12-12linux采用scp命令拷貝文件到本地,拷貝本地文件到遠(yuǎn)程服務(wù)器的方法
今天小編就為大家分享一篇linux采用scp命令拷貝文件到本地,拷貝本地文件到遠(yuǎn)程服務(wù)器的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-07-07在Linux分區(qū)或邏輯卷中創(chuàng)建文件系統(tǒng)的方法
這篇文章主要給大家介紹了關(guān)于如何在Linux分區(qū)或邏輯卷中創(chuàng)建文件系統(tǒng)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Linux具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04centeros7 安裝配置環(huán)境jdk1.8的教程
這篇文章主要介紹了centeros7 安裝配置環(huán)境jdk1.8的教程,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09Linux如何修改hosts文件并刷新DNS生效hosts文件
這篇文章主要介紹了Linux如何修改hosts文件并刷新DNS生效hosts文件問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07