如何修改服务器ntp配置,[修改]Linux下NTP服务器的配置
Linux下NTP服务器的配置
Linux下的ntp软件不但能自动与互联网上的时钟保持同步,同时本身已经是一台SNTP服务器了,可以供局域网内的电脑校对时间。服务配置如下:
第一步 安装软件包
我用的是RPM包安装的,或者到去下载xntp重新编译一个新的。
#rpm -qa | grep ntp
ntp-4.2.0-7
chkfontpath-1.10.0-1
第二步 让LAN的时间服务器(第三级)与互联网上的时间服务器(第一或者第二级)同步
修改/etc/ntp.conf
这是NTP的主要配置文件,里面设置了你用来同步时间的时间服务器的域名或者IP地址,下面是到
互联网同步时间的最基本的配置:
首先定义我们喜欢的时间服务器:
server ntp.research.gov
server otherntp.research.gov
接下来,我们设置上面两台服务器的访问权限,在这个例子中我们不允许它们修改或者查询我们配置在Linux上的NTP服务器
restrict ntp.research.gov
mask 255.255.255.255 nomodify notrap noquery
restrict otherntp.research.gov
mask 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服务器来同步时间。
最后,也是最重要的是默认的限制配置要从你配置文件中删除,否则它将覆盖你所有的配置选项,你将发现如果不删除该配置,你的时间服务器将只能和自己通讯。
如果ntp.conf中有以下一行,请将它注释:
#restrict default ignore
保存你的配置文件,然后对每个你在ntp.conf里配置的时间服务器执行2编查询命令: #ntpdate ntp.research.gov 27 Jun 10:12:01 ntpdate[25475]: adjust time server ntp.research.gov offset -0.127154 sec
#ntpdate ntp.research.gov 27 Jun 10:12:06 ntpdate[25478]: adjust time server ntp.research.gov offset 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服务
是否启动,你应该可以得到一个进程ID号:
#pgrep ntpd
第四步 检查时间服务器是否正确同步
使用下面的命令检查时间服务器同步的状态:
#ntpq
-p
一个可以证明同步问题的证据是所有远程服务器的jitter值是4000并且delay和reach的值是0。可能的原因有:
配置文件中的restrict
default ignore没有被注释
有防火墙阻断了与server之间的通讯
此外每次重启NTP服务器之后大约要3-5分钟客户端才能与server建立正常的通讯连接,否则你执行ntpdate ip的时候将返回:
27 Jun 10:20:17 ntpdate[21920]: no server
suitable for synchronization found
第五步 客户端与ntp服务器同步时间
在客户端安装NTP,安装过程同NTP在服务器端。
客户端开启ntp服务
#service ntpd start
与ntp服务器同步
#ntpdate (ntp服务器地址)接下来编辑 /etc/ntp.conf
ntp.conf
#############################################################################################
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
server stdtime.gov.hk # A stratum 1 server at server.org
server 192.168.x.y #x.y为你前面所装机器在局域网里的IP
driftfile /etc/ntp/drift
broadcastdelay 0.008
authenticate no
keys /etc/ntp/keys
restrict 192.168.x.0 mask 255.255.255.0 notrust nomodify notrap//x.0为你
所在局域网段
restrict 127.0.0.1
restrict 192.168.x.y #x.y为你前面所装机器在局域网里的IP
#restrict default ignore
#############################################################################################
同时配置
#/sbin/service ntpd start //启动ntpd 参数可为restart start stop
#/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.067 -6.884 10.339
+clock.tl.fukuok .GPS. 1 u 36 64 35 19.670 -3.259 2.341
LOCAL(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 全部接受。
如果子网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
对于权限参数的说明可以参考台湾鸟哥的文章的说明:
[root@root]#vi /etc/ntp.conf
# 1. 關於權限設定部分
# 權限的設定主要以restrict 這個參數來設定,主要的語法為:
#
# restrict IP mask netmask_IP parameter
#
# 其中IP可以是軟體位址,也可以是 default ,default 就類似 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 以及本機 IP 192.168.0.2 可以不受限制,所以:
restrict default ignore# 關閉所有的 NTP 要求封包
restrict 127.0.0.1#開啟內部遞迴網路介面 lo
restrict 192.168.0.2# 主機本身的 IP 也同時開啟!
restrict 192.168.100.20
mask 255.255.255.255 nomodify
# 針對另一個IP 開放讓他可以更新時間!
restrict 192.168.0.0
mask 255.255.255.0 nomodify
# 在網域裡面的client 可以進行網路校時,但不會影響 Server !
# 2. 上層主機的設定
# 上層主機我們選擇time.stdtime.gov.tw ,要設定上層主機主要以 server
# 這個參數來設定,語法為:
#
# server [IP|FQDN] [prefer]
#
# Server 後面接的就是我們上層 Time Server 囉!而如果 Server 參數
# 後面加上perfer 的話,那表示我們的 NTP 主機主要以該部主機來作為
# 時間校正的對應。另外,為了解決更新時間封包的傳送延遲動作,
# 所以可以使用driftfile 來規定我們的主機
# 在與 Time Server 溝通時所花費的時間,可以記錄在 driftfile
# 後面接的檔案內,例如下面的範例中,我們的NTP server 與
# time.stdtime.gov.tw連線時所花費的時間會記錄在 /etc/ntp/drift 檔案內
# 先輸入第二層主機的IP
server 210.59.157.10 prefer
server 210.59.157.30 prefer
server 202.39.157.155 prefer
# 第一層的主機就列為參考用!
server 210.59.157.40
server 210.59.157.41
server 202.39.157.151
# 當然要讓Server 可以進入我們的 NTP 主機啦!權限要開放啊!
restrict 210.59.157.10
restrict 210.59.157.30
restrict 202.39.157.155
restrict 210.59.157.40
restrict 210.59.157.41
restrict 202.39.157.151
driftfile /etc/ntp/drift
最后附上我的修改过后的/etc/ntp.conf文件。
参考了以下几篇文章:
[时间同步]NTP服务器的配置
# Prohibit general access to this service.
#restrict default ignore
restrict 66.187.224.4 mask 255.255.255.255 nomodify notrap noquery
restrict 66.187.224.4 mask 255.255.255.255 nomodify notrap noquery
restrict 66.187.224.4 mask 255.255.255.255 nomodify notrap noquery
restrict 66.187.233.4 mask 255.255.255.255 nomodify notrap 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.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 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 mask 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 ---
#
# 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 for 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.4
fudge127.127.1.0 stratum 10
#
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
#
driftfile /var/lib/ntp/drift
broadcastdelay0.008
#
# Authentication delay. If you use, or plan to use someday, the
# authentication facility you should make the programs in the auth_stuff
# directory and figure out what this number should be on your machine.
#
authenticate yes
#
# Keys file. If you want to diddle your server at run time, make a
# keys file (mode 600 for sure) and define the key number to be
# used for making requests.
#
# PLEASE DO NOT USE THE DEFAULT VALUES HERE. Pick your own, or remote
# systems might be able to reset your clock at will. Note also that
# ntpd is started with a -A flag, disabling authentication, that
# will have to be removed as well.
#
keys/etc/ntp/keys
如何修改服务器ntp配置,[修改]Linux下NTP服务器的配置相关推荐
- linux下如何配置svn,Linux下SVN安装与配置详解
一.前言 SVN服务器有两种运行方式: 1.独立服务器: 2.借助apache: 两种方式各有利弊,独立SVN服务器不结合Apache安装使用,连接独立SVN服务器也不用HTTP协议. 这是比较快捷的 ...
- linux跨服务器复制文件夹,linux下跨服务器文件文件夹的复制
了解一下C++输入和输出的概念 我们经常用到的输入和输出,都是以终端为对象的,即从键盘输入数据,运行结果输出到显示器屏幕上.从操作系统的角度看,每一个与主机相连的输入输出设备都被看作一个文件.除了以终 ...
- 让你提前认识软件开发(51):VC++集成开发环境中Linux下Pclint工程的配置方法及常见错误修改
第3部分 软件研发工作总结 VC++集成开发环境中Linux下Pclint工程的配置方法及常见错误修改 [文章摘要] Pclint是一种C/C++软件代码静态分析工具.它是一种更加严格的编译器,能够发 ...
- Tomcat修改favicon.ico图标,Linux下Tomcat修改favicon.ico图标,Tomcat更换favicon.ico图标...
Tomcat修改favicon.ico图标,Linux下Tomcat修改favicon.ico图标,Tomcat更换favicon.ico图标 >>>>>>> ...
- linux下apache服务器的配置和管理(启动、重启、中断服务)
2019独角兽企业重金招聘Python工程师标准>>> linux下apache服务器的配置和管理 一.两个重要目录: Apache有两个重要的目录: 1.配置目录/etc/http ...
- linux安装DNS服务命令,Linux下的安装和配置DNS服务器
Linux下的安装和配置DNS服务器 发布时间:2008-09-08 17:03:00 作者:佚名 我要评论 在Linux操作系统中使用BIND (Berkeley Internet Name ...
- Linux下Tomcat的安装配置
Linux下Tomcat的安装配置 一.下载安装对应的jdk,并配置Java环境. 官网下载地址: http://www.oracle.com/technetwork/java/javase/down ...
- linux下pptpd的安装配置(×××)
linux下pptpd的安装配置(×××)--单网卡×××实现 (本文部分内容摘自互联网,特此声明!) 环境介绍:Linux(redhat) 2.6.18 +PPP+PPTPD ...
- Linux下SVN服务器同时支持Apache的http和https及svnserve独立服务器三种模式且使用相同的访问权限账号...
1.在服务器上安装配置SVN服务: 2.配置SVN服务同时支持Apache的http和svnserve独立服务器两种模式访问: 3.Apache的http和svnserve独立服务器两种模式使用相同的 ...
- Linux下使用Google Authenticator配置SSH登录动态验证码
说明: 1.一般ssh登录服务器,只需要输入账号和密码. 2.本教程的目的:在账号和密码之间再增加一个 验证码,只有输入正确的验证码之后,再输入 密码才能登录.这样就增强了ssh登录的安全性. 3.账 ...
最新文章
- 【iOS】sqlite3的使用(増删改查)
- DataList在无数据记录时显示类似GridView空模板(EmptyDataTemplate)
- python中的turtle函数_1.常用turtle功能函数
- bootstrap fileinput上传返回400,404,500 等错误替换
- C# 读写文件方法总结
- 如何用python做词云图_科学网—如何用Python做词云?(基础篇视频教程) - 王树义的博文...
- PCLint使用(一)
- 命令行下安装的tensorflow怎么打开_CourseMaker微课制作教程18:录ppt一直“正在打开……”及WPS下ppt满屏放映怎么办?...
- 初识Paramiko
- 【网络攻防原理与技术】第6章:特洛伊木马
- 3dmax2009下载3dmax2009安装教程
- Github上Python超越Java,应届人工智能程序员年薪30w+
- Hibernate源码解析
- 【Kotlin】告别KAPT,拥抱KSP API
- radmi4a Android,红米手机4A获取root超级权限的教程
- iphone12mini参数配置 iphone12mini多大尺寸
- getline()函数的几点疑惑
- 画出传输门、三态门、开路门_(整理)第2章 门电路
- html转发朋友圈带图片吗,如何转发别人的朋友圈(怎么连图带文字一起转发)...
- canal 学习笔记