简介:
NTP(NetworkTime Protocol,网络时间协议)是用来在分布式时间服务器和客户端之间进行时间同步。–>另一篇关于时间的
NTP基于UDP报文进行传输,使用的UDP端口号为123。
使用NTP的目的是对网络内所有具有时钟的设备进行时钟同步,使网络内所有设备的时钟保持一致,从而使设备能够提供基于统一时间的多种应用。
对于时间错误会导致服务器宕机,所以运行NTP的本地系统,既可以接受来自其他时钟源的同步,又可以作为时钟源同步其他的时钟,并且可以和其他设备互相同步。
NTP服务器搭建
Tips: hadoop对局域网时间同步要求非常高,所以适合搭建使用ntp服务器
- /etc/ntp/ntpserver.conf
- /etc/ntp.conf
- 1.搭建环境
环境:CentOS6.4
Server192.168.126.1
Client192.168.126.2
- 2.安装NTP
1
2
|
#vim /etc/ntp.conf
restrict 192.168.126.0255.255.255.0 nomodify notrap
|
1
2
3
|
#vi /etc/ntp.conf
server127.127.1.0
fudge127.127.1.0stratum 10
|
1
|
chkconfig --level 345 ntpon
|
1
|
-A INPUT -m state --state NEW -m tcp -p tcp --dport 123 -jACCEPT
|
客户端
- 1.与服务端同步时间执行以下命令
手工执行或用crontab来执行
使用crontab –e
1
|
0 21 * * * ntpdate 192.168.126.1 >> /root/ntpdate.log 2>&1
|
1
|
-A INPUT -m state --state NEW -m tcp -p tcp --dport 123 -jACCEPT
|
手动脚本设置同步
1
2
|
/usr/sbin/ntpdate ntp.sjtu.edu.cn >> /var/log/ntp.log 2>&1; /sbin/hwclock –w
#写入crontab,根据业务需要定制时间同步的频率
|