linux服务器时间同步
由于分布式系统对时间一致性要求比较高,因此需要一台同一时间的服务器,其他服务器时间以他为准。
这里使用的工具是ntp 4.2.6p5
操作系统为centos7
一、设置时间服务器
修改/etc/ntp.conf
restrict default nomodify notrap nopeer noquer
restrict 192.168.160.0 mask 255.255.255.0 nomodify notrap
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
restrict 0.cn.pool.ntp.org
restrict 1.cn.pool.ntp.org
restrict 2.cn.pool.ntp.org
restrict 3.cn.pool.ntp.org
server 127.0.0.1
fudge 127.0.0.1 stratum 10
权限配置关键字如下:
ignore:关闭所有的 NTP 联机服务
nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网
noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器
notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日
志记录程序。
nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟
kod : 访问违规时发送 KoD 包。
restrict -6 表示IPV6地址的权限设置。
restrict 192.168.160.0 mask 255.255.255.0 nomodify notrap 表示对160网段的客户端开放网络校时功能
server 后面跟的地址为校时服务器上层的校时服务器,其中127.0.0.1表示,根据自己校时
fudge 127.0.0.1 stratum 10 其中stratum的范围为0-15
开启ntp服务
ntpd -c /etc/ntp.conf
每次修改了配置文件,都需要重启ntp服务
二、设置客户端
修改/etc/ntp.conf
server 校时服务器ip
将校时命令配置到crontab中
*/5 * * * * /usr/sbin/ntpdate 192.168.160.66 &> /var/log/ntpdate.log
注意:不能直接使用ntpdate 校时服务器ip
还没有评论,来说两句吧...