ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:57.11KB ,
资源ID:9482751      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9482751.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(linux下NTP服务的配置.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

linux下NTP服务的配置.docx

1、linux下NTP服务的配置Network Time Protocol(NTP,网络时间协议)用于同步它所有客户端时钟的服务。NTP服务器将本地系统的时钟与一个公共的NTP服务器同步然后作为时间主机提供服务,使本地网络的所有客户端能同步时钟。 同步时钟最大的好处就是相关系统上日志文件中的数据,如果网络中使用中央日志主机集中管理日志,得到的日志结果就更能反映真实情况。在同步了时钟的网络中,集中式的性能监控、服务监控系统能实时的反应系统信息,系统管理员可以快速的检测和解决系统错误。安装配置NTP服务 下面将介绍NTP服务器的简单配置:第一步,安装NTP服务 一般的Linux发行版都会带ntp软件包

2、,如果你的系统中还没有安装,就使用rpm命令安装此包,以下以centos系统为例配置一台时间服务器:查找当前系统是否已安装ntprootlocalhost # rpm -qa | grep ntpchkfontpath-1.10.1-1.1ntp-4.2.2p1-8.el5.centos.1 (这个就是已经安装的RPM包)如果没有安装,可用下例命令安装:rootlocalhost # rpm -ivh ntp-4.2.2p1-8.el5.centos.1.rpm第二步,配置NTP服务器NTP服务器配置如下: 编辑配置文件/etc/ntp.confrestrict default kod nom

3、odify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict -6 :1restrict 192.168.1.0 mask 255.255.255.0 nomodify notrapserver192.168.146.225server 0.centos.pool.ntp.orgserver 1.centos.pool.ntp.orgserver 2.centos.pool.ntp.orgserver 127.127.1.0 # local

4、clockfudge 127.127.1.0 stratum 10配置文件说明如下: 第一行restrict、default定义默认访问规则,nomodify禁止远程主机修改本地服务器配置,notrap拒绝特殊的ntpdq捕获消息,noquery拒绝btodq/ntpdc查询(这里的查询是服务器本身状态查询)。 restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap 这句是手动增加的,意思是从192.168.1.1-192.168.1.254的服务器都可以使用我们的NTP服务器来同步时间。 server 192.168.146.225 这

5、句也是手动增加的,指明局域网中作为NTP服务器的IP;配置文件的最后两行作用是当服务器与公用的时间服务器失去联系时以本地时间为客户端提供时间服务。端口ntp使用udp协议,记得开放其123端口。启动NTPD 为了使NTP服务可以在系统引导的时候自动启动,执行: #chkconfig ntpd on 启动ntpd:service ntpd startNTP客户端配置: 在客户端手动执行“ntpdate 服务器IP”来同步时间; 另可以使用crond来定时同步时间: 以root身份运行周期性任务:rootsupersun root# crontab -e添加以下内容,每15分钟更新一下时间:15

6、* * * * ntpdate 服务器IP 此处的ntpdate命令包含在ntp软件包中,记得确认系统中是否已安装。第三步,检查时间服务器是否正确同步 使用下面的命令检查时间服务器同步的状态: #ntpq -p 一个可以证明同步有问题的证据是:所有远程服务器的jitter值是4000并且delay和reach的值是0。可能的原因有: 有防火墙阻断了与server之间的通讯,即123端口是否正常开放; 此外每次重启NTP服务器之后大约要35分钟客户端才能与server建立正常的通讯连接,否则你在客户端执行“ntpdate 服务器ip”的时候将返回: 27 Jun 10:20:17 ntpdate

7、21920: no server suitable for synchronization foundLinux下NTP服务器的配置 Linux下的ntp软件不但能自动与互联网上的时钟保持同步,同时本身已经是一台SNTP服务器了,可以供局域网内的电脑校对时间。服务配置如下:第一步 安装软件包 我用的是RPM包安装的,或者到http:/www.eecis.udel.edu/ntp/去下载xntp重新编译一个新的。 #rpm -qa | grep ntp ntp-4.2.0-7 chkfontpath-1.10.0-1第二步让LAN的时间服务器(第三级)与互联网上的时间服务器(第一或者第二级)同步

8、 修改/etc/ntp.conf这是NTP的主要配置文件,里面设置了你用来同步时间的时间服务器的域名或者IP地址,下面是到 互联网同步时间的最基本的配置: 首先定义我们喜欢的时间服务器: server ntp.research.gov server otherntp.research.gov 接下来,我们设置上面两台服务器的访问权限,在这个例子中我们不允许它们修改或者查询我们配置在Linux上的NTP服务器restrictntp.research.govmask 255.255.255.255 nomodify notrap noquery restrictotherntp.research.

9、govmask 255.255.255.255 nomodify notrap noquery 掩码255.255.255.255是用来 限制远程NTP服务器的掩码地址。 接下来设置允许访问我们时间服务器的客户机地址,通常这些服务器都应该位于我们自己局域网内。请注意,配置中noquery已经去掉了: restrict 192.168.0.0 mask 255.255.255.0 notrust nomodify notrap 在上例中,掩码地址扩展为255,因此从192.168.0.1-192.168.0.254的服 务器都可以使用我们的NTP服务器来同步时间。 最后,也是最重要的是默认的限制

10、配置要从你配置文件中删除,否则它将覆盖你所有的配置选项,你将发现如果不删除该配置,你的时间服务器将只能和自己通讯。 如果ntp.conf中有以下一行,请将它注释:#restrict default ignore 保存你的配置文件,然后对每个你在ntp.conf里配置的时间服务器执行2编查询命令: #ntpdatentp.research.gov 27 Jun 10:12:01 ntpdate25475: adjust time serverntp.research.govoffset -0.127154 sec #ntpdatentp.research.gov 27 Jun 10:12:06

11、ntpdate25478: adjust time serverntp.research.govoffset 0.010008 sec第三步 启动NTP进程 为了使NTP服务可以在系统引导的时候自动启动,执行: #chkconfig ntpd on启动/关闭/重启NTP/查看状态的命令是:#/etc/init.d/ntpd start #/etc/init.d/ntpd stop #/etc/init.d/ntpd restart #/etc/init.d/ntpd status切记每次修改了配置文件后都需要重新启动服务来使配置生效。可以使用下面的命令来检查NTP服务 是否启动,你应该可以得到

12、一个进程ID号:#pgrep ntpd第四步 检查时间服务器是否正确同步 使用下面的命令检查时间服务器同步的状态:#ntpq -p一个可以证明同步问题的证据是所有远程服务器的jitter值是4000并且delay和reach的值是0。可能的原因有: 配置文件中的restrict default ignore没有被注释 有防火墙阻断了与server之间的通讯 此外每次重启NTP服务器之后大约要35分钟客户端才能与server建立正常的通讯连接,否则你执行ntpdate ip的时候将返回: 27 Jun 10:20:17 ntpdate21920: no server suitable for s

13、ynchronization found第五步 客户端与ntp服务器同步时间在客户端安装NTP,安装过程同NTP在服务器端。 客户端开启ntp服务 #service ntpd start 与ntp服务器同步 #ntpdate (ntp服务器地址)接下来编辑 /etc/ntp.confntp.conf#server 127.127.1.0 # local clockfudge 127.127.1.0 stratum 10server stdtime.gov.hk # A stratum 1 server at server.orgserver 192.168.x.y #x.y为你前面所装机器在局

14、域网里的IPdriftfile /etc/ntp/driftbroadcastdelay 0.008authenticate nokeys /etc/ntp/keysrestrict 192.168.x.0 mask 255.255.255.0 notrust nomodify notrap/x.0为你所在局域网段restrict 127.0.0.1restrict 192.168.x.y #x.y为你前面所装机器在局域网里的IP#restrict default ignore#同时配置#/sbin/service ntpd start /启动ntpd 参数可为restart start st

15、op#/sbin/chkconfig -add ntpd#/sbin/chkconfig -level 234 ntpd on /配置在开机时运行如何检查?#netstat -unl | grep 123 /查看123端口#ndptrace 192.168.x.y /看校对时间过程,出现offset即为正常 否则为time out# ntpq -p如果出现 jitter的值 为4000则是防火墙或者网络问题正常为remote refid st t when poll reach delay offset jitter=*clock.nc.fukuok .GPS. 1 u 43 64 37 19

16、.067 -6.884 10.339+clock.tl.fukuok .GPS. 1 u 36 64 35 19.670 -3.259 2.341LOCAL(0) LOCAL(0) 5 l 45 64 37 0.000 0.000 0.001几点注意:1.虽然ntp溢出问题较少 ,但建议配置大型网罗的时候,不要装在重要数据库服务器或者Web主机上(Ntp是root权限)2.在遇到问题之前,先看看ntp自带的文档。3.防火墙问题的话,送一句配置$TMP -t filter -A INPUT -p udp -destination-port 123 -j ACCEPT也就是123 udp in 全

17、部接受。如果子网IP仍然提示4000错误,可以把restrict 192.168.0.0 mask 255.255.255.0 notrust nomodify notrap改为restrict 192.168.0.0 mask 255.255.255.0 nomodify对于权限参数的说明可以参考台湾鸟哥的文章的说明:rootroot# vi /etc/ntp.conf# 1. 關於權限設定部分#權限的設定主要以restrict 這個參數來設定,主要的語法為:#restrict IP mask netmask_IP parameter#其中IP可以是軟體位址,也可以是 default ,de

18、fault 就類似 0.0.0.0 咯!#至於 paramter則有:#ignore:關閉所有的NTP 連線服務#nomodify:表示Client 端不能更改 Server 端的時間參數,不過,#Client端仍然可以透過 Server 端來進行網路校時。#notrust:該 Client 除非通過認證,否則該 Client 來源將被視為不信任網域#noquery:不提供 Client 端的時間查詢#如果 paramter完全沒有設定,那就表示該 IP (或網域) 沒有任何限制!#在我們這個例子當中,因為拒絕所有,僅開放192.168.0.0/24 ,#並且讓127.0.0.1 以及本機 I

19、P 192.168.0.2 可以不受限制,所以:restrict default ignore# 關閉所有的 NTP 要求封包restrict 127.0.0.1#開啟內部遞迴網路介面 lorestrict 192.168.0.2# 主機本身的 IP 也同時開啟!restrict 192.168.100.20mask 255.255.255.255 nomodify# 針對另一個IP 開放讓他可以更新時間!restrict 192.168.0.0mask 255.255.255.0 nomodify# 在網域裡面的client 可以進行網路校時,但不會影響 Server !# 2. 上層主機的

20、設定#上層主機我們選擇time.stdtime.gov.tw ,要設定上層主機主要以 server#這個參數來設定,語法為:#server IP|FQDN prefer#Server 後面接的就是我們上層 Time Server 囉!而如果 Server 參數#後面加上perfer 的話,那表示我們的 NTP 主機主要以該部主機來作為#時間校正的對應。另外,為了解決更新時間封包的傳送延遲動作,#所以可以使用driftfile 來規定我們的主機#在與 Time Server 溝通時所花費的時間,可以記錄在 driftfile#後面接的檔案內,例如下面的範例中,我們的NTP server 與#ti

21、me.stdtime.gov.tw連線時所花費的時間會記錄在 /etc/ntp/drift 檔案內# 先輸入第二層主機的IPserver 210.59.157.10 preferserver 210.59.157.30 preferserver 202.39.157.155 prefer# 第一層的主機就列為參考用!server 210.59.157.40server 210.59.157.41server 202.39.157.151# 當然要讓Server 可以進入我們的 NTP 主機啦!權限要開放啊!restrict 210.59.157.10restrict 210.59.157.30

22、restrict 202.39.157.155restrict 210.59.157.40restrict 210.59.157.41restrict 202.39.157.151driftfile /etc/ntp/drift最后附上我的修改过后的/etc/ntp.conf文件。参考了以下几篇文章:在RedHat9下配置时间服务器时间同步NTP服务器的配置原创linux NTP配置簡易 NTP 伺服器設定# Prohibit general access to this service.#restrict default ignorerestrict 66.187.224.4 mask 25

23、5.255.255.255 nomodify notrap noqueryrestrict 66.187.224.4 mask 255.255.255.255 nomodify notrap noqueryrestrict 66.187.224.4 mask 255.255.255.255 nomodify notrap noqueryrestrict 66.187.233.4 mask 255.255.255.255 nomodify notrap noquery# Permit all access over the loopback interface. This could# be t

24、ightened as well, but to do so would effect some of# the administrative functions.restrict 127.0.0.1 # - CLIENT NETWORK -# Permit systems on this network to synchronize with this# time service. Do not permit those systems to modify the# configuration of this service. Also, do not use those# systems

25、as peers for synchronization.restrict 192.168.28.0 mask 255.255.255.0 nomodify# - OUR TIMESERVERS - # or remove the default restrict line # Permit time synchronization with our time source, but do not# permit the source to query or modify the service on this system.# restrict mytrustedtimeserverip m

26、ask 255.255.255.255 nomodify notrap noquery# server mytrustedtimeserverip# - NTP MULTICASTCLIENT -#multicastclient # listen on default 224.0.1.1# restrict 224.0.1.1 mask 255.255.255.255 notrust nomodify notrap# restrict 192.168.1.0 mask 255.255.255.0 notrust nomodify notrap# - GENERAL CONFIGURATION

27、-# Undisciplined Local Clock. This is a fake driver intended for backup# and when no outside source of synchronized time is available. The# default stratum is usually 3, but in this case we elect to use stratum# 0. Since the server line does not have the prefer keyword, this driver# is never used fo

28、r synchronization, unless no other other# synchronization source is available. In case the local host is# controlled by some external source, such as an external oscillator or# another protocol, the prefer keyword would cause the local host to# disregard all other synchronization sources, unless the kernel# modifications are in use and declare an unsynchronized condition.#server 66.187.224.4fudge 127.127.1.0 stratum 10 # Drift file. Put this in a directory which the daemon can write to.# No symbolic links allowed

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1