在生产环境中,常常需要将各服务器之间的时间同步起来,来完成主从之间的同步,或者说是各集群服务器为了响应用户请求,有时间会被分配到不同的服务器上,那么保证取得的数据要一致,那就必须保证时间上是同步的,这才能保证一定意义上数据的同步。
我们来讲讲NTP服务器的配置:
首先,去网上下载 NTP的rpm包:
我们这里用的是: ntp-4.2.6p5-1.el6.centos.x86_64.rpm
安装:
rpm -ivh ntp-4.2.6p5-1.el6.centos.x86_64.rpm配置:
#restrict default kod nomodify notrap nopeer noquery restrict default nomodify 将上面这行改成本行的设置 允许任何IP的客户机都可以进行时间同步 restrict -6 default kod nomodify notrap nopeer noquery # Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. #restrict 127.0.0.1 restrict 192.168.1.0 mask 255.255.255.0 nomodify 只允许192.168.1.***网段的客户机进行时间同步 restrict -6 ::1 # Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
我们查看ntp服务器的时间:
再查看另外一台虚拟机的时间:
我们使用同步时间命令来同步,再查看结果明显已经改过来了。
当然,为了方便我们可以将ntpdate命令加入到周期性任务计划中去。