天天看點

NTP網絡時間服務

很多伺服器都需要同步時間,是以我跟大家分享一下時間伺服器ntp,初學者可以了解一下

首先簡單介紹一下時間伺服器

NTP Network Time Protocol   網絡時間協定

服務端工具:ntpd

用戶端;ntpdate

協定端口:UDP 123

主配置檔案:  /etc/ntp.conf

restrict    權限控制

      kod    開啟阻止Kiss of Death包攻擊

      nomodify      用戶端不能更改ntp伺服器的時間參數,但是可以校對時間

      notrap        不提供trap遠端事件登陸

      nopeer        不予其他同一層的NTP伺服器同步時間   最多16層     

      noquery        不提供ntp服務

      server    設定上層NTP伺服器

NTP伺服器的搭建

1、安裝NTP

[root@server1 ~]# yum -y install ntp

2、修改主配置檔案

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

...

  5 restrict 192.168.10.0 mask 255.255.255.0 nomodify

3、啟動服務

[root@server1 ~]# service ntpd restart

[root@server1 ~]# chkconfig ntpd on

4、驗證

[root@server1 ~]# netstat -anpu |grep ntpd

udp        0      0 192.168.10.254:123    0.0.0.0:*              3375/ntpd  j

udp        0      0 127.0.0.1:123             0.0.0.0:*              3375/ntpd  

udp        0      0 0.0.0.0:123                 0.0.0.0:*              3375/ntpd           

用戶端驗證

1、首先調整時間,使之與伺服器時間不一緻

[root@ser1 ~]# date

2013年 11月 20日 星期三 10:25:28 CST

[root@ser1 ~]# date 111819302013

2、與伺服器同步

[root@ser1 ~]# ntpdate 192.168.10.254

20 Nov 11:09:29 ntpdate[5798]: adjust time server 192.168.10.254 offset -0.000004 sec

3、與crond配合使用

[root@ser1 ~]# crontab -e

0 10 * * * /sbin/ntpdate 192.168.10.254

[root@ser1 ~]# service crond restart

[root@ser1 ~]# chkconfig crond on

繼續閱讀