集群中各服务器之间可以协调工做的前提之一,时间必须同步。若是B主机比A主机时间慢2个小时,A主机向B主机下达一个命令,B主机2小时后才执行。对整个集群而言,将是没法忍受的。node
搭建NTP服务器可让集群中的全部服务器工做在同一时钟周期内,作到步调一致。下面是实现方法:vim
NTP server IP:192.168.100.104服务器
NTP client IP:192.168.100.100网络
NTP server端设置:ide
1、安装NTP服务:ui
[root@node1 ~]# yum -y install ntpspa
2、配置NTP服务:rest
[root@node1 ~]#vim /etc/ntp.conform
添加一下三行:server
一、server 127.127.1.0 //local地址
二、fudge 127.127.1.0 stratum 10 //这行是时间服务器的层次。设为0则为顶级,若是要向别的NTP服务器更新时间,请不要把它设为0
三、restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap
(表示:容许192.168.100.0网段的服务器能够到NTP server上同步数据)
注:restrict这个参数主要语法格式:
restrict IP mask netmask_IP parameter
其中IP能够是软体位址,也能够是 default ,default 就相似0.0.0.0
paramter规则:
ignore:关闭全部的NTP 连线服务
nomodify:表示Client 端不能更改 Server 端的时间参数,不过Client端仍然能够透过Server 端來进行网络较时。
notrust:该 Client 除非经过认证,不然该 Client 来源将被视为不信任网域
noquery:不提供 Client 端的时间查询
若是 paramter彻底没有设定,那就表示该 IP (或网域) 没有任何限制!
3、iptables放行:
NTP服务默认走UPD协议,使用123端口,若是启动防火墙的话,须要配置一下防火墙。vim /etc/sysconfig/iptables 打开防火墙配置文件。加入以下配置项:
-A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
或:iptables -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT
4、重启NTP服务
[root@node1 ~]# /etc/init.d/ntpd restart
NTP client端设置:
1、按期去NTP服务器同步时间
[root@node2 ~]# vim /etc/crontab
添加:
* 2 * * * root /usr/sbin/ntpdate 192.168.100.104;/sbin/hwclock -w
2、同时复制到其余服务器
[root@node2 ~]# scp /etc/crontab root@192.168.100.101:/etc/
总结:
常见故障
客户端同时时出现:no server suitable for synchronization found 错误提示
缘由:
在ntp server上从新启动ntp服务后,ntp server自身或者与其server的同步的须要一个时间段,这个过程多是5分钟,在这个时间以内在客户端运行ntpdate命令时会产生no server suitable for synchronization found的错误。
那么如何知道什么时候ntp server完成了和自身同步的过程呢?
在ntp server上使用命令:
#ntpq -p