CentOS下快速编译安装NTP时间同步服务器

NTP(Network Time Protocol)是由美国德拉瓦大学的David L. Mills教授于1985年提出,除了可以估算封包在网络上的往返延迟外,还可独立地估算计算机时钟偏差,从而实现在网络上的高精准度计算机校时,它是设计用来在Internet上使不同的机器能维持相同时间的一种通讯协定。时间服务器(time server)是利用NTP的一种服务器,通过它可以使网络中的机器维持时间同步。在大多数的地方,NTP可以提供1-50ms的可信赖性的同步时间源和网络工作路径。

网络时间协议(NTP)的详细说明在RFC-1305[Mills 1992]中。RFC-1305对 NTP协议自动机在事件、状态、转变功能和行为方面给出了明确的说明。它以合适的算法以增强时钟的准确性,并且减轻多个由于同步源而产生的差错,实现了准确性低于毫秒的时间服务,以满足目前因特网中路径量测的需要。

一、搭建时间同步服务器
1、编译安装ntp server
[root@server ]# mkdir tools
[root@server ]# cd tools
[root@server tools]# wget ~ntp/ntp_spool/ntp4/ntp-4.2.6p5.tar.gz
[root@server tools]# tar xf ntp-4.2.6p5.tar.gz
[root@server tools]# cd ntp-4.2.6p5
[root@server ntp-4.2.6p5]# ./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
[root@server ntp-4.2.6p5]# make && make install
2、修改配置文件ntp.conf
[root@server ~]# cp /etc/ntp.conf /etc/ntp.conf.bak
[root@server ~]# vi /etc/ntp.conf
1)允许任何IP的客户机都可以进行时间同步
将“restrict default kod nomodify notrap nopeer noquery”这行修改成:
restrict default nomodify
2)只允许192.168.1.*网段的客户机进行时间同步
在“restrict default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)”之后增加一行:
restrict 192.168.1.0 mask 255.255.255.0 nomodify
3、启动NTP服务并设置随机启动
[root@server ~]# service ntpd start
[root@server ~]# chkconfig --level 35 ntpd on
4、查看ntp服务器工作情况
[root@server ~]# netstat -unl |grep 123        #查看123端口,操作结果如图
udp        0      0 192.168.1.41:123            0.0.0.0:*                             
udp        0      0 127.0.0.1:123              0.0.0.0:*                             
udp        0      0 0.0.0.0:123                0.0.0.0:*                             
udp        0      0 fe80::20c:29ff:feb1:123    :::*                                   
udp        0      0 ::1:123                    :::*                                   
udp        0      0 :::123                      :::*
5、查看ntp进程是否正常启动
[root@server ~]# ps -ef|grep ntp
ntp      17589    1  0 21:20 ?        00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
root    17607  4441  0 21:26 pts/0    00:00:00 grep ntp

PS:ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。

二、配置时间同步客户机
[root@client ~]# date    #同步之前系统时间
2012年 10月 12日 星期五 22:44:08 CST
[root@client ~]# ntpdate 192.168.1.41  #192.168.1.41是NTP服务器的IP
[root@client ~]# hwclock -w  #把时间写入BIOS
[root@client ~]# date    #同步之后系统时间
2012年 10月 11日 星期四 21:45:30 CST 
[root@client ~]# crontab -e  #每天凌晨4点Linux系统自动进行网络时间校准
00 04 * * * /usr/sbin/ntpdate 192.168.1.41; /sbin/hwclock -w
[root@client ~]# service crond restart  #重启crond服务

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/0629dd7023f47aefd80007fcfea3de54.html