ntp也是一種協議vim
ntp軟件(支持ntp協議) CentOS6自帶 CentOS7須要安裝centos
chrony軟件(支持ntp協議) CentOS7自帶服務器
CentOS6系統自帶ntp,CentOS7須要本身安裝測試
[root@m02 ~]# yum -y install ntp [root@m02 ~]# rpm -qa ntp ntp-4.2.6p5-25.el7.centos.2.x86_64
noquery:不提供ntp服務
notrap:不提供trap遠程事件登陸的功能
nomodiy:表示客戶端不能更改ntp服務器的時間參數,但能夠經過ntp服務器進行時間矯正
notrust:拒絕沒有經過認證的客戶端
nokod:kod技術能夠組織一種dos攻擊
ignore :關閉全部ntp服務
更改以前能夠備份一下,以防改錯ui
[root@m02 ~]# vim /etc/ntp.conf
server ntp1.aliyun.com 加上這個,由於默認是國外的時間同步服務器,使用國外的相對於使用阿里的,速度對比可想而知。
格式:restrict IP 權限參數 IP能夠爲ip地址或者default 權限參數:nomodify notrap nopeer noquery 例如:restrict 172.16.1.0 mask 255.255.255.0 nomodify notrap
[root@m02 ~]# diff /etc/ntp.conf{,.ori} 18c18 < restrict 172.16.1.0 mask 255.255.255.0 nomodify notrap --- > 21d20 < server ntp1.aliyun.com
[root@m02 ~]# systemctl start ntpd
服務端能夠先查看一下centos7
利用ntpq -p命令和ntpstat命令spa
[root@m02 ~]# ntpq -p #顯示上一級鏈接的服務器 remote refid st t when poll reach delay offset jitter ============================================================================== *time5.aliyun.co 10.137.38.86 2 u 57 64 377 4.209 3.841 2.685 time-d-b.nist.g .STEP. 16 u - 512 0 0.000 0.000 0.000 [root@m02 ~]# ntpstat #顯示同步結果 如今的狀態信息 synchronised to NTP server (182.92.12.11) at stratum 3 time correct to within 11 ms polling server every 64 s
客戶機要等幾分鐘再與新啓動的ntp服務器進行時間同步,不然會提示no server suitable for synchronization found
錯誤。rest
並且同步有時會很慢code
ntpdate -d 顯示同步過程server
[root@Cobbler ~]# ntpdate 172.16.1.62 16 Nov 11:42:34 ntpdate[1538]: adjust time server 172.16.1.62 offset -0.002221 sec [root@Cobbler ~]# ntpdate -d 172.16.1.62 16 Nov 16:10:07 ntpdate[2058]: ntpdate 4.2.6p5@1.2349-o Wed Apr 12 21:24:06 UTC 2017 (1) Looking for host 172.16.1.62 and service ntp host found : 172.16.1.62 transmit(172.16.1.62) receive(172.16.1.62) transmit(172.16.1.62) receive(172.16.1.62) transmit(172.16.1.62) receive(172.16.1.62) transmit(172.16.1.62) receive(172.16.1.62) server 172.16.1.62, port 123 stratum 3, precision -24, leap 00, trust 000 refid [172.16.1.62], delay 0.02592, dispersion 0.00142 transmitted 4, in filter 4 reference time: ddb7c566.e8e2acda Thu, Nov 16 2017 16:05:58.909 originate timestamp: ddb7c665.aa402c9b Thu, Nov 16 2017 16:10:13.665 transmit timestamp: ddb7c665.abf2c8a8 Thu, Nov 16 2017 16:10:13.671 filter delay: 0.02592 0.02596 0.02597 0.02599 0.00000 0.00000 0.00000 0.00000 filter offset: -0.00994 -0.00890 -0.00785 -0.00686 0.000000 0.000000 0.000000 0.000000 delay 0.02592, dispersion 0.00142 offset -0.009942 16 Nov 16:10:13 ntpdate[2058]: adjust time server 172.16.1.62 offset -0.009942 sec
[root@Cobbler ~]# date -s 20080101 Tue Jan 1 00:00:00 CST 2008 [root@Cobbler ~]# ntpdate 172.16.1.62 16 Nov 16:21:26 ntpdate[2085]: step time server 172.16.1.62 offset 311703675.400154 sec
說明: adjust和step,adjust同步時間的時候小於一秒,step同步時間的時候大於一秒
vim /etc/chrony.conf
內容和ntp是同樣的,知識順序顛倒了
systemctl status chronyd 查看狀態
注意:chrony 不能和ntp同時存在 只有centos7上有chrony