ntp时间服务器源码安装

源码安装的ntp服务/etc/下是没有ntp.conf配置文件的,需要先yum安装ntp服务把/etc/ntp.conf文件备份后,在yum –y remove ntp*删除掉安装的ntp。

下面正式开始安装

1、首先创建一个ntp目录

mkdir /ntp

cd /ntp

2.下载ntp源码安装包

wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2.6p5.tar.gz

3.解压

tar -xzvf ntp-4.2.6p5.tar.gz

4.编译并安装

cd ntp-4.2.6p5

./configure --prefix=/usr/local/ntp--enable-all-clocks --enable-parse-clocks

make &&make install

5.更改配置文件

1)允许任何IP的客户机都可以进行时间同步
“restrictdefault kod nomodify notrap nopeer noquery”这行修改成:
restrict default nomodify
2
)只允许192.168.1.*网段的客户机进行时间同步
“restrictdefault nomodify notrap noquery(表示默认拒绝所有IP的时间同步)之后增加一行:
restrict 192.168.1.0 mask 255.255.255.0nomodify

 

另外,配置文件默认通过网络同步时间:

1

server 0.centos.pool.ntp.org iburst

2

server 1.centos.pool.ntp.org iburst

 

3

server 2.centos.pool.ntp.org iburst

 

4

server 3.centos.pool.ntp.org iburst

RedHat默认有类似上面4行内容,域名不一样而已)
如果需要使用本地时间,则把上面4行删掉或者用“#”号注释掉,然后添加以下两行:

1

server 127.127.1.0

2

fudge  127.127.1.0 stratum 10



6.启动ntp服务

/usr/local/ntp/bin/ntpd-c /etc/ntp.conf -p /tmp/ntpd.pid

7.开机自启动

直接把ntp启动命令添加到/etc/re.local就可以

8.查看ntp服务器工作情况

netstat –unl|grep 123   #查看123端口,结果如下


9.查看ntp服务是否正常启动


PSntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“noserver 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  #
每天凌晨4Linux系统自动进行网络时间校准
00 04 * * * /usr/sbin/ntpdate 192.168.1.41;/sbin/hwclock -w
[root@client ~]# service crond restart  #
重启crond服务

你可能感兴趣的:(ntp时间服务器源码安装)