linux配置ntp伺服器的方法_Linux

來源:互聯網
上載者:User

一.安裝ntp軟體

1.檢查是否安裝了ntp相關包。
rpm -qa | grep ntp

2.安裝ntp軟體。
yum -y install ntp

二.參數講解

ignore  :關閉所有的 NTP 線上服務

nomodify:用戶端不能更改服務端的時間參數,但是用戶端可以通過服務端進行網路校時。

notrust :用戶端除非通過認證,否則該用戶端來源將被視為不信任子網

noquery :不提供用戶端的時間查詢:使用者端不能使用ntpq,ntpc等命令來查詢ntp伺服器

notrap :不提供trap遠端登陸:拒絕為匹配的主機提供模式 6 控制訊息陷阱服務。陷阱服務是 ntpdq 控制訊息協議的子系統,用於遠程事件記錄記錄程式。

nopeer :用於阻止主機嘗試與伺服器對等,並允許欺詐性伺服器控制時鐘

kod : 訪問違規時發送 KoD 包。

三.修改設定檔

1.查看未修改的設定檔

# grep ^[^#] /etc/ntp.conf  driftfile /var/lib/ntp/driftrestrict default nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict ::1server 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.pool.ntp.org iburstserver 3.centos.pool.ntp.org iburstincludefile /etc/ntp/crypto/pwkeys /etc/ntp/keysdisable monitor

1.設定允許任何IP的客戶機都可以進行時間同步(修改後的設定檔)

# grep ^[^#] /etc/ntp.conf  driftfile /var/lib/ntp/driftrestrict default nomodify notraprestrict 127.0.0.1restrict ::1server 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.pool.ntp.org iburstserver 3.centos.pool.ntp.org iburstincludefile /etc/ntp/crypto/pwkeys /etc/ntp/keysdisable monitor

2.只允許192.168.1.0網段的客戶機進行時間同步(修改後的設定檔)

# grep ^[^#] /etc/ntp.conf driftfile /var/lib/ntp/driftrestrict default nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict ::1restrict 192.168.1.0 mask 255.255.255.0 nomodify notrapserver 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.ntp.org iburstserver 3.centos.pool.ntp.org iburstincludefile /etc/ntp/crypto/pwkeys /etc/ntp/keysdisable monitor

四.啟動NTP服務和防火牆

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設定
vi /etc/sysconfig/ntpd#允許BIOS與系統時間同步,添加下面一行。
SYNC_HWCLOCK=yes

五.檢測NTP

1.檢測NTP服務是否運行

# netstat -tlunp | grep ntpudp    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伺服器有無和上層ntp連通

# ntpstatsynchronised to NTP server (120.25.108.11) at stratum 3  time correct to within 99 ms  polling server every 64 s

3.查看ntp伺服器與上層ntp的狀態

# 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.000x202.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.944remote  - 本機和上層ntp的ip或主機名稱,“+”表示優先,“*”表示次優先refid  - 參考上一層ntp主機地址st    - stratum階層when   - 多少秒前曾經同步過時間poll   - 下次更新在多少秒後reach  - 已經向上層ntp伺服器要求更新的次數delay  - 網路延遲offset  - 時間補償jitter  - 系統時間與bios時間差

六.配置時間同步客戶機

1.執行ntpdate命令:

ntpdate 192.168.1.101 #192.168.1.101為ntp伺服器IP地址

2.寫入BIOS

hclock -w

3.crond服務

vi /etc/crontab
30 8 * * * root /usr/sbin/ntpdate 192.168.1.101; /sbin/hwclock -w

4.重啟crond服務

service crond restart

以上就是小編為大家帶來的linux配置ntp伺服器的方法全部內容了,希望大家多多支援雲棲社區~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.