周海汉 /文 2010.3.30
对多个linux服务器,时间保持一致是很必要的。根据精确度要求,应该有相应的时间间隔进行时间同步。如果不进行时间同步,时间久了就会差别很大,遇到问题时定位就很困难。因为多台设备的配合,log之间可能有前因后果,时间是同步事件的先后的重要依据。
一般来说,对一个机房内的设备,可以设置一台时间服务器,由它定期从一个标准的时间服务器上获取时间。其他的服务器可以通过内网的连接从这台服务器进行同步。这样不仅时间会一致,而且照顾到一些没有公网的设备。
本文测试系统: [root@test ~]# cat /etc/*release
[root@test ~]# rpm -qf /usr/sbin/ntpd 在安装时应该确定ntp包已经安装。
启动服务器
如果ntpd已经安装,则可以直接启动: [root@test ~]# service ntpd start
同时,也需要检查一下配置文件,centos缺省都配置好了。 [root@test ~]# vi /etc/ntp.conf server 0.centos.pool.ntp.org driftfile /var/lib/ntp/drift keys /etc/ntp/keys
检查一下时间服务器是否可用: [root@test ~]# ping 0.centos.pool.ntp.org [root@test ~]# cat /etc/resolv.conf
设置ntpd自启动[root@test ~]# find /etc/rc.d/ -name "*ntpd"
检查防火墙[root@test ~]# iptables -L 对比较严格的防火墙,应该对ntp端口123进行配置: [root@test ~]# iptables -A INPUT -p udp --dport 123 -j ACCEPT
客户端配置
客户端采用ntpdate来更新,配置在crontab中。根据需要决定频率。在每一台需要同步时间的设备上设置crontab [root@test1 ~]# crontab -e
00 00 * * * /usr/sbin/ntpdate 192.168.12.31
192.168.12.31是test服务器的内网地址。 crontab 设置的是每天0点同步时间。 为了保证时间服务器可用,将命令先在命令行下执行一下。 [root@test1 ~]# ntpdate 192.168.12.31 说明同步时间成功。 |
|