系統環境:CentOS Linux release 7.4.1708 (Core) 3.10.0-693.el7.x86_64html
軟件版本:chrony-3.1-2.el7.centos.x86_64linux
ntp-4.2.6p5-25.el7.centos.2.x86_64web
ntpdate-4.2.6p5-25.el7.centos.2.x86_64centos
一、安裝安全
# yum install ntp
二、修改配置文件服務器
restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict ::1 #系統若啓用了ipv6,該項必須保留,不然會報錯 #增長容許查詢的網絡範圍 restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap restrict 10.20.20.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.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst
restrict的參數說明:網絡
ignore:拒絕鏈接到NTP服務器
nomodiy: 忽略全部改變NTP服務器配置的報文,但能夠查詢配置信息
noquery: 忽略全部mode字段爲6或7的報文,客戶端不能改變NTP服務器配置,也不能查詢配置信息
notrap: 不提供trap遠程登陸功能,trap服務是一種遠程時間日誌服務。
notrust: 不做爲同步的時鐘源。
nopeer: 提供時間服務,但不做爲對等體。
kod: 向不安全的訪問者發送Kiss-Of-Death報文ide
三、配置防火牆並啓動服務ui
# iptables -I INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT # iptables-save >/etc/sysconfig/iptables # systemctl start ntpd.service # systemctl enable ntpd.service
四、確認服務運行正常spa
# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== +biisoni.miuku.n 207.224.49.219 2 u 125 64 272 188.586 -5.387 19.552 61-216-153-105. 211.22.103.157 3 u 83 64 102 44.326 -6.224 13.534 *85.199.214.100 .GPS. 1 u 41 64 377 224.549 4.580 2.672 +ntp8.flashdance 194.58.202.148 2 u 56 64 377 241.409 -18.026 30.000
一、安裝
# yum install chrony
二、修改配置文件
#使用默認的時間服務器或指定其餘服務器 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 #容許查詢的客戶端範圍 allow 192.168.10.0/24 allow 10.20.20.0/24
iburst參數:在一個標準的輪詢間隔內沒有應答,客戶端會發送4個包給 NTP 服務器,以便在客戶端首次快速同步時間
三、配置防火牆並啓動服務
# iptables -I INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT # iptables-save >/etc/sysconfig/iptables # systemctl start chrony.service # systemctl enable chrony.service
四、確認服務運行正常
# chronyc sources 210 Number of sources = 4 MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^+ ntp1.ams1.nl.leaseweb.net 2 9 377 43 +17ms[ +17ms] +/- 241ms ^+ 61-216-153-105.HINET-IP.> 3 9 200 38m +8127us[ +14ms] +/- 93ms ^? 61-216-153-107.HINET-IP.> 3 9 10 36m +12ms[ +20ms] +/- 84ms ^* makaki.miuku.net 2 9 377 236 +7939us[ +11ms] +/- 242ms
一、使用NTP服務器軟件
把上面配置中的server替換成內部NTP服務器便可 server 10.20.20.2 prefer server 10.20.20.3 iburst
使用prefer參數將優先使用該服務器
二、使用ntpdate
安裝ntpdate,並修改/etc/ntp/step-tickers。固然也可使用默認的公共時間服務器
# vi /etc/ntp/step-tickers #0.centos.pool.ntp.org 10.20.20.2 iburst
# systemctl start ntpdate.service
# systemctl enable ntpdate.service
這裏一樣支持iburst或prefer等參數