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)機服務(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
以上就是小編為大家?guī)淼膌inux配置ntp服務(wù)器的方法全部內(nèi)容了,希望大家多多支持腳本之家~
相關(guān)文章
詳解linux下的.net/mvc/cms程序結(jié)構(gòu)
本片文章給大家詳細分析了在linux下.net/mvc/cms程序詳細結(jié)構(gòu)說明,了解這個對在linux下程序開發(fā)非常有用,有興趣的參考學(xué)習下吧。2017-12-12linux采用scp命令拷貝文件到本地,拷貝本地文件到遠程服務(wù)器的方法
今天小編就為大家分享一篇linux采用scp命令拷貝文件到本地,拷貝本地文件到遠程服務(wù)器的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-07-07在Linux分區(qū)或邏輯卷中創(chuàng)建文件系統(tǒng)的方法
這篇文章主要給大家介紹了關(guān)于如何在Linux分區(qū)或邏輯卷中創(chuàng)建文件系統(tǒng)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學(xué)習或者使用Linux具有一定的參考學(xué)習價值,需要的朋友們下面來一起學(xué)習學(xué)習吧2019-04-04centeros7 安裝配置環(huán)境jdk1.8的教程
這篇文章主要介紹了centeros7 安裝配置環(huán)境jdk1.8的教程,本文圖文并茂給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-09-09Linux如何修改hosts文件并刷新DNS生效hosts文件
這篇文章主要介紹了Linux如何修改hosts文件并刷新DNS生效hosts文件問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07