Linux下的ntp服務器

Linux下的ntp服務器vim

1.什麼是ntp服務器

NTPNetwork Time Protocol,網絡時間協議)是用來使計算機時間同步化的一種協議,它能夠使計算機對其服務器或時鐘源作同步化,它能夠提供 高精準度的時間校訂網絡

2.ntp配置文件的相關介紹ide

1.  /etc/ntp.conf
NTP服務的主要配置文件,不一樣的Linux版本文件所在的目錄可能會不一樣。
2.  /usr/share/zoneinfo
規定了各主要時區的時間設定文件。/usr/share/zoneinfo/Asia/Shanghai 爲中國大陸地區的時區設定文件。
3.  /etc/sysconfig/clock
時區設置文件
4.  /etc/localtime
本地系統的時間設定文件測試

[root@tx1 ~]# grep -v "^#" /etc/ntp.conf ui

restrict default kod nomodify notrap nopeer noquery//對於默認的client拒絕全部的操做spa

restrict -6 default kod nomodify notrap nopeer noquery  //針對ipv6的設置rest

restrict 127.0.0.1 //容許本機地址一切的操做server

restrict -6 ::1blog

server 0.rhel.pool.ntp.org //設置上層服務器作同步ip地址

server 1.rhel.pool.ntp.org

server 2.rhel.pool.ntp.org

server  127.127.1.0     //local地址

fudge   127.127.1.0 stratum 10   //這行是時間服務器的層次。設爲0則爲頂級,若是要向別的NTP服務器更新時間,請不要把它設爲0

driftfile /var/lib/ntp/drift   //記錄上次的NTP server與上層NTP server聯接所花費的時間

keys /etc/ntp/keys

參數:

ignore :關閉全部的 NTP 聯機服務
nomodify:客戶端不能更改服務端的時間參數,可是客戶端能夠經過服務端進行網絡校時。
notrust :客戶端除非經過認證,不然該客戶端來源將被視爲不信任子網
noquery :不提供客戶端的時間查詢

3.具體配置

[root@tx1 ~]# vim /etc/ntp.conf

3 restrict default kod nomodify notrap nopeer noquery

 4 #restrict -6 default kod nomodify notrap nopeer noquery

 5 restrict default nomodify

 6 restrict 192.168.8.0 mask 255.255.255.0 nomodify

11 restrict 127.0.0.1

18 #server 0.rhel.pool.ntp.org

19 #server 1.rhel.pool.ntp.org

20 #server 2.rhel.pool.ntp.org

21 server 192.168.8.70

31 server  127.127.1.0     # local clock

32 fudge   127.127.1.0 stratum 10


[root@tx1 ~]# /etc/init.d/ntpd restart

Shutting down ntpd:                                        [  OK  ]

Starting ntpd: [  OK  ]

客戶端測試    

注:客戶端的/etc/hosts裏須要加上ntp服務器的ip地址和主機名

[root@tx2 ~]# ntpdate 192.168.8.70

2 Mar 00:35:44 ntpdate[11181]: no server suitable for synchronization found

注:ntp server上啓動ntp服務後,ntp server自身或者與其server的同步的須要一個時間段,這個過程多是5分鐘,在這個時間以內在客戶端運行ntpdate命令進行同步時會產生 no server suitable for synchronization found的錯誤。

查看同步的過程

[root@tx1 ~]# watch ntpq -p

注:LOCAL的這個就是與自身同步的ntp serverreach這個值,在啓動ntp server服務後,這個值就從0開始不斷增長,當增長到17的時候,從0175次的變動,每一次是poll的值的秒數,是64*5=320秒的時間。
客戶端測試

[root@tx2 ~]# ntpdate 192.168.8.70

2 Mar 00:40:51 ntpdate[11184]: adjust time server 192.168.8.70 offset -0.000031 sec

[root@tx2 ~]# date

Sat Mar  2 01:00:13 CST 2013

服務器端

[root@tx1 ~]# date

Sat Mar  2 01:00:15 CST 2013

[root@tx1 ~]#

相關文章
相關標籤/搜索