实验环境:
RHEL5
Server:192.168.2.10
Client:192.168.2.120
一、搭建时间同步服务器
1、默认系统会安装ntp服务,如果没有使用yum install –y ntp安装
2、修改ntp.conf配置文件
vi /etc/ntp.conf
①、第一种配置:允许任何IP的客户机都可以进行时间同步
#restrict default kod nomodify notrap nopeer noquery
restrict default modify
②、第二种配置:只允许192.168.2.0网段的客户机进行时间同步
在restrict default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)之后增加一行:
restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap
3、启动ntp服务
service ntpd start
开机启动服务
chkconfig ntpd on
4、ntpd启动后,客户机要等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization found”错误。
二、配置时间同步客户机
手工执行 ntpdate 来同步
或者利用crontab来执行
crontab -e
*/10 * * * * /usr/sbin/ntpdate 192.168.2.10 >> /root/ntpdate.log 2>&1
表示每隔10分钟同步一次时间
三、在服务端验证:
# watch ntpq -p
Every 2.0s: ntpq -p Tue Dec 7 05:52:55 2010
remote refid st t when poll reach delay offset jitter
=============&