前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux NTP时间服务器

Linux NTP时间服务器

作者头像
863987322
发布2018-01-24 14:35:35
7.9K0
发布2018-01-24 14:35:35
举报

NTP 时间服务器

ntp也是一种协议

ntp软件(支持ntp协议)  CentOS6自带 CentOS7需要安装

chrony软件(支持ntp协议)   CentOS7自带

安装ntp

CentOS6系统自带ntp,CentOS7需要自己安装

[root@m02 ~]# yum -y install ntp
[root@m02 ~]# rpm -qa ntp
ntp-4.2.6p5-25.el7.centos.2.x86_64

配置ntp

权限参数含义

noquery:不提供ntp服务
notrap:不提供trap远程事件登录的功能
nomodiy:表示客户端不能更改ntp服务器的时间参数,但可以通过ntp服务器进行时间矫正
notrust:拒绝没有通过认证的客户端
nokod:kod技术可以组织一种dos攻击
ignore :关闭所有ntp服务

配置文件更改

更改之前可以备份一下,以防改错

[root@m02 ~]# vim /etc/ntp.conf
server ntp1.aliyun.com   加上这个,因为默认是国外的时间同步服务器,使用国外的相对于使用阿里的,速度对比可想而知。
加权限限制
格式:restrict IP 权限参数
IP可以为ip地址或者default
权限参数:nomodify notrap nopeer noquery
例如:restrict 172.16.1.0 mask 255.255.255.0 nomodify notrap
ntp服务改后和改前配置文件对比
[root@m02 ~]# diff /etc/ntp.conf{,.ori}
18c18
< restrict 172.16.1.0 mask 255.255.255.0 nomodify notrap
---
> 
21d20
< server ntp1.aliyun.com

启动ntp

[root@m02 ~]# systemctl start ntpd

服务端可以先查看一下

利用ntpq -p命令和ntpstat命令

[root@m02 ~]# ntpq -p     #显示上一级连接的服务器
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*time5.aliyun.co 10.137.38.86     2 u   57   64  377    4.209    3.841   2.685
 time-d-b.nist.g .STEP.          16 u    -  512    0    0.000    0.000   0.000
[root@m02 ~]# ntpstat      #显示同步结果 现在的状态信息
synchronised to NTP server (182.92.12.11) at stratum 3 
   time correct to within 11 ms
   polling server every 64 s

客户端测试结果

客户机要等几分钟再与新启动的ntp服务器进行时间同步,否则会提示no server suitable for synchronization found错误。

而且同步有时会很慢

ntpdate -d 显示同步过程

[root@Cobbler ~]# ntpdate 172.16.1.62
16 Nov 11:42:34 ntpdate[1538]: adjust time server 172.16.1.62 offset -0.002221 sec
[root@Cobbler ~]# ntpdate -d 172.16.1.62
16 Nov 16:10:07 ntpdate[2058]: ntpdate 4.2.6p5@1.2349-o Wed Apr 12 21:24:06 UTC 2017 (1)
Looking for host 172.16.1.62 and service ntp
host found : 172.16.1.62
transmit(172.16.1.62)
receive(172.16.1.62)
transmit(172.16.1.62)
receive(172.16.1.62)
transmit(172.16.1.62)
receive(172.16.1.62)
transmit(172.16.1.62)
receive(172.16.1.62)
server 172.16.1.62, port 123
stratum 3, precision -24, leap 00, trust 000
refid [172.16.1.62], delay 0.02592, dispersion 0.00142
transmitted 4, in filter 4
reference time:    ddb7c566.e8e2acda  Thu, Nov 16 2017 16:05:58.909
originate timestamp: ddb7c665.aa402c9b  Thu, Nov 16 2017 16:10:13.665
transmit timestamp:  ddb7c665.abf2c8a8  Thu, Nov 16 2017 16:10:13.671
filter delay:  0.02592  0.02596  0.02597  0.02599 
         0.00000  0.00000  0.00000  0.00000 
filter offset: -0.00994 -0.00890 -0.00785 -0.00686
         0.000000 0.000000 0.000000 0.000000
delay 0.02592, dispersion 0.00142
offset -0.009942

16 Nov 16:10:13 ntpdate[2058]: adjust time server 172.16.1.62 offset -0.009942 sec

step和adjust的区别

[root@Cobbler ~]# date -s 20080101 
Tue Jan  1 00:00:00 CST 2008
[root@Cobbler ~]# ntpdate 172.16.1.62 
16 Nov 16:21:26 ntpdate[2085]: step time server 172.16.1.62 offset 311703675.400154 sec

说明: adjust和step,adjust同步时间的时候小于一秒,step同步时间的时候大于一秒

CentOS7自带软件chrony

配置文件

vim /etc/chrony.conf
内容和ntp是一样的,知识顺序颠倒了
systemctl status chronyd  查看状态
注意:chrony 不能和ntp同时存在 只有centos7上有chrony
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-01-09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • NTP 时间服务器
    • 安装ntp
      • 配置ntp
        • 权限参数含义
        • 配置文件更改
        • 启动ntp
      • 客户端测试结果
        • step和adjust的区别
      • CentOS7自带软件chrony
        • 配置文件
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档