以某一台服务器的时间为准,其他服务器自己校对本地时间
服务端配置:
1.安装ntp软件
[root@cmyx ~]# yum install ntp*
修改配置文件:
[root@cmyx ~]# vim /etc/ntp.conf
配置文件说明如下:
第一行restrict、default定义默认访问规则,nomodify禁止远程主机修改本地服务器配置,notrap拒绝特殊的ntpdq捕获消息,noquery拒绝btodq/ntpdc查询(这里的查询是服务器本身状态查询)。
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
这句是手动增加的,意思是192.168.1.0网段的计算机都可以使用我们的NTP服务器来同步时间。
server 192.168.1.250
这句也是手动增加的,指明局域网中作为NTP服务器的IP;
(该配置文件的最后两行作用是当服务器与公用的时间服务器失去联系时以本地时间为客户端提供时间服务)
启动服务:
[root@cmyx ~]# service ntpd start
[root@cmyx ~]# chkconfig ntpd on
客户端配置:
1.安装ntp软件
[root@cmyx ~]# yum install ntp*
[root@cmyx ~]#ntpdate 192.168.1.11
以root身份运行周期性任务:
[root@localhost ~]# crontab -e
添加以下内容,每15分钟更新一下时间:
15 * * * * ntpdate 服务器IP
此处的ntpdate命令包含在ntp软件包中,记得确认系统中是否已安装。