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

NTP服务器搭建教程

2017-01-05 15:24 393 查看
NTP服务器搭建NTP网络时间协议NTP(Network Time Protocol)
1.ntp server安装:
[root@localhost ~]# yum -y install ntp tzdatantp相关文件说明:/etc/ntp.conf #ntp server配置文件/usr/sbin/ntpd#ntp server程序/usr/sbin/ntpdate#ntp client校正工具/etc/sysconfig/clock#时区配置文件2./etc/ntp.conf配置文件说明,主要配置restrict和server
#restrict设置格式:#restrict [授权同步的网段] mask [netmask] [parameter]例:restrict 192.168.6.0 mask 255.255.252.0 nomodifyparameter说明:kod kod技术可以阻止“Kiss of Death “包对服务器的破坏nomodity client可通过ntp进行时间同步,但不能更改server参数notrap 不提供trap远程登陆功能nopeer 不与其它同一层的ntp server进行时间同步noquery 拒绝ntp时间同步notrust 拒绝无认证的clientignore 拒绝连接到ntp server#server设置格式#server [hostname|ip][parameter]例:server server asia.pool.ntp.org preferparameter说明:prefer 最高优先级burst 当一个运程NTP服务器可用时,向它发送一系列的并发包进行检测。iburst 当一个运程NTP服务器不可用时,向它发送一系列的并发包进行检测。3.ntp配置实例 server端 1)配置/etc/ntp.conf[root@localhost ~]# vim /etc/ntp.conf#For more information about this file, see the man pages#ntp.conf(5),ntp_acc(5),ntp_auth(5),ntp_clock(5),ntp_misc(5),ntp_mon(5).driftfile /var/lib/ntp/drift#Permit time synchronization with our time source, but do not#permit the source to query or modify the service on this system.restrict default kod nomodify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noquery#Permit all access over the loopback interface. This could#be tightened as well, but to do so would effect some of#the administrative functions.restrict 127.0.0.1restrict -6 ::1#Hosts on local network are less restricted.#restrict 192.168.1.0 mask 255.255.255.0 nomodify notraprestrict 192.168.6.0 mask 255.255.252.0 nomodify 本地网段授权访问#Use public servers from the pool.ntp.org project.#Please consider joining the pool (http://www.pool.ntp.org/join.html).#server 0.centos.pool.ntp.org iburst#server 1.centos.pool.ntp.org iburst#server 2.centos.pool.ntp.org iburst#server 3.centos.pool.ntp.org iburstserver asia.pool.ntp.org preferserver 0.asia.pool.ntp.orgserver 1.asia.pool.ntp.orgserver 2.asia.pool.ntp.orgserver time.nist.gov#broadcast 192.168.1.255 autokey # broadcast server... 2)NTP启动与端口检查:[root@localhost ~]# service ntpd startStarting ntpd:[root@localhost ~]# chkconfig ntpd on[root@localhost ~]# chkconfig --list | grep ntpntpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭ntpdate 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭[root@localhost ~]# netstat -nutlp | grep ntpudp 0 0 192.168.2.213:123 0.0.0.0:* 21798/ntpdudp 0 0 192.168.6.213:123 0.0.0.0:* 21798/ntpdudp 0 0 127.0.0.1:123 0.0.0.0:* 21798/ntpdudp 0 0 0.0.0.0:123 0.0.0.0:* 21798/ntpdudp 0 0 fe80::221:f6ff:fed4:d502:123 :::* 21798/ntpdudp 0 0 fe80::221:f6ff:fed4:d501:123 :::* 21798/ntpdudp 0 0 ::1:123 :::* 21798/ntpdudp 0 0 :::123 :::* 21798/ntpd 3)ntp server与上联是否同步#查看server与上联是否同步,时间校正约8279ms,每64s轮循更新一次。[root@localhost ~]# ntpstatSynchronised to NTP server (62.201.225.9) at stratum 3 #==>上层ntptime correct to within 8279 ms #==>校正时间差polling server every 64 s #==>下次同步时间 #查看server与上联的状态[root@localhost ~]# ntpq -premote refid st t when poll reach delay offset jitter====================================================================*time.iqnet.com 62.201.214.162 2 u 146 64 124 393.411 -101.29 40.435-220.231.122.105 123.204.45.116 4 u 20 64 377 341.475 58.745 47.945+vps.jre655.com 10.84.87.146 2 u 24 64 377 211.095 0.177 38.002web10.hnshostin 158.43.128.33 2 u 17 64 177 392.506 -134.76 39.146+24.56.178.140 .ACTS. 1 u 27 64 377 282.739 -59.521 42.959 参数说明:reomte server上联的ntp主机名或ip;注意最左端符号;*表示当前正使用的上层ntp;+代表与本机server也有连接,作为侯选ntprefid 给上层ntp提供时间校对的服务器st 上层ntp stratum级别when 上一次与上层ntp同步的时间,单位为秒。poll 同步时间间隔reach 已经同上层ntp同步更新的次数delay 网络传输过程中的延迟时间,单位为10^(-6)soffset 时间补偿,单位为10^(-3)sjitter 系统时间与bios硬件时间差,单位为10^(-6)s4.ntp配置实例client端
通过crontab设置更新时间[root@dns-2-253 ~]# crontab -l*/5 * * * * /usr/sbin/ntpdate 192.168.6.213 &> /dev/null client测试是否同步成功[root@dns-2-253 ~]# ntpdate 192.168.6.21310 Nov 21:25:43 ntpdate[26381]: step time server 192.168.6.213 offset 1.318393 sec备注:如果无法同步,需查是否开启了防火墙。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息