Linux NTP时间服务器
生活随笔
收集整理的這篇文章主要介紹了
Linux NTP时间服务器
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
NTP 時(shí)間服務(wù)器
ntp也是一種協(xié)議
ntp軟件(支持ntp協(xié)議)? CentOS6自帶 CentOS7需要安裝
chrony軟件(支持ntp協(xié)議)?? CentOS7自帶
安裝ntp
CentOS6系統(tǒng)自帶ntp,CentOS7需要自己安裝
[root@m02 ~]# yum -y install ntp [root@m02 ~]# rpm -qa ntp ntp-4.2.6p5-25.el7.centos.2.x86_64配置ntp
權(quán)限參數(shù)含義
noquery:不提供ntp服務(wù) notrap:不提供trap遠(yuǎn)程事件登錄的功能 nomodiy:表示客戶端不能更改ntp服務(wù)器的時(shí)間參數(shù),但可以通過(guò)ntp服務(wù)器進(jìn)行時(shí)間矯正 notrust:拒絕沒(méi)有通過(guò)認(rèn)證的客戶端 nokod:kod技術(shù)可以組織一種dos攻擊 ignore :關(guān)閉所有ntp服務(wù)配置文件更改
更改之前可以備份一下,以防改錯(cuò)
[root@m02 ~]# vim /etc/ntp.conf server ntp1.aliyun.com 加上這個(gè),因?yàn)槟J(rèn)是國(guó)外的時(shí)間同步服務(wù)器,使用國(guó)外的相對(duì)于使用阿里的,速度對(duì)比可想而知。加權(quán)限限制
格式:restrict IP 權(quán)限參數(shù) IP可以為ip地址或者default 權(quán)限參數(shù):nomodify notrap nopeer noquery 例如:restrict 172.16.1.0 mask 255.255.255.0 nomodify notrapntp服務(wù)改后和改前配置文件對(duì)比
[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啟動(dòng)ntp
[root@m02 ~]# systemctl start ntpd服務(wù)端可以先查看一下
利用ntpq -p命令和ntpstat命令
[root@m02 ~]# ntpq -p #顯示上一級(jí)連接的服務(wù)器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.685time-d-b.nist.g .STEP. 16 u - 512 0 0.000 0.000 0.000 [root@m02 ~]# ntpstat #顯示同步結(jié)果 現(xiàn)在的狀態(tài)信息 synchronised to NTP server (182.92.12.11) at stratum 3 time correct to within 11 mspolling server every 64 s客戶端測(cè)試結(jié)果
客戶機(jī)要等幾分鐘再與新啟動(dòng)的ntp服務(wù)器進(jìn)行時(shí)間同步,否則會(huì)提示no server suitable for synchronization found錯(cuò)誤。
而且同步有時(shí)會(huì)很慢
ntpdate -d 顯示同步過(guò)程
[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.006860.000000 0.000000 0.000000 0.000000 delay 0.02592, dispersion 0.00142 offset -0.00994216 Nov 16:10:13 ntpdate[2058]: adjust time server 172.16.1.62 offset -0.009942 secstep和adjust的區(qū)別
[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說(shuō)明: adjust和step,adjust同步時(shí)間的時(shí)候小于一秒,step同步時(shí)間的時(shí)候大于一秒
CentOS7自帶軟件chrony
配置文件
vim /etc/chrony.conf 內(nèi)容和ntp是一樣的,知識(shí)順序顛倒了 systemctl status chronyd 查看狀態(tài) 注意:chrony 不能和ntp同時(shí)存在 只有centos7上有chrony?
轉(zhuǎn)載于:https://www.cnblogs.com/lyq863987322/p/8250079.html
總結(jié)
以上是生活随笔為你收集整理的Linux NTP时间服务器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 梦到挖笋好几个在一起
- 下一篇: linux系统编程:IO读写过程的原子性