您的位置:首页 > 编程语言 > PHP开发

ntpd时间同步 安装与配置

2016-09-30 17:57 323 查看
1,安装yum -y install ntpvim /etc/ntp.conf默认配置:driftfile /var/lib/ntp/driftrestrict default kod nomodify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict -6 ::1server 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.pool.ntp.org iburstserver 3.centos.pool.ntp.org iburstincludefile /etc/ntp/crypto/pwkeys /etc/ntp/keys修改:允许任何IP的客户机都可以进行时间同步将“restrict default kod nomodify notrap nopeer noquery”这行修改成:restrict default nomodify启动前先关闭防火墙service ntpd start客服端测试ntpdate 192.168.1.101 最好客户端安装ntpd,指定时间server为上面配置的服务器地址,推荐server 192.168.1.101ntpd是步进式的逐渐调整时间,测试时如果你的ntpd服务器时间是准的,客户端不一定要ntpd服务启动时就自动对准,但过一段时间,就同步了。TODO加上防火墙后测试:==============艺搜参考========== 为什么要使用ntpd而不是ntpdate?原因很简单,ntpd是步进式的逐渐调整时间,而ntpdate是断点更新,比如现在服务器时间是9.18分,而标准时间是9.28分,ntpd会在一段时间内逐渐的把时间校准到与标准时间相同,而ntpdate会立刻把时间调整到9.28分,如果你往数据库内写入内容或在其他对时间有严格要求的生产环境下,产生的后果会是很严重的。

原理 1. 首先主机启动NTP。 2. 客户端会向NTP服务器发送调整时间的message。 3. 然后NTP server会送出当前的标准时间给client 4. client接受来自server的时间后,会根据这个信息来调整自己的时间。这样就实现了网络对时。NTP这个deamon采用了UDP 123端口。

设置时区:cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtimeyum -y install ntpvim /etc/ntp.confserver 127.127.1.0 # 允许本机地址一切的操作fudge 127.127.1.0 stratum 8 //这两行在任意地方添加 service ntpd start //启动ntp服务客户端同步:ntpdate 192.168.1.105ntpdate: no server suitable for synchronization found 原因:1,防火墙原因iptables -I INPUT -p udp --dport 123 -j ACCEPT //ntp 默认使用 udp 的123号端口客户端安装ntpd,指定时间server为上面配置的服务器地址,推荐

查看ntp服务器有无和上层连通ntpstat

ntpq –p #查看本机和上层服务器的时间同步结果

http://xstarcd.github.io/wiki/sysadmin/ntpd.htmlhttp://zyan.cc/post/281/wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p8.tar.gzhttp://www.ntp.org/downloads.html./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks允许任何IP的客户机都可以进行时间同步将“restrict default kod nomodify notrap nopeer noquery”这行修改成:restrict default nomodify
fudge 127.127.1.1 stratum 10 //这行是时间服务器的层次。设为0则为顶级,如果要向别的NTP服务器更新时间,请不要把它设为0driftfile /etc/ntp/drift //记录上次的NTP server与上层NTP server联接所花费的时间
只允许192.168.18.***网段的客户机进行时间同步在restrict default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)之后增加一行:restrict 192.168.18.0 mask 255.255.255.0 nomodify以守护进程启动ntpd/usr/local/ntp/bin/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pidNTP(The Network Time Protocol) 是网络时间协议自己搭建时间服务器需要指定一个上层的时间服务器,然后它可以向局域网内的其它机器
提供同步服务。
restrict IP地址 mask 子网掩码 参数 其中 IP 可以是IP地址,也可以是 default ,default 就是指所有的IP 参数有以下几个: ignore :关闭所有的 NTP 联机服务 nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。 notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网 noquery :不提供客户端的时间查询 注意:如果参数没有设定,那就表示该 IP (或子网)没有任何限制!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: