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  //允许192.168.10.0网段同步时间,不可修改参数

...

3、启动服务

[root@server1 ~]# service ntpd restart

[root@server1 ~]# chkconfig ntpd on    //启动服务

4、验证

[root@server1 ~]# netstat -anpu |grep ntpd    //监听端口udp123

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

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    //有时失败的话稍等5~10分钟再试即可

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

[root@ser1 ~]# hwclock  --systohc   //将系统时间同步到bios;--hctosys表示将bios时间同步到系统

3、与crond配合使用

[root@ser1 ~]# crontab -e

0 10 * * * /sbin/ntpdate 192.168.10.254

[root@ser1 ~]# service crond restart

[root@ser1 ~]# chkconfig crond on