ntp时间服务器 时间同步
ntpd服务可以在修正时间的同时,修正cpu tick
ntpd有一个自我保护设置: 如果本机与上源时间相差太大, ntpd不运行
ntpdate : 不会考虑其他程序是否会阵痛,直接调整时间,有可能会对程序造成影响
# ntpdate -u 192.168.0.2
# ntpdate -u 10.11.0.35
# ntpdate -u time.ntp.org
# ntpdate -u ntp.sjtu.edu.cn >>/var/log/ntp.log 2>&1;hwclock -w
-u:指定使用无特权的端口发送数据包,可以越过防火墙与主机同步;
使用ntpd来校准时钟,而不是调整计算机时钟上的时间。
在计算机刚刚启动,但还没有启动很多服务的那个时候可以使用ntpdate同步时间
3. /etc/init.d/crond restart
以下7个域名提供服务,大家可以直接使用。
http://time2.aliyun.com
http://time3.aliyun.com
http://time4.aliyun.com
http://time5.aliyun.com
http://time6.aliyun.com
http://time7.aliyun.com
或者直接访问这个地址 time.pool.aliyun.com
13 Nov 10:48:28 ntpdate[26527]: adjust time server 182.92.12.11 offset 0.000458 sec
0.centos.pool.ntp.org
1.centos.pool.ntp.org
2.centos.pool.ntp.org
NTP通信协议原理
- 首先主机启动NTP。
- 客户端会向NTP服务器发送调整时间的message。
- 然后NTP server会送出当前的标准时间给client
- client接受来自server的时间后,会根据这个信息来调整自己的时间。这样就实现了网络对时。
NTP这个deamon采用了UDP 123端口。
由于NTP是层型结构,有顶端的服务器,多层的Relay Server再到客户端.
所以服务器从高到低级别可以设定为1-16.
为了减缓负荷和网络堵塞,原则上应该避免直接连接到级别为1的服务器的
安装
# yum install ntp
# chkconfig ntpd on
# 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).
系统时间与BIOS事件的偏差记录
# permit the source to query or modify the service on this system.
restrict -6 default kod nomodify notrap nopeer noquery
默认拒绝任何操作
任何ip4地址、ip6地址 不能修改、不能trap远程登录、不能尝试对等、不能校对时间,
语法为: restrict
[ 客户端IP ] mask [ IP掩码 ] [参数]
其中IP地址也可以是default ,default 就是指所有的IP
参数有以下几个:
nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
notrust :拒絕沒有認證的用戶端
noquery :客户端不能使用ntpq,ntpc来查询ntp服务器,等于不提供校对时间服务
notrap :不提供trap远程登录功能,trap服务是一种远程时间日志服务
拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。
nopeer :用于阻止主机尝试与服务器对等
kod : 访问违规时发送 KoD 包,向不安全的访问者发送Kiss-Of-Death报文。
restrict -6 表示IPV6地址的权限设置。
# be tightened as well, but to do so would effect some of
这里最好收紧权限,但是会影响一些管理功能
# the administrative functions.
restrict 127.0.0.1
restrict ::1
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# 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 iburst
server host [ key n ] [ version n ] [ prefer ] [ mode n ] [ minpoll n ] [ maxpoll n ] [ iburst ]
其中host是上层NTP服务器的IP地址或域名,随后所跟的参数解释如下所示:
◆ key: 表示所有发往服务器的报文包含有秘钥加密的认证信息,n是32位的整数,表示秘钥号。
◆ version: 表示发往上层服务器的报文使用的版本号,n默认是3,可以是1或者2。
◆ prefer: 优先使用。
◆ mode: 指定数据报文mode字段的值。
◆ minpoll: 指定与查询该服务器的最小时间间隔为2的n次方秒,n默认为6,范围为4-14。
◆ maxpoll: 指定与查询该服务器的最大时间间隔为2的n次方秒,n默认为10,范围为4-14。
◆ iburst: 当初始同步请求时,采用突发方式接连发送8个报文,时间间隔为2秒。
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
当外部时间不可用时,以本地(本机)时间作为服务时间
本地时间以 127.127.1.0 表示 级别为10
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
#server 127.127.1.0 # local clock
#fudge 127.127.1.0 stratum 10
下面是一些加密认证的配置
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
restrict
default kod nomodify notrap nopeer noquery 拒绝所有ip4
的请求#
restrict -6 default kod nomodify notrap nopeer noquery #针对ipv6设置#
允许本地所有操作restrict
127.0.0.1#restrict
-6 ::1#
允许的局域网络段或单独ip 某些权限restrict
10.0.0.0 mask 255.0.0.0 nomodify motraprestrict
192.168.0.0 mask 255.255.255.0 nomodify motraprestrict
192.168.1.123 mask 255.255.255.255 nomodify motrap#
使用上层的internet ntp服务器restrict
cn.pool.ntp.orgrestrict
1.cn.poo.ntp.orgrestrict
0.asia.pool.ntp.orgrestrict
3.asia.pool.ntp.orgserver
cn.pool.ntp.org preferserver
1.cn.poo.ntp.orgserver
0.asia.pool.ntp.orgserver
3.asia.pool.ntp.org#
如果无法与上层ntp server通信以本地时间为标准时间server
127.127.1.0 #
local clockfudge
127.127.1.0 stratum 10#
计算本ntp server 与上层ntpserver的频率误差driftfile
/var/lib/ntp/drift#
Key file containing the keys and key identifiers used when operating#
with symmetric key cryptography.keys
/etc/ntp/keys#日志文件logfile
/var/log/ntp.log配置/etc/sysconfig/ntpd文件
ntp服务,默认只会同步系统时间。如果想要让ntp同时同步硬件时间,可以设置/etc/sysconfig/ntpd文件,在/etc/sysconfig/ntpd文件中,添加 SYNC_HWCLOCK=yes 这样,就可以让硬件时间与系统时间一起同步。
#允许BIOS与系统时间同步,也可以通过hwclock -w 命令
SYNC_HWCLOCK=yes
启动ntpd 服务
# service ntpd start
#
查看ntp的端口,应该看到123端口#netstat
-unlnp#
查看ntp服务器有无和上层连通#ntpstatsynchronised
to NTP server () at stratum 2time
correct to within 74 mspolling
server every 128 s#
注意:此命令出现上述synchronised结果比较慢,我的用了大概5分钟。刚启动的时候,一般是:
# ntpstat
unsynchronised
time server re-starting
polling server every 64 s
连接并同步后:
synchronised to NTP server (202.112.10.36) at stratum 3
time correct to within 275 ms
polling server every 256 s
ntptrace
-n 127.0.0.1127.0.0.1:
stratum 3, offset -0.001095, synch distance 0.532610116.193.83.174:
timed out, nothing received查看ntp服务器与上层ntp服务器的状态:ntpq
#ntpq
-p#
其中:
#
remote - 本机和上层ntp的ip或主机名,“+”有连线可做候选,“*”正在使用的
#
refid - 更上一层的ntp地址
#
st - stratum的 级别
#
when - 多少秒前曾经同步过时间#
poll - 下次更新在多少秒后#
reach - 已经向上层ntp服务器要求更新的次数#
delay - 网络延迟#
offset - 时间补偿#
jitter - 系统时间与bios时间差# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*time4.aliyun.co 10.137.38.86 2 u 111 128 377 27.480 -5.995 1.852
2.配置NTP客户端:
在所有客户端上vim /etc/ntp.conf,添加:
server x.x.x.x
x.x.x.x 为上面配置的ntp服务器地址
注意:当server与client之间的时间误差过大时(可能是1000秒),处于对修改时间可能对系统和应用带来不可预知的问题,NTP将停止时间同步!
所以如果发现NTP启动之后时间并不进行同步时,应该考虑到可能是时间差过大引起的,
此时需要先手动进行时间同步 ntpdate !
ntp时间服务器 时间同步的更多相关文章
- 国内可用的Internet时间同步服务器地址(NTP时间服务器)
不知道什么鬼我这系统自带的Internet时间同步服务器地址居然不可用,终端ping系统自带服务器两个居然都不通???难道时间服务器也和谐么? 好在阿里云提供了7个NTP时间服务器也就是Interne ...
- 企业内部在centos7.2系统中必杀技NTP时间服务器及内网服务器时间同步(windows和linux客户端同步)
网络时间协议NTP(Network Time Protocol)是用于互联网中时间同步的标准互联网协议.NTP的用途是把计算机的时间同步到某些时间标准.目前采用的时间标准是世界协调时UTC(Unive ...
- 搭建内网的NTP时间服务器
NTP时间服务器 标签: linux 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 1.简介 NTP(Network Time Protocol,网络时间协议) ...
- 国内常用的几个NTP时间服务器
问题描述: 经常Windows或者Linux系统上面的时间跟我们本地的时间不一致 有时候就是Windows的Internet时间设置里面的Windows自带的时间同步服务器不好使 Linux配置NTP ...
- Linux NTP时间服务器
NTP 时间服务器 ntp也是一种协议 ntp软件(支持ntp协议) CentOS6自带 CentOS7需要安装 chrony软件(支持ntp协议) CentOS7自带 安装ntp CentOS ...
- Centos7 Ntp 时间服务器
Centos7 Ntp 时间服务器 安装环境 [root@m02 ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) 安装 ...
- Ntp时间服务器与定时任务Crontab
一 NTP时间服务器 1 局域网内的NTP同步配置 注意 所有配置操作必须是root用户 ,局域网内node21作为NTP Server,node22,node23作为NTP Client与服务器进行 ...
- centos7.5配置ntp时间服务器
Centos7配置ntp时间服务器 Centos7配置时间服务器,一个服务端,多个客户端,客户端去同步服务端 服务端: 1.先修改时区,否则即使配置完ntp时间也不对,修改时区参照:https://w ...
- 搭建NTP时间服务器~使用NTP同步时间~构建主机间时间自动同步关系
NTP是一个时间服务器,同时它也是一个时间客户端. 我们可以使用它构建主机与主机之间的时间自动同步环境,保证所有服务器时间一致性. 常用的公共NTP时间服务器有: cn.ntp.org.cn 中国 n ...
随机推荐
- Spring Boot2 系列教程 (六) | 使用 JdbcTemplates 访问 Mysql
前言 如题,今天介绍 springboot 通过jdbc访问关系型mysql,通过 spring 的 JdbcTemplate 去访问. 准备工作 SpringBoot 2.x jdk 1.8 mav ...
- 递推预处理 + Manacher
链接:https://www.nowcoder.com/acm/contest/131/D来源:牛客网 字符串 S 只包含小写英文字母.有四种操作,每次操作你可以选择其中一种: 删除字符串的第一个字母 ...
- electron教程(番外篇二): 使用TypeScript版本的electron, VSCode调试TypeScript, TS版本的ESLint
我的electron教程系列 electron教程(一): electron的安装和项目的创建 electron教程(番外篇一): 开发环境及插件, VSCode调试, ESLint + Google ...
- java小心机(6)| 多态的一些坑
对于"多态"的概念,想必大家都很熟悉了,但我们还是来回顾一下吧 class Actor { public void act(){ System.out.println(" ...
- 10、python函数
前言:本文主要介绍python函数的定义和调用.函数的参数.函数的作用域.内置函数. 一.函数的定义和调用 1.函数的作用 对特定的一些功能进行封装,提高代码的重用率,进而提升开发的效率,格式: de ...
- 现在啊还不太清楚 nodejs和coffeescript 的关系
我怎么会思考这个问题,今天看到用coffeescript做的一个服务引导 挺好 看博客里提 安装node之后 呢 npm 可以安装coffeescript 难道 coffee 是 node的 一个方言 ...
- 对于Makefile的基本使用
上课不听讲的后果就是课下疯狂补知识了 原文来自https://www.cnblogs.com/chenguanfu/p/4415072.html 在Windows下,只需要简单的点击以下make,re ...
- Word Embeddings: Encoding Lexical Semantics(译文)
词向量:编码词汇级别的信息 url:http://pytorch.org/tutorials/beginner/nlp/word_embeddings_tutorial.html?highlight= ...
- c++中多文件的组织
参考书目:visual c++ 入门经典 第七版 Ivor Horton著 第八章 根据书中例子学习使用类的多文件项目. 首先要将类CBox定义成一个连贯的整体,在CBox.H文件中写入相关的类定义, ...
- liberty | 在IDEA整合Springboot与IBM liberty
在IDEA整合Springboot与IBM liberty 简介 Liberty 是一款全新的轻量级应用服务器,它将用户的良好开发体验作为最主要的出发点.其主要特点和内容包括: 高模块化--该功能允许 ...