安装ntp
centos 6.4已经自带了ntp了,无需安装
检查是否已安装了ntp rpm -qa | grep ntp
如果需要安装:yum -y install ntp
设置开机启动
检查是否开机启动
sudo chkconfig --list ntpd
设置开机启动
sudo chkconfig ntpd on
手工同步一下时间
为了防止时间相差过大,请先手工同步一下服务端时间
service ntpd status 保证ntp处于关闭状态,否则手工同步会报错 the NTP socket is in use, exiting
手工同步命令
ntpdate cn.ntp.org.cn #cn.ntp.org.cn 中国ntp服务器
server修改配置文件
vim /etc/ntp.conf
restrict 192.168.56.0 mask 255.255.255.0 nomodify
#server cn.ntp.org.cn
server s1a.time.edu.cn
client修改配置文件
vim /etc/ntp.conf
server hadoop1
启动ntp
service ntpd start
service ntpd restart
验证
netstat -upnl |grep ntpd //查看时程
ntpq -pn //查看同步的服务器IP
ntpstat //同步的结果
ntpq -c version
watch ntpq -p
错误
ntpdate -u ip -> no server suitable for synchronization found
判断:在ntp客户端用ntpdate –d serverIP查看,发现有“Server dropped: strata too high”的错误,并且显示“stratum 16”。而正常情况下stratum这个值得范围是“0~15”。
原因:NTP server还没有和其自身或者它的server同步上。在ntp server上重新启动ntp服务后,ntpserver自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令时会产生no server suitable for synchronization found的错误。
处理:等待几分钟后,重试一般解决。
也可以使用命令 ntpq -p查看情